Skip to content

fix(promql): reject non-equality __name__ matchers instead of mislowering (#67) - #73

Merged
zzylol merged 1 commit into
mainfrom
fix/name-regex-matcher-reject
Jul 2, 2026
Merged

fix(promql): reject non-equality __name__ matchers instead of mislowering (#67)#73
zzylol merged 1 commit into
mainfrom
fix/name-regex-matcher-reject

Conversation

@zzylol

@zzylol zzylol commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Closes #67 (MEDIUM, from the whole-repo review).

Bug

{__name__=~"node_.*"} (and !~ / !=) was silently mislowered. vs_parts took the first __name__ matcher's value as the metric name regardless of operator, then dropped all __name__ matchers — so a regex name match became an exact literal metric Source("node_.*") with the match op discarded, selecting the wrong series.

Fix

A non-equality __name__ matcher selects across metric names, which the single-metric Source::TimeSeries { metric } can't represent. Reject it cleanly (consistent with how offset / @ / without are rejected) rather than mislower. Equality __name__ ({__name__="up"}) still names the metric — unchanged.

Verified

  • {__name__=~"node_.*"} → rejected (was Source("node_.*"))
  • {__name__!~"x", job="y"} → rejected
  • {__name__="up"}Source("up") (unchanged)
  • normal selectors unaffected

Corpus queries with __name__=~ now reject instead of mislowering; the totality tests require only no-panic + a lowered floor, so they stay green. Added name_regex_matcher_is_rejected__GAP. Full suite green (29 binaries), clippy clean.

Follow-up: actually supporting cross-metric name selection needs a wildcard/regex Source in the IR — a separate feature.

🤖 Generated with Claude Code

…ring (#67)

`{__name__=~"node_.*"}` (and `!~` / `!=`) was silently mislowered:
`vs_parts` took the first `__name__` matcher's value as the metric name
regardless of its operator, then dropped all `__name__` matchers — so a
regex name match became an exact literal metric (`Source("node_.*")`) with
the match op discarded, selecting the wrong series.

A non-equality `__name__` matcher selects *across* metric names, which the
single-metric `Source::TimeSeries { metric }` can't represent. Reject it
cleanly (like offset/@/without) rather than mislower. Equality `__name__`
(`{__name__="up"}`) still names the metric — unchanged.

Corpus queries with `__name__=~` now reject instead of mislowering; the
totality tests only require no-panic + a lowered floor, so they stay green.
Added `name_regex_matcher_is_rejected__GAP` (also guards the equality case).
Full workspace suite green; clippy --all-targets clean.

Follow-up (needs a wildcard/regex `Source` in the IR): actually support
cross-metric name selection.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@zzylol
zzylol merged commit d38831d into main Jul 2, 2026
1 check passed
@zzylol
zzylol deleted the fix/name-regex-matcher-reject branch July 2, 2026 21:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PromQL: __name__=~/!~ regex selectors mislowered to a literal metric name

1 participant