filter: prune StoreAPI fan-out for enumerable regex __name__ matchers - #9006
Open
HarnageaGabriel wants to merge 1 commit into
Open
HarnageaGabriel wants to merge 1 commit into
HarnageaGabriel wants to merge 1 commit into
Conversation
The Cuckoo metric-name store filter (enabled with `--enable-feature=metric-names-filter`) previously only excluded a store when the query carried an exact `__name__="x"` matcher. The very common dashboard pattern `__name__=~"a|b|c"` bypassed the filter entirely and always triggered a fan-out request, even when none of the listed metric names exist on that store. `Matches` now collects every `__name__` matcher and treats regex matchers whose value set is fully enumerable (`labels.Matcher.SetMatches()`) as constraints too. A store is skipped when, for at least one constraint, none of its candidate metric names are present in the filter. Regex matchers that cannot be reduced to a literal set (e.g. `__name__=~"a.*"`) stay non-constraining, so correctness is unchanged. Refs thanos-io#1611 Signed-off-by: HarnageaGabriel <gabriel.harnagea06@gmail.com>
HarnageaGabriel
force-pushed
the
feature/metric-name-filter-regex-sets
branch
from
September 2, 2026 21:19
e13452f to
e2cdc22
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #9006 +/- ##
==========================================
+ Coverage 64.51% 64.65% +0.14%
==========================================
Files 289 289
Lines 37352 37387 +35
==========================================
+ Hits 24097 24174 +77
+ Misses 11158 11128 -30
+ Partials 2097 2085 -12 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
GiedriusS
reviewed
Sep 3, 2026
| f.mtx.RLock() | ||
| defer f.mtx.RUnlock() | ||
|
|
||
| var constraints [][]string |
Member
There was a problem hiding this comment.
Awesome change! Only thing I'd ask you to do is maybe we can pool the slice here? This is a very hot path
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.
Changes
Extends the Cuckoo metric-name store filter (
--enable-feature=metric-names-filter, added in #7787) so it can prune fan-out for more queries.Before,
CuckooMetricNameStoreFilter.Matchesonly skipped a store when the request carried an exact__name__="x"matcher. A regex matcher such as__name__=~"a|b|c"— extremely common in Grafana dashboards, recording-rule groups andorqueries — was ignored, so the querier always fanned out even when none ofa,b,cexist on that store.Matchesnow:__name__matcher instead of returning on the first one;MatchRegexpmatcher whose value set is fully enumerable (labels.Matcher.SetMatches()) as a constraint, using its literal alternatives;__name__=~"a.*"), so those stay non-constraining and correctness is unchanged;falseonly when, for at least one constraint, none of its candidate metric names are present in the filter (AND semantics across constraints, OR within a set).This only tightens an already-probabilistic, false-positive-only check, so it cannot cause missed data: an enumerable regex that would previously fan out unconditionally now fans out iff at least one of its names might be present.
Touched files:
pkg/filter/cuckoo.go,pkg/filter/cuckoo_test.go(new),CHANGELOG.md. No proto or API changes.Part of #1611.
Verification
TestCuckooMetricNameStoreFilter_Matchescovering exact hit/miss, enumerable regex (all-miss vs partial-hit), non-enumerable regex, no__name__matcher, empty matchers, multi-constraint AND, and non-__name__regex being ignored.BenchmarkCuckooMetricNameStoreFilter_Matches(equal~56 ns/op,regexp_set~106 ns/op on a 10k-entry filter).gofmt -l,go build ./pkg/filter/...,go vet ./pkg/filter/...,go test ./pkg/filter/...all pass.