Skip to content

promql/parser: fix UTF-8 label quoting in format_query endpoint#17687

Merged
juliusv merged 4 commits intoprometheus:mainfrom
adity-a34:fix/utf8
Dec 28, 2025
Merged

promql/parser: fix UTF-8 label quoting in format_query endpoint#17687
juliusv merged 4 commits intoprometheus:mainfrom
adity-a34:fix/utf8

Conversation

@adity-a34
Copy link
Copy Markdown
Contributor

Which issue(s) does the PR fix:

Fixes #15243

Does this PR introduce a user-facing change?

[BUGFIX] PromQL: Fix UTF-8 label name quoting in format_query API endpoint for binary expressions and aggregations.

The /api/v1/format_query endpoint was returning invalid PromQL when UTF-8 label names appeared in on(), ignoring(), group_left(), group_right(), by(), and without() clauses. Labels like "äää" were rendered unquoted, breaking the expression.

@adity-a34 adity-a34 requested a review from juliusv December 15, 2025 12:50
@adity-a34
Copy link
Copy Markdown
Contributor Author

Hello @juliusv
Thanks for the review!
I've refactored the implementation to use writeLabels() everywhere and extended the tests as you instructed.

Please review it.

@adity-a34
Copy link
Copy Markdown
Contributor Author

It seems CI / fuzzing / Fuzzing (pull_request) is failing for all the PRs since yesterday!

@juliusv
Copy link
Copy Markdown
Member

juliusv commented Dec 15, 2025

It seems CI / fuzzing / Fuzzing (pull_request) is failing for all the PRs since yesterday!

Indeed! Arve already mentioned it on #prometheus-dev on Slack as well. We should just ignore that check until it's fixed.

@adity-a34
Copy link
Copy Markdown
Contributor Author

@juliusv Thanks! I've simplified the buffer operations; Removed the first b.Reset() call, combined the three WriteString calls into single statement, kept the second b.Reset() call for buffer reuse.

Please review the changes.

@adity-a34 adity-a34 requested a review from juliusv December 15, 2025 13:45
@bboreham
Copy link
Copy Markdown
Member

Please rebase on main after #17695 to fix the Fuzzing CI failure.

adity-a34 and others added 4 commits December 16, 2025 12:31
refactors binary expression formatting to reuse writeLabels() instead
of maintaining separate joinLabels() function. adds comprehensive
UTF-8 label tests for all expression types

Signed-off-by: ADITYA TIWARI <[email protected]>
@adity-a34
Copy link
Copy Markdown
Contributor Author

adity-a34 commented Dec 18, 2025

Hello @juliusv @bboreham
I have tested the changes, and it is passing the requirements of issue #15243.
This PR is ready for review!

adityatiwari@DeathNote:~/temp/prometheus$ go test ./promql/parser -run TestBinaryExprUTF8Labels
ok      github.com/prometheus/prometheus/promql/parser  0.021s
adityatiwari@DeathNote:~/temp/prometheus$ go test ./promql/parser -run TestExprString
ok      github.com/prometheus/prometheus/promql/parser  0.021s
adityatiwari@DeathNote:~/temp/prometheus$ 

Copy link
Copy Markdown
Member

@juliusv juliusv left a comment

Choose a reason for hiding this comment

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

Thanks! 👍

@juliusv juliusv merged commit 9da9e6d into prometheus:main Dec 28, 2025
28 checks passed
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.

UTF-8: format_query endpoint returning invalid format

3 participants