Skip to content

promql: allow unquoted Unicode letters and dots behind a feature flag - #19683

Merged
roidelapluie merged 3 commits into
prometheus:mainfrom
roidelapluie:roidelapluie/utf8names-backend
Oct 23, 2026
Merged

roidelapluie merged 3 commits into
prometheus:mainfrom
roidelapluie:roidelapluie/utf8names-backend

Conversation

@roidelapluie

@roidelapluie roidelapluie commented Sep 11, 2026 •

Copy link
Copy Markdown
Member

Which issue(s) does the PR fix:

Release notes for end users (ALL commits must be considered).

Reviewers should verify clarity and quality.

[FEATURE] PromQL: Allow unquoted Unicode letters and dots behind a feature flag

@roidelapluie
roidelapluie requested review from a team, dgl and vpranckaitis as code owners September 11, 2026 12:05

@vpranckaitis vpranckaitis left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, though it might be good if someone else who is more familiar with UTF8 intricacies and parser code would look at this.

Comment thread docs/querying/basics.md Resolved
@metalmatze

Copy link
Copy Markdown
Member

Thanks for working on this @roidelapluie! We're trying it out on our fork and found one lexer regression with the flag enabled.

A keyword directly followed by a decimal literal now gets absorbed into a dotted name:

foo > bool.5    # flag disabled: foo > bool 0.5, flag enabled: foo > {__name__="bool.5"}
foo atan2.5     # flag disabled: foo atan2 0.5, flag enabled: parse error

The first one is the nasty case. The query still parses, but it compares against a metric that doesn't exist and returns an empty result.

We fixed it in lexKeywordOrIdentifier by stopping before the dot when the word so far is a keyword and the dot is followed by a digit. bool.total and on.total stay names, and bool.5xx fails the same way it does today.

for {
	r := l.next()
	// Not l.peek(): at EOF it zeroes l.width and breaks the backup below.
	if r == '.' && int(l.pos) < len(l.input) && isDigit(rune(l.input[l.pos])) {
		if _, ok := keyword(l.input[l.start : l.pos-1]); ok {
			l.backup()
			break
		}
	}
	if !l.isNameContinue(r) && r != ':' {
		l.backup()
		break
	}
}

keyword() is the existing key[strings.ToLower(word)] lookup with the non-ASCII check moved into a helper. Watch out for l.peek() there. It looks like the natural choice, but at EOF it leaves l.width at 0, so the following backup() doesn't move back and foo. gets accepted even with the flag disabled.

We also moved the evaluation cases into promql/promqltest/testdata/unquoted_utf8_names.test and enabled the option in TestParserOpts, so other implementations running the built-in tests pick them up and every existing test file runs through the new lexer. Happy to send either one as a PR against your branch if that helps.

@roidelapluie

Copy link
Copy Markdown
Member Author

Thank you, but I prefer to mark that as a "bug" of the current parser and have the new one threat bool.5 as a metric name.

@metalmatze

Copy link
Copy Markdown
Member

Ok. Fair. To me this felt more on the lines of: It was this way in Prometheus previously so we're not breaking.
I'm fine with saying it was currently a bug it's fixed going forward.

@juliusv

juliusv commented Oct 17, 2026

Copy link
Copy Markdown
Member

Thank you, but I prefer to mark that as a "bug" of the current parser and have the new one threat bool.5 as a metric name.

💯 Agreed, and it would really weird if anyone accidentally wrote their queries like that.

@roidelapluie
roidelapluie force-pushed the roidelapluie/utf8names-backend branch from 7bd7b58 to 4502d4d Compare October 20, 2026 09:34
metalmatze added a commit to dash0hq/prometheus that referenced this pull request Oct 20, 2026
…ted names"

This reverts commit 5bb274e.

Upstream decided in prometheus#19683 that with unquoted UTF-8 names enabled,
`bool.5` is a metric name and the old `bool 0.5` reading is a parser
bug. Follow upstream so queries mean the same on the fork as they will
upstream.

Signed-off-by: Matthias Loibl <[email protected]>
@roidelapluie
roidelapluie force-pushed the roidelapluie/utf8names-backend branch from 4502d4d to 5f687df Compare October 20, 2026 11:14

@ywwg ywwg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm. The change makes sense, and the test cases seem to cover all the cases we are worried about.

Can you add one more case for specifying metric name inside and outside the braces? That should still be caught but just to make sure:

my.metric.name{"my.metric.name"}

Just a couple nits otherwise.

Comment thread promql/parser/printer.go Resolved
Comment thread promql/parser/generated_parser.y Resolved
Comment thread promql/parser/printer.go Resolved
Comment thread promql/parser/unquoted_utf8_test.go Resolved
@metalmatze

Copy link
Copy Markdown
Member

PTAL at roidelapluie#106
I have these conformance tests already and wanted to send them along. I think we can have them as part of this PR. Up to you @roidelapluie

roidelapluie and others added 3 commits October 21, 2026 12:16
Add the evaluation cases for unquoted Unicode and dotted names to
promqltest/testdata, so other PromQL implementations that run the
built-in test files pick them up too. Enabling the parser option in
TestParserOpts also runs every existing test file through the extended
lexer, which catches regressions in existing syntax.

Signed-off-by: Matthias Loibl <[email protected]>
@roidelapluie
roidelapluie force-pushed the roidelapluie/utf8names-backend branch from 206caba to cbbef9f Compare October 21, 2026 12:46
@roidelapluie

Copy link
Copy Markdown
Member Author

Thanks @ywwg , I have fixed the comments and rebased

Comment thread promql/parser/generated_parser.y Resolved

@ywwg ywwg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

one last nit

@roidelapluie
roidelapluie disabled auto-merge October 23, 2026 09:00
@roidelapluie
roidelapluie merged commit e2e83df into prometheus:main Oct 23, 2026
66 of 67 checks passed
roidelapluie added a commit to roidelapluie/prometheus that referenced this pull request Oct 23, 2026
Cherry-pick PR prometheus#19683 onto release-3.16.

(cherry picked from commit e2e83df)

Co-authored-by: Matthias Loibl <[email protected]>
Signed-off-by: Julien Pivotto <[email protected]>
roidelapluie added a commit that referenced this pull request Oct 26, 2026
…#20162)

Cherry-pick PR #19683 onto release-3.16.

(cherry picked from commit e2e83df)

Signed-off-by: Julien Pivotto <[email protected]>
Co-authored-by: Matthias Loibl <[email protected]>
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.

5 participants