Skip to content

expfmt: quote label names that contain colons - #1045

Merged
SuperQ merged 1 commit into
prometheus:mainfrom
krajorama:krajo/quote-colon-label-names
Nov 13, 2026
Merged

SuperQ merged 1 commit into
prometheus:mainfrom
krajorama:krajo/quote-colon-label-names

Conversation

@krajorama

Copy link
Copy Markdown
Member

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 like a:b comes out unquoted:

m{a:b="v"} 1

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.IsValidLabelName and quotes them when needed. Metric names keep the current rule, so name: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 in EscapeMetricFamily / EscapeName. This PR fixes the writer, which those don't touch.

🤖 Generated with Claude Code

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
SuperQ merged commit 0675c9e into prometheus:main Nov 13, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants