fix: don't escape UTF-8 names by default for OpenMetrics 2.0 - #2519
Open
KR-Ravindra wants to merge 1 commit into
Open
KR-Ravindra wants to merge 1 commit into
KR-Ravindra wants to merge 1 commit into
Conversation
KR-Ravindra
marked this pull request as ready for review
October 4, 2026 00:10
KR-Ravindra
requested review from
dhoard,
fstab,
jaydeluca and
zeitlinger
as code owners
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
force-pushed
the
fix/om2-default-utf8-escaping
branch
from
October 4, 2026 00:38
b013c0f to
e870943
Compare
Contributor
|
This branch has not been deployed
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.
Fixes #2517
Problem
A scrape with
Accept: application/openmetrics-text;version=2.0.0and noescapingparameter still gets UTF-8 names escaped to underscores.PrometheusScrapeHandlerpicks the escaping scheme beforefindWriterand falls back tounderscoreswhenever the header has noescapingterm. OpenMetrics 2.0 has no such parameter and Prometheus doesn't send one.Fix
findWriter. If the OM2 writer serves a request that explicitly asked forversion=2.0.0, the fallback isallow-utf-8; otherwise it staysunderscores.contentNegotiation=false, where the OM2 writer also serves OM 1.0 and unversioned requests from scrapers that may not handle UTF-8 names.escapingterm still wins.EscapingScheme.fromAcceptHeader(String, EscapingScheme fallback); the existing method delegates withDEFAULT.How tested
New
PrometheusScrapeHandlerTestcases:version=2.0.0keepsmy.counter(fails on main),version=2.0.0;escaping=underscoresescapes, and OM 1.0, unversioned OpenMetrics andtext/plainkeep underscores, each with content negotiation on and off. PlusEscapingSchemeTestfor 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.