Skip to content

Commit

Permalink
Exclude vector queries from being counted in metric for rules with ze…
Browse files Browse the repository at this point in the history
…ro fetched series
  • Loading branch information
zenador committed Nov 2, 2023
1 parent dc6ff68 commit 6f0f8db
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
* [ENHANCEMENT] Add connection-string option, `-<prefix>.azure.connection-string`, for Azure Blob Storage. #6487
* [ENHANCEMENT] Ingester: Add `-ingester.instance-limits.max-inflight-push-requests-bytes`. This limit protects the ingester against requests that together may cause an OOM. #6492
* [ENHANCEMENT] Ingester: add new per-tenant `cortex_ingester_local_limits` metric to expose the calculated local per-tenant limits seen at each ingester. Exports the local per-tenant series limit with label `{limit="max_global_series_per_user"}` #6403
* [ENHANCEMENT] Ruler: exclude vector queries from being tracked in `cortex_ruler_queries_zero_fetched_series_total`. #6544
* [BUGFIX] Ring: Ensure network addresses used for component hash rings are formatted correctly when using IPv6. #6068
* [BUGFIX] Query-scheduler: don't retain connections from queriers that have shut down, leading to gradually increasing enqueue latency over time. #6100 #6145
* [BUGFIX] Ingester: prevent query logic from continuing to execute after queries are canceled. #6085
Expand Down
7 changes: 6 additions & 1 deletion pkg/ruler/compat.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/gogo/status"
"github.com/grafana/dskit/httpgrpc"
"github.com/grafana/dskit/user"
"github.com/grafana/regexp"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prometheus/prometheus/model/exemplar"
Expand All @@ -32,6 +33,8 @@ import (
util_log "github.com/grafana/mimir/pkg/util/log"
)

var rVector = regexp.MustCompile(`vector\([\d.e+/ ]+\)`)

// Pusher is an ingester server that accepts pushes.
type Pusher interface {
Push(context.Context, *mimirpb.WriteRequest) (*mimirpb.WriteResponse, error)
Expand Down Expand Up @@ -208,7 +211,9 @@ func RecordAndReportRuleQueryMetrics(qf rules.QueryFunc, queryTime, zeroFetchedS
shardedQueries := stats.LoadShardedQueries()

queryTime.Add(wallTime.Seconds())
if err == nil && numSeries == 0 { // Do not count queries with errors for zero fetched series.
// Do not count queries with errors for zero fetched series, or vector queries that are not
// meant to fetch any series.
if err == nil && numSeries == 0 && !rVector.MatchString(qs) {
zeroFetchedSeriesCount.Add(1)
}

Expand Down
8 changes: 8 additions & 0 deletions pkg/ruler/compat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,14 @@ func TestRecordAndReportRuleQueryMetrics(t *testing.T) {
_, _ = qf(context.Background(), "test", time.Now())
require.LessOrEqual(t, float64(2), testutil.ToFloat64(queryTime.WithLabelValues("userID")))
require.Equal(t, float64(2), testutil.ToFloat64(zeroFetchedSeriesCount.WithLabelValues("userID")))

_, _ = qf(context.Background(), "vector(0.995)", time.Now())
require.LessOrEqual(t, float64(2), testutil.ToFloat64(queryTime.WithLabelValues("userID")))
require.Equal(t, float64(2), testutil.ToFloat64(zeroFetchedSeriesCount.WithLabelValues("userID")))

_, _ = qf(context.Background(), "vector(2.4192e+15 / 1e+09)", time.Now())
require.LessOrEqual(t, float64(2), testutil.ToFloat64(queryTime.WithLabelValues("userID")))
require.Equal(t, float64(2), testutil.ToFloat64(zeroFetchedSeriesCount.WithLabelValues("userID")))
}

// TestManagerFactory_CorrectQueryableUsed ensures that when evaluating a group with non-empty SourceTenants
Expand Down

0 comments on commit 6f0f8db

Please sign in to comment.