diff --git a/CHANGELOG.md b/CHANGELOG.md index f32e39e4efe..709040ef422 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,6 +43,7 @@ * [BUGFIX] Ring: Fix `DoBatch` counting a key more than once when more replicas than the quorum succeed, which in rare cases could hide a write error from a key that did not reach quorum. A distributor push now always waits until every series reaches quorum, so it returns the error of a series that misses quorum, and takes as long as its slowest series to reach quorum. #7975 * [BUGFIX] Compactor: Stop downloading the parquet files and the `parquet-converter-mark.json` and `parquet-no-convert-mark.json` markers written by the parquet converter under a block's prefix. Compaction never reads them, so they only used local disk and bandwidth until the compaction job ended. #7972 * [BUGFIX] Ring: Fix shuffle-sharding subrings treating instances with a stale heartbeat as healthy when using the DynamoDB KV store. #7976 +* [BUGFIX] Query Frontend: Apply the tenant's `default_priority` to metadata queries. `/api/v1/labels`, `/api/v1/series` and `/api/v1/label//values` were left with no priority assigned when none of the configured query attributes matched, so the frontend's own queue ordered them at a hardcoded 0 instead of the configured default, the `priority` label of `cortex_query_frontend_queue_length` reported 0 for them, and the query stats log omitted the field. A metadata query that does match an attribute now takes the first matching priority rather than the last. #7942 ## 1.22.0 2026-11-19 diff --git a/pkg/querier/tripperware/query_attribute_matcher.go b/pkg/querier/tripperware/query_attribute_matcher.go index 54dcaee85cf..d32ef7ddc7c 100644 --- a/pkg/querier/tripperware/query_attribute_matcher.go +++ b/pkg/querier/tripperware/query_attribute_matcher.go @@ -77,10 +77,11 @@ func rejectQueryOrSetPriority(r *http.Request, now time.Time, lookbackDelta time for _, attribute := range priority.QueryAttributes { if matchAttributeForMetadataQuery(attribute, op, r, now) { reqStats.SetPriority(priority.Priority) - break + return nil } } } + reqStats.SetPriority(queryPriority.DefaultPriority) } } diff --git a/pkg/querier/tripperware/query_attribute_matcher_test.go b/pkg/querier/tripperware/query_attribute_matcher_test.go index 60d8d82f5a2..40aae4aecad 100644 --- a/pkg/querier/tripperware/query_attribute_matcher_test.go +++ b/pkg/querier/tripperware/query_attribute_matcher_test.go @@ -816,3 +816,39 @@ func Test_rejectQueryOrSetPriorityShouldMatchOnApiType(t *testing.T) { }) } } + +func Test_rejectQueryOrSetPriorityShouldSetDefaultPriorityWhenNoAttributeMatches(t *testing.T) { + // A single priority that only ever matches query_range, so neither request below matches it. + limits := mockLimits{queryPriority: validation.QueryPriority{ + Enabled: true, + DefaultPriority: 5, + Priorities: []validation.PriorityDef{ + { + Priority: 1, + QueryAttributes: []validation.QueryAttribute{ + {ApiType: "query_range"}, + }, + }, + }, + }} + + for name, path := range map[string]string{ + "instant query": "/api/v1/query?time=1536716898&query=up", + "label names": "/api/v1/labels", + "series": "/api/v1/series?match%5B%5D=up", + "label values": "/api/v1/label/foo/values", + } { + t.Run(name, func(t *testing.T) { + req, err := http.NewRequest("GET", path, http.NoBody) + require.NoError(t, err) + reqStats, ctx := stats.ContextWithEmptyStats(context.Background()) + req = req.WithContext(ctx) + + require.NoError(t, rejectQueryOrSetPriority(req, time.Now(), time.Duration(1), limits, "", rejectedQueriesPerTenant)) + + priority, assigned := reqStats.LoadPriority() + assert.True(t, assigned, "priority should have been assigned") + assert.Equal(t, int64(5), priority) + }) + } +}