Skip to content

Query Frontend: apply default_priority to metadata queries - #7942

Open
arpitjain099 wants to merge 1 commit into
cortexproject:masterfrom
arpitjain099:fix/metadata-query-default-priority
Open

arpitjain099 wants to merge 1 commit into
cortexproject:masterfrom
arpitjain099:fix/metadata-query-default-priority

Conversation

@arpitjain099

Copy link
Copy Markdown

What this PR does:

rejectQueryOrSetPriority splits on operation. The expression branch takes the first matching priority and then falls back to queryPriority.DefaultPriority. The metadata branch does neither: there is no fallback after the loop, and its break leaves only the inner loop, so a later matching priority overwrites an earlier one.

SetPriority is what flips PriorityAssigned, and both schedulerRequest.Priority() and request.Priority() return a hardcoded 0 when LoadPriority reports false. So /api/v1/labels, /api/v1/series and /api/v1/label/<name>/values are enqueued at 0 rather than at the tenant's default_priority. With default_priority: -1 and a priority: 0 class holding reserved_queriers, they land in the reserved class. The priority label of cortex_query_scheduler_queue_length reports 0 for them as well, and the query log drops the field.

#7128 extended query priority to operations beyond query and query_range, and the default fallback did not come across with it. This mirrors the expression branch: return nil on a match, SetPriority(DefaultPriority) after the loop. The branch also covers /api/v1/metadata and any other non-query path, so those pick up the default too.

Testing:

Test_rejectQueryOrSetPriorityShouldSetDefaultPriorityWhenNoAttributeMatches configures a single query_range priority that none of its four probes match, and asserts each one receives default_priority: 5. The three metadata cases fail on master with actual: 0. The instant-query case passes either way and is there as a control. The package goes from 166 passing with 4 failures to 170 passing, and tripperware, scheduler and frontend are green with the change, built with netgo slicelabels.

Which issue(s) this PR fixes:
N/A

Checklist

  • Tests updated
  • Documentation added (no config, flag or documented behaviour change)
  • CHANGELOG.md updated
  • docs/configuration/v1-guarantees.md updated if this PR introduces experimental flags (no new flags)

Prepared with the assistance of generative AI, reviewed and tested by me.

@arpitjain099
arpitjain099 requested a review from a team as a code owner November 17, 2026 15:05
Comment thread CHANGELOG.md Outdated
* [BUGFIX] Compactor: Delete block deletion markers left in the global `markers/` location of a tenant after the block they refer to was removed. They were skipped at every bucket index update and kept the tenant location in the bucket forever. #7890
* [BUGFIX] Ring: Fix an instance becoming permanently unable to acquire tokens. #7901
* [BUGFIX] Ingester: Stop `QueryStream` from reading the TSDB index after the request is canceled or times out. The series loop noticed cancellation only when it sent a batch, so a query shard whose series all failed the shard matcher, or the lazy matchers of `-ingester.enable-matcher-optimization`, kept decoding every series in its postings after the querier had given up. The loop now checks the request context every 128 series and returns the context error. #7931
* [BUGFIX] Query Frontend: Apply the tenant's `default_priority` to metadata queries. `/api/v1/labels`, `/api/v1/series` and `/api/v1/label/<name>/values` were left with no priority assigned when none of the configured query attributes matched, so the frontend and the scheduler both queued them at a hardcoded 0 instead of the configured default, the `priority` label of `cortex_query_scheduler_queue_length` reported 0 for them, and the query log omitted the field. A metadata query that does match an attribute now takes the first matching priority rather than the last. #7942

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The enqueue message doesn't carry priority, so the scheduler still sees 0. Can we pass it through or narrow this entry to the frontend?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, @sandy2008. You're right that the enqueue message carries no priority, so the scheduler still sees 0. I've narrowed the changelog entry to the query-frontend's own queue, which is where the fix actually applies, and rebased onto master to clear the conflict. If it helps, could I please open a separate issue to track the scheduler side?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it helps, could I please open a separate issue to track the scheduler side?

@arpitjain099 No need, #7949 already tracks it.

@sandy2008 sandy2008 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The narrowed CHANGELOG entry matches the code now. LGTM once the CHANGELOG conflict with master is resolved.

The metadata branch of rejectQueryOrSetPriority never fell back to the
tenant's default priority, so /api/v1/labels, /series and /label/*/values
were enqueued at a hardcoded 0. Its break also left only the inner loop, so
the last matching priority won where the expression branch takes the first.

Co-Authored-By: Claude <[email protected]>
Signed-off-by: Arpit Jain <[email protected]>
@arpitjain099
arpitjain099 force-pushed the fix/metadata-query-default-priority branch from 6472811 to 739cc54 Compare December 1, 2026 17:36
@arpitjain099

Copy link
Copy Markdown
Author

@sandy2008 Thanks for the #7949 pointer. The CHANGELOG conflict is resolved and pushed, the entry moved to the end of the BUGFIX list under master / unreleased, and both code files are unchanged from what you approved. Could you please take another look?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants