Hacktoberfest 2026 : les issues que les mainteneurs ont marquées pour octobre, ouvertes et accessibles aux débutants. Parcourir les issues Hacktoberfest

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

Ouverte
#2,517 0 commentaires 1 réaction 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

@KR-Ravindra y travaille déjà.

Depuis le 4/10/2026.

  • #2519 par @KR-Ravindra — ouverte

Évaluation

Difficulté
4/5
Temps estimé
3-5 jours
Accessibilité débutants
35/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
À l'abandon
Stack technique
java

Piste de recherche

Start with prometheus-metrics-config/.../EscapingScheme.java, PrometheusScrapeHandler.java, and ExpositionFormats.java, then inspect how Accept clauses are parsed and matched. Add coverage in ExpositionFormatsTest and a scrape-handler test for OM 2.0, explicit escaping, older formats, and contentNegotiation=false. Update the referenced escaping schemes documentation and verify the linked pull request before starting.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

When a scraper negotiates OpenMetrics 2.0 (Accept: application/openmetrics-text;version=2.0.0) without an escaping parameter, PrometheusScrapeHandler escapes UTF-8 metric and label names with EscapingScheme.DEFAULT (underscores). OpenMetrics 2.0 supports UTF-8 names natively and doesn't define an escaping parameter at all, so we could assume that scraper asking for 2.0.0 already supports UTF-8 names. In that case we shouldn't escape by default.

Prometheus main doesn't send escaping for OM 2.0 (https://github.com/prometheus/prometheus/blob/961c9ba40923ca4d7adf4a7a9167e56d0406df83/scrape/scrape.go#L794-L800), so UTF-8 names are currently escaped to underscores when scraping a Java target with OM 2.0. There's a Prometheus-side workaround in https://github.com/prometheus/prometheus/compare/main...bwplotka/om2-accept-escaping, but the default here should be fixed regardless.

The escaping scheme is chosen without looking at the selected format:

Proposed change (pseudo code):

// PrometheusScrapeHandler
String acceptHeader = request.getHeader("Accept");
ExpositionFormatWriter writer = expositionFormats.findWriter(acceptHeader);
EscapingScheme escapingScheme = EscapingScheme.fromAcceptHeader(acceptHeader, defaultFor(acceptHeader));

// Only default to UTF-8 when 2.0.0 was explicitly requested. With
// contentNegotiation=false the OM 2.0 writer also serves OM 1.0 / unversioned
// requests, e.g. from pre-3.0 Prometheus that can't parse UTF-8 names.
EscapingScheme defaultFor(String acceptHeader) {
  return "2.0.0".equals(parseOpenMetricsVersion(acceptHeader))
      ? EscapingScheme.ALLOW_UTF8
      : EscapingScheme.DEFAULT;
}

// EscapingScheme
public static EscapingScheme fromAcceptHeader(@Nullable String acceptHeader, EscapingScheme fallback) {
  // Same parsing as today. An explicit escaping term always wins, also for OM 2.0
  // (e.g. a Prometheus with legacy name validation asking for underscores).
  // Return fallback instead of DEFAULT when the term is missing or unknown.
}

Existing fromAcceptHeader(String) can keep delegating with DEFAULT to stay API compatible. Ideally the version and escaping term should come from the same Accept clause that findWriter matched. Today both helpers scan the whole header, so a parameter from another clause can leak in.

Tests to add (e.g. ExpositionFormatsTest, plus a scrape handler test):

  • version=2.0.0 without escaping writes unescaped UTF-8 names.
  • version=2.0.0;escaping=underscores still escapes.
  • version=1.0.0, unversioned OpenMetrics and text/plain without escaping keep the underscores default, including with contentNegotiation=false.

The escaping schemes doc should get the same OM 2.0 exception, since its "Default Behavior" section says to use underscores whenever escaping is missing: https://github.com/prometheus/docs/blob/605cf81fefc2e8e91f8ba89bb1555ae52a43a318/docs/instrumenting/escaping_schemes.md#default-behavior.

Matching client_golang issue: https://github.com/prometheus/client_golang/issues/2149

Langage dominant
Java
Étoiles
2.3k
Forks
832
Merge moyen
1 j 7 h
PR mergées (30 j)
63

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de prometheus/client_java

Toutes les issues de prometheus/client_java

Issues similaires

Plus d'issues Java

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.