@@ -67,7 +67,7 @@ func StartTenant(
67
67
return nil , "" , "" , err
68
68
}
69
69
70
- args , err := makeTenantSQLServerArgs (stopper , kvClusterName , baseCfg , sqlCfg )
70
+ args , err := makeTenantSQLServerArgs (ctx , stopper , kvClusterName , baseCfg , sqlCfg )
71
71
if err != nil {
72
72
return nil , "" , "" , err
73
73
}
@@ -96,7 +96,18 @@ func StartTenant(
96
96
// TODO(davidh): Do we need to force this to be false?
97
97
baseCfg .SplitListenSQL = false
98
98
99
- background := baseCfg .AmbientCtx .AnnotateCtx (context .Background ())
99
+ // Add the server tags to the startup context.
100
+ //
101
+ // We use args.BaseConfig here instead of baseCfg directly because
102
+ // makeTenantSQLArgs defines its own AmbientCtx instance and it's
103
+ // defined by-value.
104
+ ctx = args .BaseConfig .AmbientCtx .AnnotateCtx (ctx )
105
+
106
+ // Add the server tags to a generic background context for use
107
+ // by async goroutines.
108
+ // We can only annotate the context after makeTenantSQLServerArgs
109
+ // has defined the instance ID container in the AmbientCtx.
110
+ background := args .BaseConfig .AmbientCtx .AnnotateCtx (context .Background ())
100
111
101
112
// StartListenRPCAndSQL will replace the SQLAddr fields if we choose
102
113
// to share the SQL and gRPC port so here, since the tenant config
@@ -164,6 +175,16 @@ func StartTenant(
164
175
args .sqlStatusServer = tenantStatusServer
165
176
s , err := newSQLServer (ctx , args )
166
177
tenantStatusServer .sqlServer = s
178
+ // Also add the SQL instance tag to the tenant status server's
179
+ // ambient context.
180
+ //
181
+ // We use the tag "sqli" instead of just "sql" because the latter is
182
+ // too generic and would be hard to search if someone was looking at
183
+ // a log message and wondering what it stands for.
184
+ //
185
+ // TODO(knz): find a way to share common logging tags between
186
+ // multiple AmbientContext instances.
187
+ tenantStatusServer .AmbientContext .AddLogTag ("sqli" , s .sqlIDContainer )
167
188
168
189
if err != nil {
169
190
return nil , "" , "" , err
@@ -355,7 +376,11 @@ func loadVarsHandler(
355
376
}
356
377
357
378
func makeTenantSQLServerArgs (
358
- stopper * stop.Stopper , kvClusterName string , baseCfg BaseConfig , sqlCfg SQLConfig ,
379
+ startupCtx context.Context ,
380
+ stopper * stop.Stopper ,
381
+ kvClusterName string ,
382
+ baseCfg BaseConfig ,
383
+ sqlCfg SQLConfig ,
359
384
) (sqlServerArgs , error ) {
360
385
st := baseCfg .Settings
361
386
@@ -366,6 +391,7 @@ func makeTenantSQLServerArgs(
366
391
// too generic and would be hard to search if someone was looking at
367
392
// a log message and wondering what it stands for.
368
393
baseCfg .AmbientCtx .AddLogTag ("sqli" , instanceIDContainer )
394
+ startupCtx = baseCfg .AmbientCtx .AnnotateCtx (startupCtx )
369
395
370
396
// TODO(tbg): this is needed so that the RPC heartbeats between the testcluster
371
397
// and this tenant work.
0 commit comments