Skip to content

feat: preserve metric suffixes in OpenMetrics 2.0 - #2529

Open
arnabnandy7 wants to merge 2 commits into
prometheus:mainfrom
arnabnandy7:feature/openMetricsSuffixes
Open

arnabnandy7 wants to merge 2 commits into
prometheus:mainfrom
arnabnandy7:feature/openMetricsSuffixes

Conversation

@arnabnandy7

Copy link
Copy Markdown
Contributor

Summary

Add an OpenMetrics 2.0 naming option that preserves the suffix behavior of OpenMetrics 1.0 by default.

  • Add io.prometheus.openmetrics2.suffixes.
  • Default suffixes to true.
  • Append missing unit suffixes and _total for counters.
  • Avoid duplicating suffixes already present in metric names.
  • Allow exact application-provided names with suffixes=false.
  • Apply the selected naming behavior consistently to metadata and samples.
  • Document the default and opt-out behavior.

Fixes #2518.

Why

Previously, enabling the OpenMetrics 2.0 writer exposed names exactly as passed to metric builders. For common instrumentation such as:

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

OpenMetrics 1.0 exposed requests_bytes_total, while OpenMetrics 2.0 exposed requests.

Changing the negotiated format could therefore create new series and silently break existing queries, alerts, recording rules, and dashboards.

With this change, the OpenMetrics 2.0 writer exposes requests_bytes_total by default. Users who need suffix-free or OpenTelemetry-style names can opt out:

io.prometheus.openmetrics2.suffixes=false

Implementation

The writer reuses MetricMetadata.expositionBaseName, which already contains the normalized unit suffix and preserves explicitly provided suffixes. Counter names then 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

Ran targeted tests for the affected modules:

Tests run: 52, Failures: 0, Errors: 0, Skipped: 0
BUILD SUCCESS

Command:

./mvnw test \
  -pl prometheus-metrics-config,prometheus-metrics-exposition-textformats,prometheus-metrics-core \
  -am \
  -Dtest=OpenMetrics2PropertiesTest,PrometheusPropertiesTest,OpenMetrics2TextFormatWriterTest \
  -Dcoverage.skip=true \
  -Dsurefire.failIfNoSpecifiedTests=false

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.

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.

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

2 participants