Skip to content

Commit

Permalink
Merge pull request #97919 from cockroachdb/blathers/backport-release-…
Browse files Browse the repository at this point in the history
…22.2-97897

release-22.2: tracing: fix stack gathering null bytes bug
  • Loading branch information
dt authored Mar 27, 2023
2 parents 1b606cd + f08c037 commit fc7ffbb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/util/tracing/tracer_snapshots.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ func (t *Tracer) generateSnapshot() SpansSnapshot {
stacks = make([]byte, n)
nbytes := runtime.Stack(stacks, true /* all */)
if nbytes < len(stacks) {
stacks = stacks[:nbytes]
break
}
}
Expand Down
19 changes: 19 additions & 0 deletions pkg/util/tracing/tracer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -878,3 +878,22 @@ func TestTracerClusterSettings(t *testing.T) {
require.False(t, sp.IsNoop())
sp.Finish()
}

func TestTracerSnapshots(t *testing.T) {
tr := NewTracer()

s1 := tr.SaveSnapshot()
require.Equal(t, SnapshotID(1), s1.ID)
_ = tr.SaveSnapshot()
s3 := tr.SaveSnapshot()
require.Equal(t, SnapshotID(3), s3.ID)
require.Equal(t, 3, len(tr.GetSnapshots()))

for _, i := range []SnapshotID{2, 1, 3} {
s, err := tr.GetSnapshot(i)
require.NoError(t, err)
for _, s := range s.Stacks {
require.Less(t, len(s), 5<<10, s)
}
}
}

0 comments on commit fc7ffbb

Please sign in to comment.