-
Notifications
You must be signed in to change notification settings - Fork 324
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
UTF8: Content negotiation (encoding side) #570
Conversation
eef9af4
to
f4d7f87
Compare
This will be squashed :) |
expfmt/encode.go
Outdated
} | ||
} | ||
return FmtText | ||
return FmtText_0_0_4 + Format(fmt.Sprintf("; escaping=%s", model.EscapeValues)) |
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.
this specifies a default escaping scheme when none other is specified. not sure if this is the right thing to do
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.
General direction looks OK. I will only manage to do a code level review next week.
Some broad thoughts:
First the versioning. See the individual comment below. It feels weird to pretend to support a version that doesn't exist yet. (But as said, I'm not an expert and I don't know how this is usually done.)
Another gut feeling: validchars
and escaping
never show up together. Maybe they can be merged into one option? escaping=none
could take the role of validchars=utf8
, and escaping=values
is the default. (Maybe that default should be part of the (upcoming) standard and hardwired in the code. It feels weird that the default is set via a package variable and that would change the behavior for the same accept header.)
expfmt/expfmt.go
Outdated
OpenMetricsType = `application/openmetrics-text` | ||
OpenMetricsVersion_0_0_1 = "0.0.1" | ||
OpenMetricsVersion_2_0_0 = "2.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 guess for the classic text format, anything goes because it hasn't really been formally specified, but here I would definitively add a comment that this doesn't imply that we are really implementing OM v2 from the future.
On a more general note, I'm wondering if pretending we are supporting a version of the standard that doesn't exist yet is the right way to go. I'm not an expert in those content-type shenanigans. Maybe we should add some "alpha" or "pre" in here?
Another thought: Maybe we don't need to change version numbers at all right now. Any escaping that is not |
I like the idea of using escaping to also select for utf8 mode. maybe instead of "none" we call it |
can't remember if dashes are allowed in content-type parameters though |
Yes, let's do that. I.e. only one parameter I would also say, for now, that we don't change the version numbers but "tolerate" that the client can ask for And yes, dashes are allowed in the content type, we use it for The former reminds me that we should try to be consistent and spell UTF-8 as UTF-8 where possible. |
The Go test errors seem to have to do with Go modules. Probably need to run Could you fix that and work in the ideas above? I think the code otherwise is technically fine. I'll do a final review once that's done. |
notes should all be addressed |
oh except for adding comments |
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 good. I assume you will squash the commits yourself and then take care of DCO signing.
Signed-off-by: Owen Williams <[email protected]>
78b2c9a
to
9b1ede5
Compare
squashed |
9b1ede5
to
319c62c
Compare
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.
Thank you very much.
This PR builds on #537 by adding content negotation during scraping.
Scrapers can announce that they support utf-8 names by adding "escaping=allow-utf-8" in the Content-Type header. In cases where utf8 is not available, metric providers can be configured to escape names in a few different ways: values (U__ utf value escaping for perfect round-tripping), underscores (all invalid chars become _), dots (dots become
_dot_
,_
becomes__
, all other values become __). Escaping can either be a global default (model.NameEscapingScheme) or can also be specific in Content-Type with the "escaping=" term, which can be "allow-utf-8" (for UTF8-compatible), "underscores", "dots", or "values".This is still a noop for existing configurations because scrapers will not be passing the escaping key in the Content-Type header. Existing functionality is maintained.