[DO NOT MERGE] Rule group select merging #7522
Draft
alanprot wants to merge 1 commit into
Draft
Conversation
88e3d22 to
5ae03f9
Compare
…eries When a rule group has multiple rules querying the same metric with overlapping matchers, pre-fetch the broadest query once and serve individual rules from the cached result with local filtering. - Parse rules' PromQL expressions, group by metric + expression structure - Detect superset matchers (e.g., =~".*" covers "blue" and "green") - Pre-fetch broadest rule's expression once via QueryFunc - Serve subsequent rules from cached Vector with local matcher filtering - Zero vendored changes — uses context injection via GroupEvalIterationFunc Config: --ruler.select-merger-enabled, --ruler.select-merger-min-rules Benchmark: 114 → 38 queries per group evaluation (66% reduction)
5ae03f9 to
93ccc9a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Rule Group Select Merging — Reduce redundant ingester queries
What
When a rule group has multiple rules querying the same metric with overlapping matchers (e.g., different label filter variants), this optimization pre-fetches the broadest query once and serves individual rules from the cached result with local filtering.
Why
Rule groups often contain multiple rules querying the same metric with slightly different label filters (e.g., per-environment, per-deployment variant). Each rule independently queries the ingester even when one rule's matchers are a superset of the others. This results in redundant postings resolution and series fetching that scales linearly with the number of variants.
How
Uses the existing
GroupEvalIterationFunchook — zero vendored Prometheus changes. The QueryFunc is wrapped at construction time to check context for a prefetch cache, and the iteration func injects the cache via context.Flow per group evaluation:
=~".*"covers"blue"and"green")Configuration
Flags:
--ruler.select-merger-enabled,--ruler.select-merger-min-rulesSafety
rate(m{...}[5m])andsum(m{...})are never mergedjob="api"+job="web"(no superset) won't mergeBenchmark
66% query reduction, 19% faster, 28% fewer allocations.
Files
pkg/ruler/select_merger.gopkg/ruler/prefetch_queryable.gopkg/ruler/manager.gopkg/ruler/ruler.gopkg/ruler/compat.go