Skip to content

expfmt: default to allow-utf-8 escaping for OpenMetrics 2.0 - #1008

Merged
bwplotka merged 1 commit into
prometheus:mainfrom
KR-Ravindra:fix/om2-negotiate-utf8-escaping
Oct 13, 2026
Merged

bwplotka merged 1 commit into
prometheus:mainfrom
KR-Ravindra:fix/om2-negotiate-utf8-escaping

Conversation

@KR-Ravindra

Copy link
Copy Markdown
Contributor

@roidelapluie

Problem

When a scraper negotiates OpenMetrics 2.0 without an escaping parameter (which is what Prometheus sends today), NegotiateAccept appends model.NameEscapingScheme, so UTF-8 metric and label names get escaped to underscores. OpenMetrics 2.0 is UTF-8 native and has no escaping parameter.

Also, the escaping value was carried across Accept clauses, so an escaping on a skipped clause could apply to a later match.

Fix

Following the pseudo-code in the issue: the escaping term now comes from the clause that matched. An explicit, known escaping always wins; otherwise OpenMetrics 2.0 gets allow-utf-8 and every other format keeps model.NameEscapingScheme. Fallbacks are unchanged.

Same fix as prometheus/client_java#2519.

Part of prometheus/client_golang#2149 (client_golang still needs a dependency bump and a promhttp test).

How tested

New NegotiateAccept cases (OM 2.0 with and without escaping, unknown escaping, OM 1.0 default, skipped-clause leak) and an encode test checking that UTF-8 names stay unescaped only for OM 2.0. go test ./... and make common-lint pass.

Prepared with an AI agent operated by KR-Ravindra, who reviewed and tested it. The agent is pointed only at issues maintainers have confirmed and problems he has hit, not at producing contributions.

OpenMetrics 2.0 supports UTF-8 names natively and defines no escaping
parameter, so a scraper negotiating it without one should not get names
escaped with model.NameEscapingScheme. An explicit escaping parameter
still wins.

The escaping parameter is now also taken only from the Accept clause that
matched, so a value on a skipped clause no longer leaks into a later match.

Part of prometheus/client_golang#2149

Signed-off-by: KR Ravindra <42912207+KR-Ravindra@users.noreply.github.com>
@KR-Ravindra
KR-Ravindra marked this pull request as ready for review October 4, 2026 04:20

@bwplotka bwplotka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@bwplotka
bwplotka merged commit 25bdf5c into prometheus:main Oct 13, 2026
8 checks passed
gjed added a commit to gjed/github-activity-exporter that referenced this pull request Nov 10, 2026
v0.73.0 (prometheus/common#1008) takes the escaping
scheme only from the matching Accept clause. expfmt negotiates only text
0.0.4, so the Prometheus 3.x default scrape gets escaping=underscores and
/metrics serves underscored names instead of pure OTel names. Hold until
prometheus/common#1035 lands.
gjed added a commit to gjed/github-activity-exporter that referenced this pull request Nov 15, 2026
prometheus/common v0.74.0 ships text format 1.0.0 negotiation
(prometheus/common#1035), so Prometheus 3.x's default scrape matches
text/plain;version=1.0.0;escaping=allow-utf-8 and /metrics serves
github.pr.count again instead of github_pr_count. Remove the
allowedVersions <0.73.0 rule added in #105.

Escaping is taken only from the matching Accept clause since v0.73.0
(prometheus/common#1008). /metrics does not serve OpenMetrics, so an
OpenMetrics-only Accept matches no format and gets underscore names.
The openmetrics live-check case now scrapes with the Prometheus
v3.16.0 default header, which also offers text 1.0.0.

go mod tidy adds github.com/pandatix/go-abnf v0.5.5 and raises
go.yaml.in/yaml/v2 to v2.4.5, both required by common v0.74.0, and
drops stale go.sum lines.

Closes #109
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants