Skip to content

fix: don't escape UTF-8 names by default for OpenMetrics 2.0 - #2519

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

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

Conversation

@KR-Ravindra

Copy link
Copy Markdown
Contributor

Fixes #2517

Problem

A scrape with Accept: application/openmetrics-text;version=2.0.0 and no escaping parameter still gets UTF-8 names escaped to underscores. PrometheusScrapeHandler picks the escaping scheme before findWriter and falls back to underscores whenever the header has no escaping term. OpenMetrics 2.0 has no such parameter and Prometheus doesn't send one.

Fix

  • Pick the escaping scheme after findWriter. If the OM2 writer serves a request that explicitly asked for version=2.0.0, the fallback is allow-utf-8; otherwise it stays underscores.
  • The version check matters with contentNegotiation=false, where the OM2 writer also serves OM 1.0 and unversioned requests from scrapers that may not handle UTF-8 names.
  • An explicit escaping term still wins.
  • Add EscapingScheme.fromAcceptHeader(String, EscapingScheme fallback); the existing method delegates with DEFAULT.
  • One sentence in the Unicode docs.

How tested

New PrometheusScrapeHandlerTest cases: version=2.0.0 keeps my.counter (fails on main), version=2.0.0;escaping=underscores escapes, and OM 1.0, unversioned OpenMetrics and text/plain keep underscores, each with content negotiation on and off. Plus EscapingSchemeTest for the new overload.

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.

@KR-Ravindra
KR-Ravindra marked this pull request as ready for review October 4, 2026 00:10
OpenMetrics 2.0 supports UTF-8 names and has no escaping parameter, but
PrometheusScrapeHandler picked the escaping scheme before the writer and
fell back to underscores whenever the Accept header had no escaping
term. Prometheus does not send one for OM 2.0, so UTF-8 names were
escaped.

Choose the escaping scheme after findWriter and default to allow-utf-8
when the OM2 writer serves an explicit version=2.0.0 request. An
explicit escaping term still wins, and OM 1.0, unversioned OpenMetrics
and text requests keep the underscores default, also with
contentNegotiation=false. EscapingScheme.fromAcceptHeader gets an
overload taking the fallback scheme.

Signed-off-by: KR Ravindra <42912207+KR-Ravindra@users.noreply.github.com>
@KR-Ravindra
KR-Ravindra force-pushed the fix/om2-default-utf8-escaping branch from b013c0f to e870943 Compare October 4, 2026 00:38
@github-actions

github-actions Bot commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

⚠️ API changes detected — maintainer review required

This PR modifies the published API diff for the following module(s):

  • prometheus-metrics-config
  • prometheus-metrics-exporter-common

Please review the changes in docs/apidiffs/current_vs_latest/ carefully before approving.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Don't escape UTF-8 names by default for OpenMetrics 2.0

1 participant