Skip to content

fix: prevent Prettify() from corrupting __name__ regex matchers (#60)#61

Merged
f41gh7 merged 1 commit intoVictoriaMetrics:masterfrom
freeseacher:patch-Ii9
Feb 12, 2026
Merged

fix: prevent Prettify() from corrupting __name__ regex matchers (#60)#61
f41gh7 merged 1 commit intoVictoriaMetrics:masterfrom
freeseacher:patch-Ii9

Conversation

@freeseacher
Copy link
Contributor

@freeseacher freeseacher commented Feb 12, 2026

The mustGetMetricName() function was extracting metric names from name label filters without checking the operator type. This caused queries with regex matchers like {__name__=~"pattern"} to be incorrectly simplified to {"pattern"}, resulting in silent query corruption.

Added checks for IsRegexp and IsNegative flags to ensure only exact match operators (=) on name are treated as metric names, while preserving regex matchers (=~, !~) and negative matchers (!=, !=) as label filters.

Fixes #60


Summary by cubic

Prevented Prettify() from corrupting queries by treating metric names only when name uses an exact = match. Regex (=), negative (!=), and negative regex (!) on name now remain as label filters, avoiding silent query changes.

  • Bug Fixes
    • Updated mustGetMetricName to skip name when IsRegexp or IsNegative is set; only name="foo" becomes a metric name.
    • Added tests for =, !, and exact matches to verify correct formatting.

Written for commit 9e54372. Summary will update on new commits.

…oriaMetrics#60)

The mustGetMetricName() function was extracting metric names from __name__
label filters without checking the operator type. This caused queries with
regex matchers like {__name__=~"pattern"} to be incorrectly simplified to
{"pattern"}, resulting in silent query corruption.

Added checks for IsRegexp and IsNegative flags to ensure only exact match
operators (=) on __name__ are treated as metric names, while preserving
regex matchers (=~, !~) and negative matchers (!=, !=) as label filters.

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 2 files

@vrutkovs vrutkovs requested a review from makasim February 12, 2026 14:41
@f41gh7 f41gh7 self-assigned this Feb 12, 2026
@f41gh7 f41gh7 self-requested a review February 12, 2026 15:10
@codecov
Copy link

codecov bot commented Feb 12, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.69%. Comparing base (a50761b) to head (9e54372).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master      #61   +/-   ##
=======================================
  Coverage   89.69%   89.69%           
=======================================
  Files          11       11           
  Lines        2969     2969           
=======================================
  Hits         2663     2663           
  Misses        209      209           
  Partials       97       97           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

@f41gh7 f41gh7 left a comment

Choose a reason for hiding this comment

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

LGTM

@f41gh7 f41gh7 merged commit 8ec6569 into VictoriaMetrics:master Feb 12, 2026
4 checks passed
@f41gh7
Copy link
Contributor

f41gh7 commented Feb 12, 2026

Thanks for contribution!

@f41gh7
Copy link
Contributor

f41gh7 commented Feb 12, 2026

Bugfix was included into v1.110 and v1.122 LTS branches

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.

metricsql.Prettify() Corrupts __name__ Label Matchers

2 participants