Skip to content

Commit f12a8ae

Browse files
committed
Adding 'not_optimized_regex_matchers_count' field on the query stats
Signed-off-by: alanprot <[email protected]>
1 parent 06cedd9 commit f12a8ae

File tree

6 files changed

+114
-38
lines changed

6 files changed

+114
-38
lines changed

Diff for: pkg/frontend/transport/handler.go

+2
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,7 @@ func (f *Handler) reportQueryStats(r *http.Request, source, userID string, query
387387
numPeakSamples := stats.LoadPeakSamples()
388388
numChunkBytes := stats.LoadFetchedChunkBytes()
389389
numDataBytes := stats.LoadFetchedDataBytes()
390+
notOptimizedRegexMatchers := stats.LoadNotOptimizedRegexMatchers()
390391
numStoreGatewayTouchedPostings := stats.LoadStoreGatewayTouchedPostings()
391392
numStoreGatewayTouchedPostingBytes := stats.LoadStoreGatewayTouchedPostingBytes()
392393
splitQueries := stats.LoadSplitQueries()
@@ -431,6 +432,7 @@ func (f *Handler) reportQueryStats(r *http.Request, source, userID string, query
431432
"status_code", statusCode,
432433
"response_size", contentLength,
433434
"samples_scanned", numScannedSamples,
435+
"not_optimized_regex_matchers_count", notOptimizedRegexMatchers,
434436
}, stats.LoadExtraFields()...)
435437

436438
if numStoreGatewayTouchedPostings > 0 {

Diff for: pkg/querier/querier.go

+11
Original file line numberDiff line numberDiff line change
@@ -348,6 +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))
351352
stats.AddQueryStorageWallTime(time.Since(startT))
352353
}()
353354

@@ -610,6 +611,16 @@ func (u useBeforeTimestampQueryable) UseQueryable(_ time.Time, queryMinT, _ int6
610611
return queryMinT < u.ts
611612
}
612613

614+
func notOptimizedRegexMatchersCount(matchers []*labels.Matcher) uint64 {
615+
n := uint64(0)
616+
for _, matcher := range matchers {
617+
if matcher.GetRegexString() != "" && !matcher.IsRegexOptimized() {
618+
n++
619+
}
620+
}
621+
return n
622+
}
623+
613624
// Returns QueryableWithFilter, that is used only if query starts before given timestamp.
614625
// If timestamp is zero (time.IsZero), queryable is always used.
615626
func UseBeforeTimestampQueryable(queryable storage.Queryable, ts time.Time) QueryableWithFilter {

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

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

224+
func (s *QueryStats) AddNotOptimizedRegexMatchers(count uint64) {
225+
if s == nil {
226+
return
227+
}
228+
atomic.AddUint64(&s.NotOptimizedRegexCount, count)
229+
}
230+
231+
func (s *QueryStats) LoadNotOptimizedRegexMatchers() uint64 {
232+
if s == nil {
233+
return 0
234+
}
235+
236+
return atomic.LoadUint64(&s.NotOptimizedRegexCount)
237+
}
238+
224239
// LoadQueryStorageWallTime returns current query storage wall time.
225240
func (s *QueryStats) LoadQueryStorageWallTime() time.Duration {
226241
if s == nil {
@@ -390,6 +405,7 @@ func (s *QueryStats) Merge(other *QueryStats) {
390405
s.AddFetchedChunkBytes(other.LoadFetchedChunkBytes())
391406
s.AddFetchedDataBytes(other.LoadFetchedDataBytes())
392407
s.AddFetchedSamples(other.LoadFetchedSamples())
408+
s.AddNotOptimizedRegexMatchers(other.LoadNotOptimizedRegexMatchers())
393409
s.AddFetchedChunks(other.LoadFetchedChunks())
394410
s.AddStoreGatewayTouchedPostings(other.LoadStoreGatewayTouchedPostings())
395411
s.AddStoreGatewayTouchedPostingBytes(other.LoadStoreGatewayTouchedPostingBytes())

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

+82-38
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

+2
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,6 @@ message Stats {
4545
// The highest count of samples considered while evaluating a query.
4646
// Equal to PeakSamples in https://github.com/prometheus/prometheus/blob/main/util/stats/query_stats.go
4747
uint64 peak_samples = 14;
48+
// The total number of not optimized regex matchers
49+
uint64 not_optimized_regex_count = 15;
4850
}

Diff for: pkg/ruler/compat.go

+1
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ func RecordAndReportRuleQueryMetrics(qf rules.QueryFunc, userID string, evalMetr
292292
"fetched_samples_count", queryStats.FetchedSamplesCount,
293293
"fetched_chunks_bytes", queryStats.FetchedChunkBytes,
294294
"fetched_data_bytes", queryStats.FetchedDataBytes,
295+
"not_optimized_regex_matchers_count", queryStats.NotOptimizedRegexCount,
295296
)
296297
logMessage = append(logMessage, queryStats.LoadExtraFields()...)
297298
level.Info(util_log.WithContext(ctx, logger)).Log(logMessage...)

0 commit comments

Comments
 (0)