Conversation
krajorama
reviewed
Oct 7, 2025
Member
krajorama
left a comment
There was a problem hiding this comment.
There's more escaping schemes https://prometheus.io/docs/instrumenting/escaping_schemes/
If, as you say, prom2json doesn't actually care about the names, why single out utf-8? Might as well enumerate the possible values in the option ?
Member
Author
|
True. It didn't occur to me that people would like to pick other schemes (just that we cannot just make utf-8 the default). But you are right, maybe some people really want a particular escaping in their JSON. Will update. |
ywwg
requested changes
Oct 7, 2025
Member
Author
|
All addressed. PHAL. |
Due to its simplistic design, prom2json has always tolerated any characters in metric and label names. (It does not validate anything, just puts strings into JSON objects…) However, a compliant scrape target will only serve unescaped UTF-8 in names if asked to do so. This commit adds a CLI option to add the 'escaping=SCHEME' parameter in content negotiation. We cannot set this option to 'allow-utf-8' by default without a major release because users might depend on the default (underscore) escaping. I implemented this in a slightly clunky way to not change the library API (although we use semver for the user API, not the library API here – I still thought we can be nice at a relatively small price). Signed-off-by: beorn7 <beorn@grafana.com>
krajorama
reviewed
Oct 14, 2025
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.
Due to its simplistic design, prom2json has always tolerated any characters in metric and label names. (It does not validate anything, just puts strings into JSON objects…)
However, a compliant scrape target will only serve unescaped UTF-8 in names if asked to do so. This commit adds a CLI option to make prom2json ask for it.
We cannot set this option by default without a major release because users might depend on the escaping.
I implemented this in a slightly clunky way to not change the library API (although we use semver for the user API, not the library API here – I still thought we can be nice at a relatively small price).