Skip to content

Commit ac68bca

Browse files
craig[bot]stevendanna
andcommitted
Merge #154234
154234: *: use logtags.BuildBuffer() r=shubhamdhama a=stevendanna This handles most of the places where we are adding multiple tags to the context. Most of these are not called frequently, but it still seems better to use the more efficient API since people often look to existing code as an example. Epic: none Release note: None Co-authored-by: Steven Danna <[email protected]>
2 parents 299240d + 206de31 commit ac68bca

15 files changed

+71
-56
lines changed

pkg/crosscluster/logical/logical_replication_writer_processor.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,9 +272,11 @@ func newLogicalReplicationWriterProcessor(
272272
//
273273
// Start implements the RowSource interface.
274274
func (lrw *logicalReplicationWriterProcessor) Start(ctx context.Context) {
275-
ctx = logtags.AddTag(ctx, "job", lrw.spec.JobID)
276-
ctx = logtags.AddTag(ctx, "src-node", lrw.spec.PartitionSpec.PartitionID)
277-
ctx = logtags.AddTag(ctx, "proc", lrw.ProcessorID)
275+
tags := logtags.BuildBuffer()
276+
tags.Add("job", lrw.spec.JobID)
277+
tags.Add("src-node", lrw.spec.PartitionSpec.PartitionID)
278+
tags.Add("proc", lrw.ProcessorID)
279+
ctx = logtags.AddTags(ctx, tags.Finish())
278280
lrw.agg = tracing.TracingAggregatorForContext(ctx)
279281
var listeners []tracing.EventListener
280282
if lrw.agg != nil {

pkg/crosscluster/logical/offline_initial_scan_processor.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,11 @@ func (o *offlineInitialScanProcessor) setup(ctx context.Context) error {
189189
}
190190

191191
func (o *offlineInitialScanProcessor) Start(ctx context.Context) {
192-
tags := &logtags.Buffer{}
193-
tags = tags.Add("job", o.spec.JobID)
194-
tags = tags.Add("src-node", o.spec.PartitionSpec.PartitionID)
195-
tags = tags.Add("proc", o.ProcessorID)
196-
ctx = logtags.AddTags(ctx, tags)
192+
tags := logtags.BuildBuffer()
193+
tags.Add("job", o.spec.JobID)
194+
tags.Add("src-node", o.spec.PartitionSpec.PartitionID)
195+
tags.Add("proc", o.ProcessorID)
196+
ctx = logtags.AddTags(ctx, tags.Finish())
197197

198198
ctx = o.StartInternal(ctx, offlineInitialScanProcessorName)
199199

pkg/crosscluster/physical/stream_ingestion_processor.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,8 +396,10 @@ func newStreamIngestionDataProcessor(
396396
//
397397
// Start implements the RowSource interface.
398398
func (sip *streamIngestionProcessor) Start(ctx context.Context) {
399-
ctx = logtags.AddTag(ctx, "job", sip.spec.JobID)
400-
ctx = logtags.AddTag(ctx, "proc", sip.ProcessorID)
399+
tags := logtags.BuildBuffer()
400+
tags.Add("job", sip.spec.JobID)
401+
tags.Add("proc", sip.ProcessorID)
402+
ctx = logtags.AddTags(ctx, tags.Finish())
401403
log.Dev.Infof(ctx, "starting ingest proc")
402404
sip.agg = tracing.TracingAggregatorForContext(ctx)
403405

pkg/crosscluster/producer/event_stream.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,11 @@ func (s *eventStream) Start(ctx context.Context, txn *kv.Txn) (retErr error) {
100100
// false. However, this generator never terminates without an error,
101101
// so this method should be called once. Be defensive and return an error
102102
// if this method is called again.
103-
ctx = logtags.AddTag(ctx, "id", s.streamID)
104-
ctx = logtags.AddTag(ctx, "dst-node", s.spec.ConsumerNode)
105-
ctx = logtags.AddTag(ctx, "dst-proc", s.spec.ConsumerProc)
103+
tags := logtags.BuildBuffer()
104+
tags.Add("id", s.streamID)
105+
tags.Add("dst-node", s.spec.ConsumerNode)
106+
tags.Add("dst-proc", s.spec.ConsumerProc)
107+
ctx = logtags.AddTags(ctx, tags.Finish())
106108
if s.errCh != nil {
107109
return errors.AssertionFailedf("expected to be started once")
108110
}

pkg/kv/kvclient/kvcoord/dist_sender_mux_rangefeed.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -369,14 +369,14 @@ func (m *rangefeedMuxer) startNodeMuxRangeFeed(
369369
stream *future.Future[muxStreamOrError],
370370
) (retErr error) {
371371

372-
tags := &logtags.Buffer{}
373-
tags = tags.Add("mux_n", nodeID)
372+
tags := logtags.BuildBuffer()
373+
tags.Add("mux_n", nodeID)
374374
// Add "generation" number to the context so that log messages and stacks can
375375
// differentiate between multiple instances of mux rangefeed goroutine
376376
// (this can happen when one was shutdown, then re-established).
377-
tags = tags.Add("gen", atomic.AddInt64(&m.seqID, 1))
377+
tags.Add("gen", atomic.AddInt64(&m.seqID, 1))
378378

379-
ctx = logtags.AddTags(ctx, tags)
379+
ctx = logtags.AddTags(ctx, tags.Finish())
380380
ctx, restore := pprofutil.SetProfilerLabelsFromCtxTags(ctx)
381381
defer restore()
382382

pkg/rpc/context.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2023,12 +2023,12 @@ func (rpcCtx *Context) wrapCtx(
20232023
if remoteNodeID == 0 {
20242024
rnodeID = redact.SafeString("?")
20252025
}
2026-
l := &logtags.Buffer{}
2027-
l = l.Add(RemoteNodeTag, rnodeID)
2028-
l = l.Add(RemoteAddressTag, target)
2029-
l = l.Add(Class, class)
2030-
l = l.Add(RpcTag, nil)
2031-
return logtags.AddTags(ctx, l)
2026+
l := logtags.BuildBuffer()
2027+
l.Add(RemoteNodeTag, rnodeID)
2028+
l.Add(RemoteAddressTag, target)
2029+
l.Add(Class, class)
2030+
l.Add(RpcTag, nil)
2031+
return logtags.AddTags(ctx, l.Finish())
20322032
}
20332033

20342034
// grpcDialRaw connects to the remote node.

pkg/server/authserver/authentication.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,10 @@ func (s *authenticationServer) UserLogin(
260260
// DemoLogin is the same as UserLogin but using the GET method.
261261
// It is only available for 'cockroach demo' and test clusters.
262262
func (s *authenticationServer) DemoLogin(w http.ResponseWriter, req *http.Request) {
263-
ctx := context.Background()
264-
ctx = logtags.AddTag(ctx, "client", log.SafeOperational(req.RemoteAddr))
265-
ctx = logtags.AddTag(ctx, "demologin", nil)
263+
tags := logtags.BuildBuffer()
264+
tags.Add("client", log.SafeOperational(req.RemoteAddr))
265+
tags.Add("demologin", nil)
266+
ctx := logtags.WithTags(context.Background(), tags.Finish())
266267

267268
fail := func(err error) {
268269
w.WriteHeader(500)

pkg/server/node.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2266,14 +2266,14 @@ func (n *Node) muxRangeFeed(muxStream kvpb.RPCInternal_MuxRangeFeedStream) error
22662266
continue
22672267
}
22682268

2269-
tags := &logtags.Buffer{}
2270-
tags = tags.Add("r", req.RangeID)
2271-
tags = tags.Add("sm", req.Replica.StoreID)
2272-
tags = tags.Add("sid", req.StreamID)
2269+
tags := logtags.BuildBuffer()
2270+
tags.Add("r", req.RangeID)
2271+
tags.Add("sm", req.Replica.StoreID)
2272+
tags.Add("sid", req.StreamID)
22732273
if req.ConsumerID != 0 {
2274-
tags = tags.Add("cid", req.ConsumerID)
2274+
tags.Add("cid", req.ConsumerID)
22752275
}
2276-
streamCtx := logtags.AddTags(ctx, tags)
2276+
streamCtx := logtags.AddTags(ctx, tags.Finish())
22772277

22782278
streamSink := sm.NewStream(req.StreamID, req.RangeID)
22792279

pkg/server/server_controller_channel_orchestrator.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,10 @@ func (o *channelOrchestrator) startControlledServer(
223223
// stopper will have its own tracer which is incompatible with the
224224
// tracer attached to the incoming context.
225225
tenantCtx := logtags.WithTags(context.Background(), logtags.FromContext(ctx))
226-
tenantCtx = logtags.AddTag(tenantCtx, "tenant-orchestration", nil)
227-
tenantCtx = logtags.AddTag(tenantCtx, "tenant", tenantName)
226+
tags := logtags.BuildBuffer()
227+
tags.Add("tenant-orchestration", nil)
228+
tags.Add("tenant", tenantName)
229+
tenantCtx = logtags.AddTags(tenantCtx, tags.Finish())
228230

229231
// ctlStopper is a stopper uniquely responsible for the control
230232
// loop. It is separate from the tenantStopper defined below so

pkg/server/testserver.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2731,9 +2731,11 @@ func newClientRPCContext(
27312731
cid *base.ClusterIDContainer,
27322732
s serverutils.ApplicationLayerInterface,
27332733
) *rpc.Context {
2734-
ctx = logtags.AddTag(ctx, "testclient", nil)
2735-
ctx = logtags.AddTag(ctx, "user", user)
2736-
ctx = logtags.AddTag(ctx, "nsql", s.SQLInstanceID())
2734+
tags := logtags.BuildBuffer()
2735+
tags.Add("testclient", nil)
2736+
tags.Add("user", user)
2737+
tags.Add("nsql", s.SQLInstanceID())
2738+
ctx = logtags.AddTags(ctx, tags.Finish())
27372739

27382740
stopper := s.AppStopper()
27392741
if ctx.Done() == nil {

0 commit comments

Comments
 (0)