Repository navigation
fix(prometheus-exporter): correctly normalize percent ratio units in map_unit - #5899
Open
knowprasad wants to merge 1 commit into
Open
knowprasad wants to merge 1 commit into
knowprasad wants to merge 1 commit into
Conversation
Pull request dashboard statusWaiting on reviewers · refreshed 2026-11-08 07:23 UTC Review the latest changes. Status above doesn't look right?
|
…map_unit
In map_unit(), compound ratio units were sanitizing the numerator before checking _UNIT_MAPPINGS. Because _sanitize_name("%") produces "_", the percent symbol was not resolved against _UNIT_MAPPINGS ("%": "percent"), producing "__per_second" instead of "percent_per_second".
Check raw_top against _UNIT_MAPPINGS before falling back to sanitization, preserving unit mappings for percent ratio units.
Fixes open-telemetry#5875
Signed-off-by: prsdx <prsdx.dev@gmail.com>
knowprasad
force-pushed
the
fix-5875-prometheus-map-unit-percent
branch
from
November 8, 2026 07:18
506aad8 to
900468d
Compare
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 #5875
Description
In
opentelemetry-exporter-prometheus,map_unitdid not correctly preserve the unit mapping for compound ratio units when the numerator was the percent symbol (%).When parsing ratio units separated by
/, the numerator was passed to_sanitize_name()before checking_UNIT_MAPPINGS. Since_sanitize_name("%")replaces non-alphanumeric characters with_, the subsequent_UNIT_MAPPINGS.get("_", "_")lookup failed to match the"%": "percent"mapping. This resulted in units such as%/s,%/min, and%/hbeing exported with the unit suffix__per_second,__per_min, and__per_hourrather thanpercent_per_second.This change checks
_UNIT_MAPPINGS.get(raw_top)before falling back to sanitization, ensuring percent ratio units are normalized as expected.Type of change
How Has This Been Tested?
tests/test_mapping.pycovering%/s,%/min,%/h, and annotated%{utilization}/s{interval}.tests/test_prometheus_exporter.pyverifyingtest_gauge_percent_per_second.pytest exporter/opentelemetry-exporter-prometheus/tests/(all 41 tests pass).ruff checkandruff format.