8000 PromQL parser: support underscores in literal numbers by rexagod · Pull Request #12821 · prometheus/prometheus · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

PromQL parser: support underscores in literal numbers #12821

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 27, 2024

Conversation

rexagod
Copy link
Contributor
@rexagod rexagod commented Sep 9, 2023

Support underscores in numbers, namely, decimals, hexadecimals, and exponentials.

Fixes #12769.

@roidelapluie
Copy link
Member

I will consult the team about this.

@gouthamve
Copy link
Member

@roidelapluie Has there been any feedback for this yet? If not, lets kick off a thread in prometheus-developers / dev-summit?

We looked at this in our bug scrub.

SuperQ
SuperQ previously approved these changes Jun 13, 2024
Copy link
Member
@SuperQ SuperQ left a comment

Choose a reason for hiding this comment

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

LGTM

@beorn7
Copy link
Member
beorn7 commented Jun 18, 2024

@rexagod sorry for letting this fall through the cracks. We have picked this up, everyone seems fine with the change. Are you still up for finishing the PR?

@rexagod
Copy link
Contributor Author
rexagod commented Jun 18, 2024

@beorn7 Sure, apologies for the delay here. I'll patch this up.

Copy link
Contributor Author
@rexagod rexagod left a comment

Choose a reason for hiding this comment

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

I revisited the patch and refactored the parsing logic for better readability, PTAL.

@rexagod rexagod force-pushed the 12769 branch 4 times, most recently from bfe5f35 to 97cc304 Compare June 18, 2024 23:54
Comment on lines 918 to 924
dotPattern := "."
exponentPattern := "eE"
underscorePattern := "_"
// Anti-patterns are rune sets that cannot follow their respective rune.
dotAntiPattern := "_."
exponentAntiPattern := "._eE" // and EOL.
underscoreAntiPattern := "._eE" // and EOL.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to ot 8000 hers. Learn more.

These are not modified like digitPattern is. Let's move them to the package scope as const values.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

+1 on the const change, but I'm not sure about changing the scope for these (since they are only used in this method)? LMK if you think otherwise and I'll make the change.

SuperQ
SuperQ previously approved these changes Jun 19, 2024
Copy link
Member
@SuperQ SuperQ left a comment

Choose a reason for hiding this comment

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

LGTM, I'll leave the const scope decision to the other reviewers.

Copy link
Member
@beorn7 beorn7 left a comment

Choose a reason for hiding this comment

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

The code looks good. Thank you very much.

However, this needs an update of the frontend, too. Otherwise, the syntax highlighting will not work properly for numbers with underscores, and the UI will draw squiggly red lines:

image

I'm not a frontend expert myself (@juliusv and @Nexucis are the usual persons to ask for help), but I guess the changes will be in the web/ui/module/lezer-promql/src/ directory.

@@ -313,6 +313,11 @@ func (l *Lexer) accept(valid string) bool {
return false
}

// is peeks and returns true if the next rune is in the valid set.
Copy link
Member

Choose a reason for hiding this comment

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

From the doc comment, I found it a bit hard to understand what this helper method is doing. I had to read the code. Given that the code is short and the method is unexported, I would be fine without a doc comment. But if we keep it, it should probably be clearer, e.g. "is is peeks and returns true if if the next rune is contained in the provided string".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Patched, PTAL.

@beorn7
Copy link
Member
beorn7 commented Jun 26, 2024

@rexagod do you think you can tackle the UI changes, too? We could also try to find a frontend expert to do it, but that's notoriously hard.

@juliusv
Copy link
Member
juliusv commented Jun 27, 2024

Yeah, you probably have to just edit

number {
(std.digit+ ("." std.digit*)? | "." std.digit+) (("e" | "E") ("+" | "-")? std.digit+)? |
"0x" (std.digit | $[a-fA-F])+
}
and then the rest of the make build process should take care of the rest (parser regeneration, etc.).

Copy link
Member
@beorn7 beorn7 left a comment

Choose a reason for hiding this comment

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

I'm not really familiar with the grammar syntax, but this seems to do the job. Giving it another hour or so for an actual expert to intervene. Otherwise, I'll merge.

Support underscores in numbers, namely, decimals, hexadecimals, and
exponentials.

Fixes prometheus#12769
Signed-off-by: Pranshu Srivastava <rexagod@gmail.com>

Signed-off-by: Pranshu Srivastava <rexagod@gmail.com>
@rexagod
Copy link
Contributor Author
rexagod commented Jun 27, 2024

@beorn7 @juliusv Thank you for the inputs and pointers. Seeing this has gained an approval, I've squashed the commits.

@beorn7
Copy link
Member
beorn7 commented Jun 27, 2024

OK, time is up. Merging… 💥

@beorn7 beorn7 merged commit 19da579 into prometheus:main Jun 27, 2024
25 checks passed
@bboreham bboreham changed the title parser: support underscores parser: support underscores in literal numbers Jul 22, 2024
@bboreham bboreham changed the title parser: support underscores in literal numbers PromQL parser: support underscores in literal numbers Jul 22, 2024
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.

Proposal: optionally support underscore in big numbers
7 participants
0