Skip to content

Commit 9d54802

Browse files
committed
adding merge test
Signed-off-by: alanprot <[email protected]>
1 parent f12a8ae commit 9d54802

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

Diff for: pkg/querier/querier.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ func (q querier) Select(ctx context.Context, sortSeries bool, sp *storage.Select
348348
}
349349
startT := time.Now()
350350
defer func() {
351-
stats.AddNotOptimizedRegexMatchers(notOptimizedRegexMatchersCount(matchers))
351+
stats.StoreNotOptimizedRegexMatchers(notOptimizedRegexMatchersCount(matchers))
352352
stats.AddQueryStorageWallTime(time.Since(startT))
353353
}()
354354

Diff for: pkg/querier/stats/stats.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -221,18 +221,20 @@ func (s *QueryStats) AddQueryStorageWallTime(t time.Duration) {
221221
atomic.AddInt64((*int64)(&s.QueryStorageWallTime), int64(t))
222222
}
223223

224-
func (s *QueryStats) AddNotOptimizedRegexMatchers(count uint64) {
224+
func (s *QueryStats) StoreNotOptimizedRegexMatchers(count uint64) {
225225
if s == nil {
226226
return
227227
}
228-
atomic.AddUint64(&s.NotOptimizedRegexCount, count)
228+
229+
// For this stats we get the MAX, instead of adding the counts
230+
// as for split queries we will call this method multiples times.
231+
atomic.StoreUint64(&s.NotOptimizedRegexCount, max(count, s.LoadNotOptimizedRegexMatchers()))
229232
}
230233

231234
func (s *QueryStats) LoadNotOptimizedRegexMatchers() uint64 {
232235
if s == nil {
233236
return 0
234237
}
235-
236238
return atomic.LoadUint64(&s.NotOptimizedRegexCount)
237239
}
238240

@@ -405,7 +407,7 @@ func (s *QueryStats) Merge(other *QueryStats) {
405407
s.AddFetchedChunkBytes(other.LoadFetchedChunkBytes())
406408
s.AddFetchedDataBytes(other.LoadFetchedDataBytes())
407409
s.AddFetchedSamples(other.LoadFetchedSamples())
408-
s.AddNotOptimizedRegexMatchers(other.LoadNotOptimizedRegexMatchers())
410+
s.StoreNotOptimizedRegexMatchers(other.LoadNotOptimizedRegexMatchers())
409411
s.AddFetchedChunks(other.LoadFetchedChunks())
410412
s.AddStoreGatewayTouchedPostings(other.LoadStoreGatewayTouchedPostings())
411413
s.AddStoreGatewayTouchedPostingBytes(other.LoadStoreGatewayTouchedPostingBytes())

Diff for: pkg/querier/stats/stats_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ func TestStats_Merge(t *testing.T) {
221221
stats1.AddFetchedSamples(109)
222222
stats1.AddScannedSamples(100)
223223
stats1.AddPeakSamples(100)
224+
stats1.StoreNotOptimizedRegexMatchers(2)
224225
stats1.AddExtraFields("a", "b")
225226
stats1.AddExtraFields("a", "b")
226227

@@ -234,6 +235,7 @@ func TestStats_Merge(t *testing.T) {
234235
stats1.AddStoreGatewayTouchedPostingBytes(301)
235236
stats2.AddFetchedChunks(102)
236237
stats2.AddFetchedSamples(103)
238+
stats2.StoreNotOptimizedRegexMatchers(3)
237239
stats2.AddPeakSamples(105)
238240
stats2.AddScannedSamples(105)
239241
stats2.AddExtraFields("c", "d")
@@ -251,6 +253,7 @@ func TestStats_Merge(t *testing.T) {
251253
assert.Equal(t, uint64(105), stats1.LoadPeakSamples())
252254
assert.Equal(t, uint64(401), stats1.LoadStoreGatewayTouchedPostings())
253255
assert.Equal(t, uint64(601), stats1.LoadStoreGatewayTouchedPostingBytes())
256+
assert.Equal(t, uint64(3), stats1.LoadNotOptimizedRegexMatchers())
254257
checkExtraFields(t, []interface{}{"a", "b", "c", "d"}, stats1.LoadExtraFields())
255258
})
256259

0 commit comments

Comments
 (0)