Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

util/tracing: trim trace recordings in a smarter way #88414

Merged
merged 4 commits into from
Sep 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pkg/server/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -3906,7 +3906,8 @@ func (s *adminServer) GetTrace(
}
traceStillExists = true
if recording == nil {
recording = sp.GetFullRecording(tracingpb.RecordingVerbose)
trace := sp.GetFullRecording(tracingpb.RecordingVerbose)
recording = trace.Flatten()
}
return iterutil.StopIteration()
}); err != nil {
Expand Down
1 change: 0 additions & 1 deletion pkg/server/node_tenant.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import "github.com/cockroachdb/cockroach/pkg/util/tracing/tracingpb"
func redactRecording(rec tracingpb.Recording) {
for i := range rec {
sp := &rec[i]
sp.Tags = nil // TODO(benbardin): Remove for 23.1.
sp.TagGroups = nil
for j := range sp.Logs {
record := &sp.Logs[j]
Expand Down
2 changes: 0 additions & 2 deletions pkg/server/node_tenant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ func TestRedactRecordingForTenant(t *testing.T) {

rec := mkRec()
redactRecording(rec)
require.Zero(t, rec[0].Tags)
require.Zero(t, rec[0].TagGroups)
require.Len(t, rec[0].Logs, 1)
msg := rec[0].Logs[0].Msg().StripMarkers()
Expand All @@ -79,7 +78,6 @@ func TestNewSpanFields(t *testing.T) {
SpanID tracingpb.SpanID
ParentSpanID tracingpb.SpanID
Operation string
Tags map[string]string
TagGroups []tracingpb.TagGroup
StartTime time.Time
Duration time.Duration
Expand Down
3 changes: 2 additions & 1 deletion pkg/sql/crdb_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -1520,7 +1520,8 @@ CREATE TABLE crdb_internal.node_inflight_trace_spans (
"only users with the admin role are allowed to read crdb_internal.node_inflight_trace_spans")
}
return p.ExecCfg().AmbientCtx.Tracer.VisitSpans(func(span tracing.RegistrySpan) error {
for _, rec := range span.GetFullRecording(tracingpb.RecordingVerbose) {
trace := span.GetFullRecording(tracingpb.RecordingVerbose)
for _, rec := range trace.Flatten() {
traceID := rec.TraceID
parentSpanID := rec.ParentSpanID
spanID := rec.SpanID
Expand Down
6 changes: 3 additions & 3 deletions pkg/sql/sem/builtins/generator_builtins.go
Original file line number Diff line number Diff line change
Expand Up @@ -2253,12 +2253,12 @@ func (p *payloadsForSpanGenerator) Start(_ context.Context, _ *kv.Txn) error {
p.payloadIndex = -1

rec := p.span.GetFullRecording(tracingpb.RecordingStructured)
if rec == nil {
if rec.Empty() {
// No structured records.
return nil
}
p.payloads = make([]json.JSON, len(rec[0].StructuredRecords))
for i, sr := range rec[0].StructuredRecords {
p.payloads = make([]json.JSON, len(rec.Root.StructuredRecords))
for i, sr := range rec.Root.StructuredRecords {
var err error
p.payloads[i], err = protoreflect.MessageToJSON(sr.Payload, protoreflect.FmtFlags{EmitDefaults: true})
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion pkg/testutils/testcluster/testcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ func (tc *TestCluster) stopServers(ctx context.Context) {
fmt.Fprintf(&buf, "unexpectedly found %d active spans:\n", len(sps))
var ids []uint64
for _, sp := range sps {
rec := sp.GetFullRecording(tracingpb.RecordingVerbose)
trace := sp.GetFullRecording(tracingpb.RecordingVerbose)
rec := trace.Flatten()
for _, rs := range rec {
// NB: it would be a sight easier to just include these in the output of
// the string formatted recording, but making a change there presumably requires
Expand Down
Loading