Skip to content

Merge colliding Prometheus label values#8364

Open
ADITYA-CODE-SOURCE wants to merge 3 commits into
open-telemetry:mainfrom
ADITYA-CODE-SOURCE:issue-8236-prometheus-label-collisions
Open

Merge colliding Prometheus label values#8364
ADITYA-CODE-SOURCE wants to merge 3 commits into
open-telemetry:mainfrom
ADITYA-CODE-SOURCE:issue-8236-prometheus-label-collisions

Conversation

@ADITYA-CODE-SOURCE
Copy link
Copy Markdown
Contributor

Summary

  • merge colliding normalized attribute labels by joining values with ';' in original-key order
  • preserve existing precedence between metric, resource, and synthetic labels while fixing collision handling
  • add regression tests for both metric attribute and allowed resource attribute normalization conflicts

Fixes #8236

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
@ADITYA-CODE-SOURCE ADITYA-CODE-SOURCE requested a review from a team as a code owner May 3, 2026 16:44
@codecov
Copy link
Copy Markdown

codecov Bot commented May 3, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.86%. Comparing base (1b207c6) to head (5c8f7e1).
⚠️ Report is 8 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #8364      +/-   ##
============================================
+ Coverage     90.82%   90.86%   +0.04%     
- Complexity     7927     7960      +33     
============================================
  Files           895      896       +1     
  Lines         23872    24039     +167     
  Branches       2378     2390      +12     
============================================
+ Hits          21681    21844     +163     
- Misses         1446     1457      +11     
+ Partials        745      738       -7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ADITYA-CODE-SOURCE
Copy link
Copy Markdown
Contributor Author

ADITYA-CODE-SOURCE commented May 6, 2026

@psx95 Thanks for the thoughtful review
I’ve addressed the suggestions in the latest commits, including broader collision coverage, stronger assertions, a cross-source collision case, and helper naming/documentation cleanup. I also fixed a follow-up test expectation in the new ordering case.
Appreciate the detailed feedback.

@zeitlinger
Copy link
Copy Markdown
Member

There's significant conceptual overlap with #8346 - so I'd park this PR for now.

@ADITYA-CODE-SOURCE
Copy link
Copy Markdown
Contributor Author

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.
Let me know if there's anything else I should do in the meantime.

MetricDataType.LONG_SUM,
Attributes.empty(),
Resource.create(
createMapAttributes("foo_bar", "b", "foo-bar", "c", "foo.bar", "a"))),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

labelNameToValue.put(
convertLabelName(key.getKey()), toLabelValue(key.getType(), value)));
Map<String, String> labelNameToValue = new LinkedHashMap<>();
normalizeAndMergeAttributeLabels(labelNameToValue, attributes);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Prometheus attribute conversion should merge values when collisions occur

4 participants