Skip to content

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

Open
KR-Ravindra wants to merge 1 commit into
prometheus:mainfrom
KR-Ravindra:fix/om2-negotiate-utf8-escaping
Open

KR-Ravindra wants to merge 1 commit into
prometheus:mainfrom
KR-Ravindra:fix/om2-negotiate-utf8-escaping

Conversation

@KR-Ravindra

Copy link
Copy Markdown

@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
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.

1 participant