fix: Preserve original metric names in OM2 output#2058
Merged
zeitlinger merged 1 commit intomainfrom Apr 27, 2026
Merged
Conversation
Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
034ad7a to
4eb69b8
Compare
jaydeluca
approved these changes
Apr 27, 2026
zeitlinger
added a commit
that referenced
this pull request
Apr 27, 2026
🤖 I have created a release *beep* *boop* --- ## [1.6.1](v1.6.0...v1.6.1) (2026-04-27) ### Bug Fixes * Preserve original metric names in OM2 output ([#2058](#2058)) ([59a7a6d](59a7a6d)) ### Documentation * clarify 1.6.0 release notes ([#2062](#2062)) ([9e5d591](9e5d591)) * Document semantic PR title guidance ([#2060](#2060)) ([7277889](7277889)) --- > [!IMPORTANT] > Close and reopen this PR to trigger CI checks. --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
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.
Refs #1954.
Summary
This fixes OM2 name preservation in the text writer.
_infoexception for info metrics..unit(...).Why
openmetrics2.enabled=trueis documented as preserving metric names as written by the application. The writer still used OM1-derived names in several paths, and classic histograms delegated to the OM1 writer, so.unit(...)could still leak unit-suffixed names into OM2 output.Smoking gun
prometheus-metrics-core/src/test/java/io/prometheus/metrics/core/metrics/OpenMetrics2TextFormatWriterTest.javaadds
counterPreservesOriginalNameWhenUnitIsConfigured().That test builds a real counter through the public builder API:
It then asserts that OM1 still emits the legacy name
my_counter_seconds_total, while OM2 emitsmy_counterand does not containmy_counter_seconds.I verified this test fails against pre-fix
origin/mainwhen only the test is applied:That is the bug this PR fixes: OM2 was still using the OM1 unit-suffixed metric name.
Validation
./mvnw test -pl prometheus-metrics-core,prometheus-metrics-exposition-textformats -am -Dtest=OpenMetrics2TextFormatWriterTest -Dcoverage.skip=true -Dcheckstyle.skip=true -Dsurefire.failIfNoSpecifiedTests=falsemise run buildmise run lintgit diff --check