Skip to content

Commit 6294bba

Browse files
authored
fix panic due to concurent access to rand in active queried series (#7329)
Signed-off-by: yeya24 <benye@amazon.com>
1 parent 5894083 commit 6294bba

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

pkg/ingester/active_queried_series.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ type ActiveQueriedSeries struct {
3131
windows []*hllWindow
3232
currentWindow int
3333
sampleRate float64
34-
rng *rand.Rand
3534
logger log.Logger
3635
mu sync.RWMutex
3736

@@ -85,19 +84,20 @@ func NewActiveQueriedSeries(windowsToQuery []time.Duration, windowDuration time.
8584
windows: windows,
8685
currentWindow: numWindows - 1, // Start with the most recent window
8786
sampleRate: sampleRate,
88-
rng: rand.New(rand.NewSource(time.Now().UnixNano())),
8987
logger: logger,
9088
cache: make(map[time.Duration]*mergedCacheEntry),
9189
}
9290
}
9391

9492
// SampleRequest returns whether this request should be sampled based on sampling.
9593
// This should be called before collecting hashes to avoid unnecessary work.
94+
// Uses the global rand source which is safe for concurrent use, avoiding the
95+
// data race that occurs when multiple goroutines access a shared *rand.Rand.
9696
func (a *ActiveQueriedSeries) SampleRequest() bool {
9797
if a.sampleRate >= 1.0 {
9898
return true // 100% sampling, always track
9999
}
100-
return a.rng.Float64() <= a.sampleRate
100+
return rand.Float64() <= a.sampleRate
101101
}
102102

103103
// UpdateSeriesBatch adds multiple series hashes to the current active window in a single batch.

0 commit comments

Comments
 (0)