Skip to content

Commit 03fe272

Browse files
authored
[processor/tailsampling] fix benchmarks (open-telemetry#43947)
Several of the benchmarks were failing to run, this fixes them all for future use.
1 parent 3d79645 commit 03fe272

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

processor/tailsamplingprocessor/internal/idbatcher/id_batcher_test.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,27 @@ func TestMinBufferedChannels(t *testing.T) {
4949
func BenchmarkConcurrentEnqueue(b *testing.B) {
5050
ids := generateSequentialIDs(1)
5151
batcher, err := New(10, 100, uint64(4*runtime.NumCPU()))
52-
defer batcher.Stop()
5352
require.NoError(b, err, "Failed to create Batcher")
5453

5554
ticker := time.NewTicker(100 * time.Millisecond)
56-
defer ticker.Stop()
55+
var wg sync.WaitGroup
56+
defer func() {
57+
batcher.Stop()
58+
wg.Wait()
59+
ticker.Stop()
60+
}()
5761
ticked := &atomic.Int64{}
5862
received := &atomic.Int64{}
63+
wg.Add(1)
5964
go func() {
65+
defer wg.Done()
6066
for range ticker.C {
61-
batch, _ := batcher.CloseCurrentAndTakeFirstBatch()
67+
batch, more := batcher.CloseCurrentAndTakeFirstBatch()
6268
ticked.Add(1)
6369
received.Add(int64(len(batch)))
70+
if !more {
71+
return
72+
}
6473
}
6574
}()
6675

processor/tailsamplingprocessor/internal/sampling/util_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ func TestSetAttrOnScopeSpans_Many(t *testing.T) {
6363

6464
func BenchmarkSetAttrOnScopeSpans(b *testing.B) {
6565
for b.Loop() {
66+
b.StopTimer()
6667
traces := ptrace.NewTraces()
6768

6869
for range 5 {
@@ -86,6 +87,5 @@ func BenchmarkSetAttrOnScopeSpans(b *testing.B) {
8687

8788
b.StartTimer()
8889
SetAttrOnScopeSpans(traceData, "test.attr", "value")
89-
b.StopTimer()
9090
}
9191
}

processor/tailsamplingprocessor/processor_benchmarks_test.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
package tailsamplingprocessor
55

66
import (
7+
"sync/atomic"
78
"testing"
89
"time"
910

1011
"github.com/stretchr/testify/require"
1112
"go.opentelemetry.io/collector/component/componenttest"
1213
"go.opentelemetry.io/collector/consumer/consumertest"
13-
"go.opentelemetry.io/collector/pdata/ptrace"
1414
"go.opentelemetry.io/collector/processor/processortest"
1515

1616
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/tailsamplingprocessor/internal/metadata"
@@ -31,14 +31,16 @@ func BenchmarkSampling(b *testing.B) {
3131
defer func() {
3232
require.NoError(b, tsp.Shutdown(b.Context()))
3333
}()
34-
metrics := &policyMetrics{}
34+
metrics := newPolicyMetrics(len(cfg.PolicyCfgs))
3535
sampleBatches := make([]*samplingpolicy.TraceData, 0, len(batches))
3636

37-
for range batches {
37+
for _, batch := range batches {
38+
spanCount := &atomic.Int64{}
39+
spanCount.Store(int64(batch.SpanCount()))
3840
sampleBatches = append(sampleBatches, &samplingpolicy.TraceData{
39-
ArrivalTime: time.Now(),
40-
// SpanCount: spanCount,
41-
ReceivedBatches: ptrace.NewTraces(),
41+
ArrivalTime: time.Now(),
42+
SpanCount: spanCount,
43+
ReceivedBatches: batch,
4244
})
4345
}
4446

0 commit comments

Comments
 (0)