Skip to content

Support UTF-8 metric names and labels in web UI#15244

Merged
juliusv merged 2 commits intomainfrom
utf8-web-ui-support
Nov 4, 2024
Merged

Support UTF-8 metric names and labels in web UI#15244
juliusv merged 2 commits intomainfrom
utf8-web-ui-support

Conversation

@juliusv
Copy link
Copy Markdown
Member

@juliusv juliusv commented Oct 29, 2024

This should address all areas of the UI except for the autocompletion in the codemirror-promql text editor. The strategy here is that any time we print or internally serialize (like for the PromLens tree view) either a metric name or a label name as part of a selector or in other relevant parts of PromQL, we check whether it contains characters beyond what was previously supported, and if so, quote and escape it. In the case of metric names, we also have to move them from the beginning of the selector into the curly braces.

part of #15202

@juliusv juliusv requested review from Nexucis and ywwg October 29, 2024 18:44
Fixes most of #15202

This should address all areas of the UI except for the autocompletion in the
codemirror-promql text editor. The strategy here is that any time we print or
internally serialize (like for the PromLens tree view) either a metric name or
a label name as part of a selector or in other relevant parts of PromQL, we
check whether it contains characters beyond what was previously supported, and
if so, quote and escape it. In the case of metric names, we also have to move
them from the beginning of the selector into the curly braces.

Signed-off-by: Julius Volz <[email protected]>
@juliusv juliusv force-pushed the utf8-web-ui-support branch from 8947dcb to c861b31 Compare October 29, 2024 19:23
@Nexucis
Copy link
Copy Markdown
Member

Nexucis commented Oct 30, 2024

looks like the tests are broken @juliusv. I don't know if you notice

Copy link
Copy Markdown
Member

@ywwg ywwg left a comment

Choose a reason for hiding this comment

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

I can read some of this! 😅 Just a couple non-blocking comments on how I've been framing naming / logic choices when implementing this in other languages. Consistency is not required but might be nice to have in the future.

@@ -1,12 +1,24 @@
import {
maybeQuoteLabelName,
metricContainsExtendedCharset,
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.

for what it's worth, I have been inverting this function call and naming it something like "isLegacyCompatible". I do this because UTF-8 is the new default, whereas the old restrictions only really apply to old versions of the code. This isn't a required fix but would be more consistent with how it's being implemented in other languages.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I didn't like "legacy" because for me the old character set is still the main one and the one I'll keep advocating for for regular users of Prometheus - at least unless someone comes up with a better selector syntax for the extended character set 😅

const labelNodes: React.ReactElement[] = [];
let first = true;

// If the metric name uses the extended new charset, we need to escape it,
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.

continuing the reasoning from above, then the comment becomes something like: "If the metric name conforms to the legacy character set, it can appear outside the braces. All other metrics must be escaped and put into the label matcher list, and make sure it's the first item.")

@juliusv
Copy link
Copy Markdown
Member Author

juliusv commented Oct 30, 2024

looks like the tests are broken @juliusv. I don't know if you notice

Whoops, I forgot that it's not sufficient to do npm run test locally, but also npm run build... looks like I had erroneously removed a few necessary lines, re-added them.

@juliusv
Copy link
Copy Markdown
Member Author

juliusv commented Nov 4, 2024

Build is passing - from my side it's fine to merge unless @ywwg feels strongly about the wording ;)

Copy link
Copy Markdown
Member

@Nexucis Nexucis left a comment

Choose a reason for hiding this comment

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

yep it looks fine for me :)

@juliusv
Copy link
Copy Markdown
Member Author

juliusv commented Nov 4, 2024

Ok, will merge it for now, we can still change variable and function namings later on to make things more consistent one way or the other, if we want :)

@juliusv juliusv merged commit 51866b9 into main Nov 4, 2024
@juliusv juliusv deleted the utf8-web-ui-support branch November 4, 2024 11:13
@ywwg
Copy link
Copy Markdown
Member

ywwg commented Nov 5, 2024

Build is passing - from my side it's fine to merge unless @ywwg feels strongly about the wording ;)

sorry I was on PTO -- no blocking comments

@ywwg ywwg mentioned this pull request Nov 5, 2024
2 tasks
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.

3 participants