Repository navigation
fix(lexers): recognize colons in PromQL metric names - #1495
Merged
github-actions[bot] merged 1 commit intoNov 17, 2026
Merged
github-actions[bot] merged 1 commit into
github-actions[bot] merged 1 commit into
Conversation
The name rule accepts a letter or underscore followed by letters, digits and underscores, so each colon in a recording-rule name such as instance_path:requests:rate5m lexes as an error. Allow colons in both character classes, as the Prometheus metric name pattern does. https://prometheus.io/docs/concepts/data_model/#metric-names-and-labels https://prometheus.io/docs/practices/rules/#naming
github-actions Bot
pushed a commit
that referenced
this pull request
Nov 17, 2026
PromQL allows single-quoted, double-quoted, and raw backtick strings. The quoted forms use backslash escapes, while raw strings can contain newlines. The lexer currently ends a string on either quote type and does not account for escapes. That splits valid strings into incorrect tokens, including Error tokens. Raw backtick strings are not recognized either. In a label value, an escaped quote followed by a brace can also end the label state too early. Use a shared string state for expressions and label values. Keep the existing Punctuation delimiters and LiteralString contents. Add golden coverage for escaped and opposite quotes, raw and multiline strings, braces inside label values, escaped trailing backslashes, and ordinary strings/selectors. Validation on base and candidate: - Full ordinary suite with pinned Go 1.27.3 and shuffle seed 42 passes. - Go 1.25 and 1.27.3 race/shuffle runs pass with existing TestGet, TestLongTokensMatch, and TestLexers/OpenEdge_ABL excluded. - Focused PromQL tests pass on Linux/386. - With only the new golden copied to unchanged base, the new case fails while existing PromQL cases pass. Candidate-only checks: - Focused PromQL race tests pass 100 times. - golangci-lint 2.15.0 passes. - Regenerating lexer metadata produces no change. - HTML output was rendered and visually checked against base. Full race runs are not uniformly green: TestLongTokensMatch hits its existing regex timeout on both trees under Go 1.26.6, and also on the candidate in one pinned Go run. Bounded runs also hit an existing OpenEdge_ABL test timeout on both trees; default-order runs stalled at TestGet/ViaGoooFilename on both. Plain vet returns identical existing unkeyed Rule warnings on both trees. This extends the PromQL support in #422 and #474 while retaining the metric-colon behavior from #1495. The lexer XML has a trailing newline versus the original draft. The complete diff is three files, +166/-8.
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.
For these PromQL metric names:
Main splits each name at its colons:
{"type":"NameVariable","value":"instance_path"}, {"type":"Error","value":":"}, {"type":"NameVariable","value":"requests"}, {"type":"Error","value":":"}, {"type":"NameVariable","value":"rate5m"},The second name also starts and ends with
{"type":"Error","value":":"}. Each name should be oneNameVariabletoken.In the current Prometheus docs, Metric names and labels gives the pattern
[a-zA-Z_:][a-zA-Z0-9_:]*and reserves colons for recording rules. The recording rules guide uses the formlevel:metric:operations, and its examples includeinstance_path:requests:rate5m.The name rule accepts a letter or underscore followed by letters, digits and underscores. This adds
:to both character classes, as in the Prometheus pattern.The new golden fails without the rule change:
go test -count=1 ./...passes.