expfmt: reject invalid UTF-8 and a trailing CR in OpenMetrics 2.0 metadata - #998
Merged
Merged
Conversation
…adata MetricFamilyToOpenMetrics20 wrote a metric name, HELP or UNIT that is not valid UTF-8, and a HELP ending in a carriage return, which makes the line end in "\r\n". OpenMetrics 2.0 requires UTF-8 and forbids \r in line endings, and the Prometheus OpenMetrics 2.0 parser rejects the whole exposition in both cases. Return an error instead, as for raw newlines in the name and unit. Signed-off-by: Aditya <205600203+Rohilalala@users.noreply.github.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.
MetricFamilyToOpenMetrics20wrote a metric name, HELP or UNIT that is not valid UTF-8, and a HELP that ends in a carriage return. The spec requires UTF-8, and "Line endings MUST be signalled with line feed (\n) and MUST NOT contain carriage returns (\r)". The Prometheus OpenMetrics 2.0 parser (model/textparse/openmetrics2parse.go) rejects the whole exposition in both cases:Both now return an error, as raw newlines in the name and unit already do. A carriage return inside HELP is still written, since the spec and the parser allow it.
Found by encoding families with
MetricFamilyToOpenMetrics20and parsing the output with the Prometheus OpenMetrics 2.0 parser.Not changed: label names and values are not checked for UTF-8. Checking them on every series made encoding about 17% slower in a benchmark, and client_golang already rejects invalid UTF-8 label values. The OpenMetrics 1.0 and text encoders are unchanged.