Parsing OpenMetrics text shaped like promtool tsdb dump-openmetrics, where the same metric family appears in separate blocks for different targets, currently raises:
ValueError: Clashing name: go_gc_duration_seconds
Minimal shape:
# TYPE go_gc_duration_seconds summary
go_gc_duration_seconds{instance="a",quantile="0"} 1
go_gc_duration_seconds_sum{instance="a"} 1
go_gc_duration_seconds_count{instance="a"} 1
# TYPE up gauge
up{instance="a"} 1
# TYPE go_gc_duration_seconds summary
go_gc_duration_seconds{instance="b",quantile="0"} 2
go_gc_duration_seconds_sum{instance="b"} 2
go_gc_duration_seconds_count{instance="b"} 1
# EOF
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_created versus counter a) still raise ValueError. 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-openmetrics output; true name clashes are still rejected. See the OpenMetrics specification: https://github.com/OpenObservability/OpenMetrics/blob/main/specification/OpenMetrics.md
Validation
Reproduced on current master before the fix: minimal script raised ValueError: Clashing name: go_gc_duration_seconds.
Regression test without the parser fix: tests/openmetrics/test_parser.py::TestParse::test_repeated_metric_family failed with the same ValueError (1 failed).
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
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:
# TYPE go_gc_duration_seconds summary go_gc_duration_seconds{instance="a",quantile="0"} 1 go_gc_duration_seconds_sum{instance="a"} 1 go_gc_duration_seconds_count{instance="a"} 1 # TYPE up gauge up{instance="a"} 1 # TYPE go_gc_duration_seconds summary go_gc_duration_seconds{instance="b",quantile="0"} 2 go_gc_duration_seconds_sum{instance="b"} 2 go_gc_duration_seconds_count{instance="b"} 1 # EOFRoot 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_created versus counter a) still raise ValueError. 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-openmetrics output; true name clashes are still rejected. See the OpenMetrics specification: https://github.com/OpenObservability/OpenMetrics/blob/main/specification/OpenMetrics.md
Validation