Merge colliding Prometheus label values#8364
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #8364 +/- ##
============================================
- Coverage 91.61% 91.59% -0.03%
- Complexity 10320 10338 +18
============================================
Files 1013 1013
Lines 27287 27359 +72
Branches 3203 3210 +7
============================================
+ Hits 25000 25059 +59
- Misses 1559 1573 +14
+ Partials 728 727 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
@psx95 Thanks for the thoughtful review |
|
There's significant conceptual overlap with #8346 - so I'd park this PR for now. |
Understood, thanks for the context. There's definitely conceptual overlap with #8346 in the Otel2PrometheusConverter label translation logic. I'll park this PR for now and revisit once #8346 settles, so the collision-handling fix can be cleanly applied on top of the final translation model. |
| MetricDataType.LONG_SUM, | ||
| Attributes.empty(), | ||
| Resource.create( | ||
| createMapAttributes("foo_bar", "b", "foo-bar", "c", "foo.bar", "a"))), |
There was a problem hiding this comment.
I eventually put together that createMapAttributes intentionally creates a non-default Attributes implementation to confirm the sorting logic.
- Let's add a comment explaining this because its not immediately apparent why we're going out of the way to add a new attributes implementation
- Is it possible / reasonable to avoid the extra allocation / overhead by detecting when the Attributes implementation is default ArrayBackedAttributes?
There was a problem hiding this comment.
Thinking about this more, I don't think we should try to check if Attributes is instance of ArrayBackedAttributes. But I am still worried about the excessive new allocation here which occurs regardless of whether a collision occurs. To mitigate, let's adjust to a strategy which assumes that no collision occurs, but if one does occur, triggers the code path with all this additional new machinery.
There was a problem hiding this comment.
Rebased this onto current main and addressed this in the latest push. The custom MapAttributes helper now has a short comment explaining that it intentionally uses a non-default Attributes implementation so the ordering-sensitive collision tests do not accidentally rely on the SDK default storage type. I did not add an ArrayBackedAttributes special case in production code.
| labelNameToValue.put( | ||
| convertLabelName(key.getKey()), toLabelValue(key.getType(), value))); | ||
| Map<String, String> labelNameToValue = new LinkedHashMap<>(); | ||
| normalizeAndMergeAttributeLabels(labelNameToValue, attributes); |
There was a problem hiding this comment.
This is just looking at attributes, but I think the collisions also have to consider collisions potentially caused by normalization of other sources of attributes: resource, scope, additionalAttributes
There was a problem hiding this comment.
Addressed in the rebased branch. Collision merging is now source-local and precedence-preserving: metric attributes are normalized/merged first, synthetic and scope labels keep their current putIfAbsent behavior, and filtered resource attributes are normalized/merged within the resource source before being applied last with putIfAbsent. That fixes normalized collisions without concatenating values across sources.
|
@jack-berg Thanks for the review. Those are good points — I’ll make sure to optimize the allocation with a fast path for the no-collision case, extend the collision check to resource/scope/additionalAttributes sources, and add the comment explaining the sorting logic.\n\nThis PR is currently parked per @zeitlinger’s request pending #8346. Once that settles, I’ll rebase, apply these changes, and re-request review. |
@ADITYA-CODE-SOURCE this is unblocked now |
Preserve Prometheus compatibility when normalized attribute names collide by joining the values in original-key order instead of letting later entries overwrite earlier ones. Add regression tests for metric and resource attribute collisions. Fixes open-telemetry#8236
5c8f7e1 to
6e3a97f
Compare
|
Rebased this parked PR onto current Latest update:
Local verification completed with:
The branch was force-pushed after rebase. |
|
This PR has review comments. Review suggestions, whether from maintainers or automated reviewers, aren't always correct or required. Please evaluate each comment on its merits, then make sure each thread has a clear outcome. For example, link to the commit if you applied a suggestion, explain why it wasn't applied, or ask a follow-up question. Automation flags a PR for human review once every review thread has a reply or is marked as resolved. Status across open PRs is visible on the pull request dashboard. |
|
Pushed a follow-up for the failing CI. The Linux/macOS I regenerated the apidiffs with Local verification:
At this point the code-side maintainer feedback is addressed and CI should rerun cleanly on the updated branch. The remaining merge blocker after CI is the stale review state from the earlier requested-changes review, which will still need maintainer re-review or dismissal. |
|
@psx95 @jack-berg CI is green now, and I’ve addressed the earlier review feedback in the rebased branch. The main implementation update is in Could you please take another look |
…y-java into issue-8236-prometheus-label-collisions
|
@psx95 @jack-berg All checks are green now, and the branch has been rebased onto current At this point the remaining merge blocker appears to be the old |
Summary
Fixes #8236