Skip to content

Commit ee1fdc0

Browse files
authored
fix(tracer): pass prioritySampler in agentTraceWriter benchmarks to prevent nil panic (#4601)
<!-- * New contributors are highly encouraged to read our [CONTRIBUTING](/CONTRIBUTING.md) documentation. * Commit and PR titles should be prefixed with the general area of the pull request's change. --> ### What does this PR do? Provides the agentTraceWriters used in writer_bench_test.go with a real prioritySampler, instead of nil. ### Motivation I noticed `BenchmarkAgentTraceWriterFlush` panicking with a nil pointer dereference because `newAgentTraceWriter` was called with a `nil` prioritySampler. This panics because, after a successful flush, the writer calls `prioritySampling.readRatesJSON`, which dereferences the `nil`. Passing `newPrioritySampler()` in all benchmark constructors avoids the panic and matches how the writer is created in production. ### Reviewer's Checklist <!-- * Authors can use this list as a reference to ensure that there are no problems during the review but the signing off is to be done by the reviewer(s). --> - [ ] Changed code has unit tests for its functionality at or near 100% coverage. - [ ] [System-Tests](https://github.com/DataDog/system-tests/) covering this feature have been added and enabled with the va.b.c-dev version tag. - [ ] There is a benchmark for any new code, or changes to existing code. - [ ] If this interacts with the agent in a new way, a system test has been added. - [ ] New code is free of linting errors. You can check this by running `make lint` locally. - [ ] New code doesn't break existing tests. You can check this by running `make test` locally. - [ ] Add an appropriate team label so this PR gets put in the right place for the release notes. - [ ] All generated files are up to date. You can check this by running `make generate` locally. - [ ] Non-trivial go.mod changes, e.g. adding new modules, are reviewed by @DataDog/dd-trace-go-guild. Make sure all nested modules are up to date by running `make fix-modules` locally. Unsure? Have a question? Request a review! Co-authored-by: mikayla.toffler <[email protected]>
1 parent 944319d commit ee1fdc0

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

ddtrace/tracer/writer_bench_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func BenchmarkAgentTraceWriterAdd(b *testing.B) {
3232
cfg, err := newTestConfig()
3333
require.NoError(b, err)
3434

35-
writer := newAgentTraceWriter(cfg, nil, &statsd)
35+
writer := newAgentTraceWriter(cfg, newPrioritySampler(), &statsd)
3636

3737
trace := make([]*Span, size.numSpans)
3838
for i := 0; i < size.numSpans; i++ {
@@ -54,7 +54,7 @@ func BenchmarkAgentTraceWriterFlush(b *testing.B) {
5454
cfg, err := newTestConfig()
5555
require.NoError(b, err)
5656

57-
writer := newAgentTraceWriter(cfg, nil, &statsd)
57+
writer := newAgentTraceWriter(cfg, newPrioritySampler(), &statsd)
5858
trace := []*Span{newBasicSpan("flush-test")}
5959

6060
b.ReportAllocs()
@@ -76,7 +76,7 @@ func BenchmarkAgentTraceWriterConcurrent(b *testing.B) {
7676
cfg, err := newTestConfig()
7777
require.NoError(b, err)
7878

79-
writer := newAgentTraceWriter(cfg, nil, &statsd)
79+
writer := newAgentTraceWriter(cfg, newPrioritySampler(), &statsd)
8080
trace := []*Span{newBasicSpan("concurrent-test")}
8181

8282
b.ReportAllocs()
@@ -102,7 +102,7 @@ func BenchmarkAgentTraceWriterStats(b *testing.B) {
102102
cfg, err := newTestConfig()
103103
require.NoError(b, err)
104104

105-
writer := newAgentTraceWriter(cfg, nil, &statsd)
105+
writer := newAgentTraceWriter(cfg, newPrioritySampler(), &statsd)
106106

107107
for range 10 {
108108
trace := []*Span{newBasicSpan("stats-test")}

0 commit comments

Comments
 (0)