-
Notifications
You must be signed in to change notification settings - Fork 815
UTF-8 Content Negotiation #1102
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
base: master
Are you sure you want to change the base?
Conversation
prometheus_client/exposition.py
Outdated
@@ -37,7 +37,7 @@ | |||
'write_to_textfile', | |||
) | |||
|
|||
CONTENT_TYPE_LATEST = 'text/plain; version=0.0.4; charset=utf-8' | |||
CONTENT_TYPE_PLAIN = 'text/plain; version=0.0.4; charset=utf-8' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
text/plain v 0.0.4 is not the latest, so I thought it best to rename this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Though I agree with you, this will be a breaking change as other programs use CONTENT_TYPE_LATEST
. Perhaps we should update this to version=1.0.0 instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is needed for compatibility, but LATEST and PLAIN are both really different versions of PLAIN that is confusing for external users to use. I'd propose a couple options:
- Keep
CONTENT_TYPE_PLAIN
internal, so rename it to_CONTENT_TYPE_PLAIN
. - Support content types for each version, so have
CONTENT_TYPE_PLAIN_0_4_0
,CONTENT_TYPE_PLAIN_1_0_0
, and then aliasCONTENT_TYPE_LATEST
toCONTENT_TYPE_PLAIN_1_0_0
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like option 2
TODO need more openmetrics/exposition tests |
33ea581
to
630fb65
Compare
|
||
|
||
def _escape(s: str) -> str: | ||
def _escape(s: str, escaping: str, is_labelname: bool) -> str: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't love how messy this function signature is getting...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it is internal only so not the end of the world. Would it help at all to have a second function for specifically escaping label names?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried another approach that looks better
Signed-off-by: Owen Williams <owen.williams@grafana.com>
prometheus_client/exposition.py
Outdated
@@ -37,7 +37,7 @@ | |||
'write_to_textfile', | |||
) | |||
|
|||
CONTENT_TYPE_LATEST = 'text/plain; version=0.0.4; charset=utf-8' | |||
CONTENT_TYPE_PLAIN = 'text/plain; version=0.0.4; charset=utf-8' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Though I agree with you, this will be a breaking change as other programs use CONTENT_TYPE_LATEST
. Perhaps we should update this to version=1.0.0 instead?
prometheus_client/exposition.py
Outdated
escaping = _get_escaping(toks) | ||
# Only return an escaping header if we have a good version and | ||
# mimetype. | ||
if version == '1.0.0': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this test that the version is at least 1.0.0? I imagine at least anything in 1.x should be ok?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like there's a python lib for that!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lmk if I should just test for major version versus any >= version
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(I think any greater version should be fine)
|
||
|
||
def _escape(s: str) -> str: | ||
def _escape(s: str, escaping: str, is_labelname: bool) -> str: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it is internal only so not the end of the world. Would it help at all to have a second function for specifically escaping label names?
tools/simple_client.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this used anywhere? Or just a nice example for testing locally?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just for testing locally
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but is also pretty nice for people to get off the ground
we do still need a 0.0.4 constant as the fallback when all else fails. What I could do is update LATEST to be 1.0.0 and then create the new PLAIN constant for 0.0.4 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally looks to be getting there! A few comments mostly around the content types still. CONTENT_TYPE_LATEST from just exposition.py (not open metrics) doesn't actually seem to be used?
prometheus_client/exposition.py
Outdated
@@ -37,7 +37,7 @@ | |||
'write_to_textfile', | |||
) | |||
|
|||
CONTENT_TYPE_LATEST = 'text/plain; version=0.0.4; charset=utf-8' | |||
CONTENT_TYPE_PLAIN = 'text/plain; version=0.0.4; charset=utf-8' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is needed for compatibility, but LATEST and PLAIN are both really different versions of PLAIN that is confusing for external users to use. I'd propose a couple options:
- Keep
CONTENT_TYPE_PLAIN
internal, so rename it to_CONTENT_TYPE_PLAIN
. - Support content types for each version, so have
CONTENT_TYPE_PLAIN_0_4_0
,CONTENT_TYPE_PLAIN_1_0_0
, and then aliasCONTENT_TYPE_LATEST
toCONTENT_TYPE_PLAIN_1_0_0
.
Part of #1013
The remaining piece is configuration to force escaping even if a scraper does not request it