Skip to content

feat: preserve metric suffixes in OpenMetrics 2.0 - #2529

Merged
zeitlinger merged 5 commits into
prometheus:mainfrom
arnabnandy7:feature/openMetricsSuffixes
Oct 15, 2026
Merged

zeitlinger merged 5 commits into
prometheus:mainfrom
arnabnandy7:feature/openMetricsSuffixes

Conversation

@arnabnandy7

@arnabnandy7 arnabnandy7 commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Add an opt-in OpenMetrics 2.0 compatibility setting for applications migrating from the existing client_java naming behavior.

  • Add io.prometheus.openmetrics2.suffixes.
  • Keep suffixes=false as the default so OM2 preserves names exactly as registered.
  • With suffixes=true, append missing unit suffixes and _total for counters.
  • Avoid duplicating suffixes already present in metric names.
  • Apply the selected naming behavior consistently to metadata and samples.
  • Document the compatibility setting and migration path.

Fixes #2518.

Why

OpenMetrics 2.0 uses a "name in, name out" model. For example:

Counter.builder()
    .name("requests")
    .unit(Unit.BYTES)
    .build();

OM2 exposes this as requests by default. Existing client_java applications may rely on the OM1-style exposition name requests_bytes_total, so switching formats can otherwise rename series and affect queries, alerts, recording rules, and dashboards.

Applications that need a gradual migration can temporarily enable compatibility naming:

io.prometheus.openmetrics2.suffixes=true

This exposes requests_bytes_total while producers and downstream consumers migrate. Once registrations use the intended names explicitly, compatibility mode can be disabled without changing the exposed series.

Implementation

When compatibility naming is enabled, the writer reuses MetricMetadata.expositionBaseName, which contains the normalized unit suffix and preserves explicitly provided suffixes. Counter names receive _total only when it is missing.

The existing OpenMetrics 1.0 summary-writing flow is reused with the selected metric name so summary metadata and samples follow the same configuration.

Validation

All current GitHub Actions checks pass, including build, lint, API diff, Java compatibility, integration, native, and acceptance tests.

Signed-off-by: Arnab Nandy <arnab_nandy7@yahoo.com>
@zeitlinger

Copy link
Copy Markdown
Member

Let's discuss the feature in #2518 first.

Signed-off-by: Arnab Nandy <arnab_nandy7@yahoo.com>
@github-actions

github-actions Bot commented Oct 7, 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

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

@arnabnandy7

Copy link
Copy Markdown
Contributor Author

Let's discuss the feature in #2518 first.

@zeitlinger sure thanks, I'll post in issue for further discussion.

Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
@zeitlinger
zeitlinger force-pushed the feature/openMetricsSuffixes branch from 4c98ad5 to 608b1f4 Compare October 13, 2026 16:20
Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
@zeitlinger
zeitlinger enabled auto-merge (squash) October 15, 2026 16:57
@zeitlinger
zeitlinger merged commit b1aa8b3 into prometheus:main Oct 15, 2026
23 checks passed
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.

OpenMetrics 2.0: option to keep _total and unit suffixes, so switching from OM1 doesn't rename series

2 participants