diff --git a/pkg/frontend/transport/handler.go b/pkg/frontend/transport/handler.go index c1c6ce05d7..874d06dc61 100644 --- a/pkg/frontend/transport/handler.go +++ b/pkg/frontend/transport/handler.go @@ -387,6 +387,7 @@ func (f *Handler) reportQueryStats(r *http.Request, source, userID string, query numPeakSamples := stats.LoadPeakSamples() numChunkBytes := stats.LoadFetchedChunkBytes() numDataBytes := stats.LoadFetchedDataBytes() + notOptimizedRegexMatchers := stats.LoadNotOptimizedRegexMatchers() numStoreGatewayTouchedPostings := stats.LoadStoreGatewayTouchedPostings() numStoreGatewayTouchedPostingBytes := stats.LoadStoreGatewayTouchedPostingBytes() splitQueries := stats.LoadSplitQueries() @@ -431,6 +432,7 @@ func (f *Handler) reportQueryStats(r *http.Request, source, userID string, query "status_code", statusCode, "response_size", contentLength, "samples_scanned", numScannedSamples, + "not_optimized_regex_matchers_count", notOptimizedRegexMatchers, }, stats.LoadExtraFields()...) if numStoreGatewayTouchedPostings > 0 { diff --git a/pkg/querier/querier.go b/pkg/querier/querier.go index f13121caf9..0cd486fa62 100644 --- a/pkg/querier/querier.go +++ b/pkg/querier/querier.go @@ -348,6 +348,7 @@ func (q querier) Select(ctx context.Context, sortSeries bool, sp *storage.Select } startT := time.Now() defer func() { + stats.StoreMaxNotOptimizedRegexMatchers(notOptimizedRegexMatchersCount(matchers)) stats.AddQueryStorageWallTime(time.Since(startT)) }() @@ -610,6 +611,16 @@ func (u useBeforeTimestampQueryable) UseQueryable(_ time.Time, queryMinT, _ int6 return queryMinT < u.ts } +func notOptimizedRegexMatchersCount(matchers []*labels.Matcher) uint64 { + n := uint64(0) + for _, matcher := range matchers { + if matcher.GetRegexString() != "" && !matcher.IsRegexOptimized() { + n++ + } + } + return n +} + // Returns QueryableWithFilter, that is used only if query starts before given timestamp. // If timestamp is zero (time.IsZero), queryable is always used. func UseBeforeTimestampQueryable(queryable storage.Queryable, ts time.Time) QueryableWithFilter { diff --git a/pkg/querier/stats/stats.go b/pkg/querier/stats/stats.go index 127c422878..d74ae4f4ee 100644 --- a/pkg/querier/stats/stats.go +++ b/pkg/querier/stats/stats.go @@ -221,6 +221,23 @@ func (s *QueryStats) AddQueryStorageWallTime(t time.Duration) { atomic.AddInt64((*int64)(&s.QueryStorageWallTime), int64(t)) } +func (s *QueryStats) StoreMaxNotOptimizedRegexMatchers(count uint64) { + if s == nil { + return + } + + // For this stats we get the MAX, instead of adding the counts + // as for split queries we will call this method multiples times. + atomic.StoreUint64(&s.NotOptimizedRegexCount, max(count, s.LoadNotOptimizedRegexMatchers())) +} + +func (s *QueryStats) LoadNotOptimizedRegexMatchers() uint64 { + if s == nil { + return 0 + } + return atomic.LoadUint64(&s.NotOptimizedRegexCount) +} + // LoadQueryStorageWallTime returns current query storage wall time. func (s *QueryStats) LoadQueryStorageWallTime() time.Duration { if s == nil { @@ -390,6 +407,7 @@ func (s *QueryStats) Merge(other *QueryStats) { s.AddFetchedChunkBytes(other.LoadFetchedChunkBytes()) s.AddFetchedDataBytes(other.LoadFetchedDataBytes()) s.AddFetchedSamples(other.LoadFetchedSamples()) + s.StoreMaxNotOptimizedRegexMatchers(other.LoadNotOptimizedRegexMatchers()) s.AddFetchedChunks(other.LoadFetchedChunks()) s.AddStoreGatewayTouchedPostings(other.LoadStoreGatewayTouchedPostings()) s.AddStoreGatewayTouchedPostingBytes(other.LoadStoreGatewayTouchedPostingBytes()) diff --git a/pkg/querier/stats/stats.pb.go b/pkg/querier/stats/stats.pb.go index ea6f4ba418..fa26dd46c9 100644 --- a/pkg/querier/stats/stats.pb.go +++ b/pkg/querier/stats/stats.pb.go @@ -65,6 +65,8 @@ type Stats struct { // The highest count of samples considered while evaluating a query. // Equal to PeakSamples in https://github.com/prometheus/prometheus/blob/main/util/stats/query_stats.go PeakSamples uint64 `protobuf:"varint,14,opt,name=peak_samples,json=peakSamples,proto3" json:"peak_samples,omitempty"` + // The total number of not optimized regex matchers + NotOptimizedRegexCount uint64 `protobuf:"varint,15,opt,name=not_optimized_regex_count,json=notOptimizedRegexCount,proto3" json:"not_optimized_regex_count,omitempty"` } func (m *Stats) Reset() { *m = Stats{} } @@ -197,6 +199,13 @@ func (m *Stats) GetPeakSamples() uint64 { return 0 } +func (m *Stats) GetNotOptimizedRegexCount() uint64 { + if m != nil { + return m.NotOptimizedRegexCount + } + return 0 +} + func init() { proto.RegisterType((*Stats)(nil), "stats.Stats") proto.RegisterMapType((map[string]string)(nil), "stats.Stats.ExtraFieldsEntry") @@ -205,43 +214,46 @@ func init() { func init() { proto.RegisterFile("stats.proto", fileDescriptor_b4756a0aec8b9d44) } var fileDescriptor_b4756a0aec8b9d44 = []byte{ - // 574 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x53, 0xcf, 0x6e, 0xd3, 0x30, - 0x18, 0x8f, 0xb7, 0x75, 0x2c, 0x4e, 0x37, 0x46, 0x28, 0x22, 0x9b, 0x84, 0xd7, 0x31, 0x24, 0x7a, - 0x40, 0x19, 0x2a, 0x17, 0x04, 0x12, 0x9a, 0xba, 0x0d, 0x38, 0x20, 0x04, 0xed, 0x24, 0xa4, 0x5d, - 0x2c, 0xb7, 0x75, 0xd3, 0xa8, 0x69, 0x52, 0x12, 0x87, 0x91, 0x1b, 0x8f, 0xc0, 0x91, 0x47, 0xe0, - 0x51, 0x7a, 0xa3, 0xc7, 0x9d, 0x06, 0x4d, 0x2f, 0x1c, 0xf7, 0x08, 0xc8, 0x9f, 0x9d, 0x16, 0x26, - 0x81, 0xb8, 0xc5, 0xdf, 0xef, 0x8f, 0xfc, 0xfb, 0x7d, 0x31, 0xb6, 0x12, 0xc1, 0x44, 0xe2, 0x8e, - 0xe2, 0x48, 0x44, 0x76, 0x09, 0x0e, 0xdb, 0x15, 0x2f, 0xf2, 0x22, 0x98, 0xec, 0xcb, 0x2f, 0x05, - 0x6e, 0x13, 0x2f, 0x8a, 0xbc, 0x80, 0xef, 0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0x0a, 0x7b, 0x13, 0x2f, 0x0f, 0x78, 0x06, 0xaf, 0xc2, 0x6c, 0xca, 0x4f, 0xbb, 0x82, 0x4b, - 0x1f, 0x58, 0x90, 0x72, 0xf8, 0xb9, 0xcd, 0xa6, 0x3a, 0x3c, 0x59, 0x7a, 0x8c, 0x1a, 0x4f, 0x27, - 0x53, 0x62, 0x9c, 0x4f, 0x89, 0x71, 0x39, 0x25, 0xe8, 0x53, 0x4e, 0xd0, 0xd7, 0x9c, 0xa0, 0x71, - 0x4e, 0xd0, 0x24, 0x27, 0xe8, 0x47, 0x4e, 0xd0, 0xcf, 0x9c, 0x18, 0x97, 0x39, 0x41, 0x9f, 0x67, - 0xc4, 0x98, 0xcc, 0x88, 0x71, 0x3e, 0x23, 0xc6, 0xa9, 0x7a, 0xdf, 0xed, 0x55, 0xd8, 0xcc, 0xa3, - 0x5f, 0x01, 0x00, 0x00, 0xff, 0xff, 0xd3, 0x67, 0xda, 0xe5, 0xfc, 0x03, 0x00, 0x00, + // 610 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x94, 0xcb, 0x4e, 0x14, 0x4f, + 0x14, 0xc6, 0xbb, 0x80, 0x01, 0xa6, 0x66, 0xb8, 0xfc, 0xfb, 0x3f, 0x6a, 0x43, 0x62, 0x31, 0x88, + 0x89, 0xb3, 0x30, 0x8d, 0xc1, 0x8d, 0x97, 0xc4, 0x90, 0x01, 0xd4, 0x85, 0xf1, 0xd2, 0x43, 0x62, + 0xc2, 0xa6, 0x52, 0xcc, 0x14, 0x4d, 0x85, 0x9e, 0xae, 0xb6, 0xbb, 0x5a, 0x68, 0x57, 0xae, 0x5d, + 0xb9, 0xf4, 0x11, 0x7c, 0x14, 0x96, 0x2c, 0x59, 0xa1, 0x34, 0x1b, 0x97, 0x3c, 0x82, 0xa9, 0x53, + 0xd5, 0xa0, 0x24, 0x1a, 0x77, 0x5d, 0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e, 0xc9, 0xfa, 0x2c, 0x8e, 0x2f, 0xa7, 0xee, 0x4d, 0x41, 0xe7, 0xb4, 0x2d, 0xdb, + 0x79, 0xbb, 0x8b, 0xb8, 0x99, 0x70, 0xb6, 0x77, 0xa1, 0x9a, 0x06, 0x55, 0x43, 0xd7, 0x2a, 0xc9, + 0x43, 0x3c, 0x17, 0x4b, 0x45, 0x65, 0xa2, 0xc4, 0x50, 0x7c, 0xe0, 0x03, 0x9a, 0xf2, 0x90, 0x1f, + 0xd8, 0x78, 0x33, 0xa0, 0xbf, 0x1e, 0x4b, 0xf5, 0xaa, 0xe2, 0x81, 0xc6, 0x10, 0x6a, 0xfe, 0x09, + 0x9e, 0xbd, 0xfa, 0x7b, 0x72, 0x67, 0xf1, 0xe8, 0x1e, 0x2f, 0xe0, 0x41, 0xd5, 0x03, 0xfd, 0xe9, + 0xb6, 0x70, 0xed, 0x3d, 0x8b, 0x72, 0x0e, 0xef, 0xa2, 0x1e, 0x98, 0xc3, 0xa3, 0x91, 0x07, 0xa8, + 0xfb, 0xf8, 0xe8, 0x94, 0x38, 0xc7, 0xa7, 0xc4, 0x39, 0x3f, 0x25, 0xe8, 0x63, 0x49, 0xd0, 0xd7, + 0x92, 0xa0, 0xc3, 0x92, 0xa0, 0xa3, 0x92, 0xa0, 0xef, 0x25, 0x41, 0x3f, 0x4a, 0xe2, 0x9c, 0x97, + 0x04, 0x7d, 0x3e, 0x23, 0xce, 0xd1, 0x19, 0x71, 0x8e, 0xcf, 0x88, 0xb3, 0x65, 0xfe, 0x1a, 0xb6, + 0xc7, 0x61, 0xa9, 0xf7, 0x7f, 0x06, 0x00, 0x00, 0xff, 0xff, 0x85, 0xc6, 0xa6, 0x98, 0x37, 0x04, + 0x00, 0x00, } func (this *Stats) Equal(that interface{}) bool { @@ -310,13 +322,16 @@ func (this *Stats) Equal(that interface{}) bool { if this.PeakSamples != that1.PeakSamples { return false } + if this.NotOptimizedRegexCount != that1.NotOptimizedRegexCount { + return false + } return true } func (this *Stats) GoString() string { if this == nil { return "nil" } - s := make([]string, 0, 18) + s := make([]string, 0, 19) s = append(s, "&stats.Stats{") s = append(s, "WallTime: "+fmt.Sprintf("%#v", this.WallTime)+",\n") s = append(s, "FetchedSeriesCount: "+fmt.Sprintf("%#v", this.FetchedSeriesCount)+",\n") @@ -344,6 +359,7 @@ func (this *Stats) GoString() string { s = append(s, "StoreGatewayTouchedPostingBytes: "+fmt.Sprintf("%#v", this.StoreGatewayTouchedPostingBytes)+",\n") s = append(s, "ScannedSamples: "+fmt.Sprintf("%#v", this.ScannedSamples)+",\n") s = append(s, "PeakSamples: "+fmt.Sprintf("%#v", this.PeakSamples)+",\n") + s = append(s, "NotOptimizedRegexCount: "+fmt.Sprintf("%#v", this.NotOptimizedRegexCount)+",\n") s = append(s, "}") return strings.Join(s, "") } @@ -375,6 +391,11 @@ func (m *Stats) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if m.NotOptimizedRegexCount != 0 { + i = encodeVarintStats(dAtA, i, uint64(m.NotOptimizedRegexCount)) + i-- + dAtA[i] = 0x78 + } if m.PeakSamples != 0 { i = encodeVarintStats(dAtA, i, uint64(m.PeakSamples)) i-- @@ -533,6 +554,9 @@ func (m *Stats) Size() (n int) { if m.PeakSamples != 0 { n += 1 + sovStats(uint64(m.PeakSamples)) } + if m.NotOptimizedRegexCount != 0 { + n += 1 + sovStats(uint64(m.NotOptimizedRegexCount)) + } return n } @@ -571,6 +595,7 @@ func (this *Stats) String() string { `StoreGatewayTouchedPostingBytes:` + fmt.Sprintf("%v", this.StoreGatewayTouchedPostingBytes) + `,`, `ScannedSamples:` + fmt.Sprintf("%v", this.ScannedSamples) + `,`, `PeakSamples:` + fmt.Sprintf("%v", this.PeakSamples) + `,`, + `NotOptimizedRegexCount:` + fmt.Sprintf("%v", this.NotOptimizedRegexCount) + `,`, `}`, }, "") return s @@ -1027,6 +1052,25 @@ func (m *Stats) Unmarshal(dAtA []byte) error { break } } + case 15: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field NotOptimizedRegexCount", wireType) + } + m.NotOptimizedRegexCount = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowStats + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.NotOptimizedRegexCount |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } default: iNdEx = preIndex skippy, err := skipStats(dAtA[iNdEx:]) diff --git a/pkg/querier/stats/stats.proto b/pkg/querier/stats/stats.proto index 8e53e02ccc..47ed1bc9a0 100644 --- a/pkg/querier/stats/stats.proto +++ b/pkg/querier/stats/stats.proto @@ -45,4 +45,6 @@ message Stats { // The highest count of samples considered while evaluating a query. // Equal to PeakSamples in https://github.com/prometheus/prometheus/blob/main/util/stats/query_stats.go uint64 peak_samples = 14; + // The total number of not optimized regex matchers + uint64 not_optimized_regex_count = 15; } diff --git a/pkg/querier/stats/stats_test.go b/pkg/querier/stats/stats_test.go index 5f2e850aef..b3d2f590a5 100644 --- a/pkg/querier/stats/stats_test.go +++ b/pkg/querier/stats/stats_test.go @@ -221,6 +221,7 @@ func TestStats_Merge(t *testing.T) { stats1.AddFetchedSamples(109) stats1.AddScannedSamples(100) stats1.AddPeakSamples(100) + stats1.StoreMaxNotOptimizedRegexMatchers(2) stats1.AddExtraFields("a", "b") stats1.AddExtraFields("a", "b") @@ -234,6 +235,7 @@ func TestStats_Merge(t *testing.T) { stats1.AddStoreGatewayTouchedPostingBytes(301) stats2.AddFetchedChunks(102) stats2.AddFetchedSamples(103) + stats2.StoreMaxNotOptimizedRegexMatchers(3) stats2.AddPeakSamples(105) stats2.AddScannedSamples(105) stats2.AddExtraFields("c", "d") @@ -251,6 +253,7 @@ func TestStats_Merge(t *testing.T) { assert.Equal(t, uint64(105), stats1.LoadPeakSamples()) assert.Equal(t, uint64(401), stats1.LoadStoreGatewayTouchedPostings()) assert.Equal(t, uint64(601), stats1.LoadStoreGatewayTouchedPostingBytes()) + assert.Equal(t, uint64(3), stats1.LoadNotOptimizedRegexMatchers()) checkExtraFields(t, []interface{}{"a", "b", "c", "d"}, stats1.LoadExtraFields()) }) diff --git a/pkg/ruler/compat.go b/pkg/ruler/compat.go index eb34ee02e3..113acb6ea0 100644 --- a/pkg/ruler/compat.go +++ b/pkg/ruler/compat.go @@ -292,6 +292,7 @@ func RecordAndReportRuleQueryMetrics(qf rules.QueryFunc, userID string, evalMetr "fetched_samples_count", queryStats.FetchedSamplesCount, "fetched_chunks_bytes", queryStats.FetchedChunkBytes, "fetched_data_bytes", queryStats.FetchedDataBytes, + "not_optimized_regex_matchers_count", queryStats.NotOptimizedRegexCount, ) logMessage = append(logMessage, queryStats.LoadExtraFields()...) level.Info(util_log.WithContext(ctx, logger)).Log(logMessage...)