Allow repeated OpenMetrics metric families - #1197
Open
deepakganesh78 wants to merge 1 commit into
Open
Conversation
Signed-off-by: Deepak Ganesh <deepakganesh78@users.noreply.github.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.
Fixes #1091
Reproduction
Parsing OpenMetrics text shaped like
promtool tsdb dump-openmetrics, where the same metric family appears in separate blocks for different targets, currently raises:Minimal shape:
Root cause
The OpenMetrics parser kept a flat set of all sample names emitted by already-built metric families. When the same family name appeared again later, its own valid sample names were treated as clashing, even though they belonged to the same family.
Fix
Track the owning metric family for each seen sample name. Repeated blocks for the same family are accepted, while real suffix collisions between different families (for example
a_createdversus countera) still raiseValueError. The parser also rejects repeated family blocks if the family metadata changes type or unit.Compatibility notes
The parser docstring says it is intentionally laxer than the main Go parser. This remains compatible with the OpenMetrics model of MetricFamilies while allowing non-contiguous family blocks such as
promtool tsdb dump-openmetricsoutput; true name clashes are still rejected. See the OpenMetrics specification: https://github.com/OpenObservability/OpenMetrics/blob/main/specification/OpenMetrics.mdValidation
masterbefore the fix: minimal script raisedValueError: Clashing name: go_gc_duration_seconds.tests/openmetrics/test_parser.py::TestParse::test_repeated_metric_familyfailed with the sameValueError(1 failed).58 passed.427 passed, 3 skipped.flake8 prometheus_client/openmetrics/parser.py tests/openmetrics/test_parser.py: passed.isort --check prometheus_client/openmetrics/parser.py tests/openmetrics/test_parser.py: passed.mypy --install-types --non-interactive prometheus_client/openmetrics/parser.py tests/openmetrics/test_parser.py: reported existing Windows-onlyos.getpagesize/os.sysconfattribute errors inprometheus_client/process_collector.py(2 errors), unrelated to this change.