Repository navigation
Conversation
ResponseFormat kept the escaping parameter of the Content-Type only for text/plain; version=1.0.0. For protobuf and OpenMetrics responses it returned the bare format, so NewDecoder fell back to legacy name validation and rejected UTF-8 metric names that NewEncoder had written with escaping=allow-utf-8. Prometheus sends escaping=allow-utf-8 for OpenMetrics 1.0.0 in its default Accept header, so such responses are common. Read the escaping parameter the same way for all formats that support it, using the value parsed by mime.ParseMediaType so that quoted values work. Without the parameter the returned format is unchanged. Signed-off-by: Ismail Tarim <ismailtarim7@gmail.com>
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.
Follow-up to #1035 (comment).
ResponseFormatkeeps theescapingparameter only fortext/plain; version=1.0.0. For protobuf and OpenMetrics it returns the bare format, soNewDecoder(body, ResponseFormat(h))falls back to legacy name validation and rejects UTF-8 names thatNewEncoderwrote withescaping=allow-utf-8:Prometheus asks for
escaping=allow-utf-8on OpenMetrics 1.0.0 in its defaultAcceptheader, so a client that passes that header on and decodes the response this way runs into it.This reads the parameter the same way for protobuf, text 1.0.0 and OpenMetrics 1.0.0 / 2.0.0, using the value from
mime.ParseMediaTypeso quoted values work too. Without the parameter the returned format is unchanged. For OpenMetrics 2.0 this also means that an explicit scheme other thanallow-utf-8is now honoured instead of dropped. Protobuf is included becauseNegotiateAcceptand the encoder already emit the parameter for it.Added
ResponseFormattable cases and an encode/decode test with a UTF-8 name. The new tests fail without the change, andgo test ./...andgolangci-lintpass with it.@roidelapluie