Skip to content

Commit 2447c46

Browse files
committed
Use a fixed seed for downsampling
1 parent 158ba59 commit 2447c46

File tree

1 file changed

+5
-1
lines changed
  • exporter/elasticsearchexporter/internal/serializer/otelserializer/serializeprofiles

1 file changed

+5
-1
lines changed

exporter/elasticsearchexporter/internal/serializer/otelserializer/serializeprofiles/downsampling.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ const (
8282

8383
var eventIndices = initEventIndexes(MaxEventsIndexes)
8484

85+
// A fixed seed is used for deterministic tests and development.
86+
// There is no downside in using a fixed seed in production.
87+
var rnd = rand.New(rand.NewPCG(0, 0))
88+
8589
// initEventIndexes initializes eventIndexes to avoid calculations for every TraceEvent later.
8690
func initEventIndexes(count int) []string {
8791
indices := make([]string, 0, count)
@@ -111,7 +115,7 @@ func IndexDownsampledEvent(event StackTraceEvent, pushData func(any, string, str
111115
for range event.Count {
112116
// samplingRatio is the probability p=0.2 for an event to be copied into the next
113117
// downsampled index.
114-
if rand.Float64() < SamplingRatio {
118+
if rnd.Float64() < SamplingRatio {
115119
count++
116120
}
117121
}

0 commit comments

Comments
 (0)