Repository navigation
expfmt: quote label names that contain colons - #1045
Merged
Merged
Conversation
Label names were checked against the legacy metric name rules, which
allow ':'. Colons are not valid in legacy label names, so a label such
as "a:b" was written unquoted as m{a:b="v"}, which the text and
OpenMetrics parsers reject. Check label names against the legacy label
name rules instead and quote them when needed.
Signed-off-by: György Krajcsovits <gyorgy.krajcsovits@grafana.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
SuperQ
approved these changes
Nov 13, 2026
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.
The text and OpenMetrics writers decide whether to quote a label name using the legacy metric name rules, which allow
:. Legacy label names can't contain:, so a label likea:bcomes out unquoted:The parser in this repo rejects that line, even with UTF-8 validation:
expected '=' after label name, found ':'. Escaping doesn't help when it is skipped (NoEscaping/escaping=allow-utf-8).This PR checks label names with
model.LegacyValidation.IsValidLabelNameand quotes them when needed. Metric names keep the current rule, soname:with:colons{"label:name"="val"}is written as expected. This covers the classic text format, OpenMetrics 1.0 and OpenMetrics 2.0.I found this while checking the approach in prometheus/prometheus#20417, which quotes names in
promtool tsdb dump-openmetrics, against this repo's writers.Related: prometheus/prometheus#18380 and #953 fix the same
:mix-up inEscapeMetricFamily/EscapeName. This PR fixes the writer, which those don't touch.🤖 Generated with Claude Code