feat(metrics): add metric validation + UTF-8 support#238
Draft
ethanolchik wants to merge 20 commits into
Draft
Conversation
Add owned fixed-bucket storage, direct protobuf encoding, and support for the legacy HistogramBuilder API (only classic histograms in this commit).
Choose to pre-sort histogram buckets over a sorted boolean variable. Also satisfies cargo clippy & cargo fmt
ethanolchik
force-pushed
the
validation-and-utf8
branch
from
July 24, 2026 12:07
6cd35d0 to
ff0cd51
Compare
…omplete, non-empty names
… names Legacy metric and label names must match Prometheus' name grammars. Names outside these grammars cause Prometheus to reject the scrape, and the grammars exclude non-ASCII characters. Foundations now quotes label names and uses OpenMetrics' quoted metric-name syntax when required. This allows UTF-8 and other nonstandard names without affecting legacy compatibility.
ethanolchik
force-pushed
the
validation-and-utf8
branch
from
July 24, 2026 14:43
ff0cd51 to
7e00086
Compare
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.
What Changed
Introduces shared validation used during collection and by both encoders.
Names are valid when they are non-empty UTF-8 strings without NUL (
\0) bytes. Names containing spaces, punctuation, newlines, or non-ASCII characters remain valid and are escaped appropriately for text output.Validation failures are isolated as narrowly as possible:
MetricFamily; exemplar-producing metric types are introduced separately.Histogram and gauge-histogram rows reserve
le, while summary rows reserve quantile, according to the canonical metric model.Service Labels
Service-label insertion now handles existing labels safely:
OpenMetrics Text
The text encoder now:
OPENMETRICS_CONTENT_TYPEwithescaping=allow-utf-8.Legacy-compatible metric names remain unquoted.
Protobuf
Protobuf output preserves valid UTF-8 names exactly. The protobuf encoder applies the same defensive validation when called directly, so bypassing collection does not bypass validation.