Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: otel prometheus duplicated attributes #62

Merged
merged 5 commits into from
May 29, 2023
Merged

fix: otel prometheus duplicated attributes #62

merged 5 commits into from
May 29, 2023

Conversation

fracasula
Copy link
Collaborator

@fracasula fracasula commented May 26, 2023

Description

This is to address an error that happens when the same label is set both at the resource level and at the metric label.
The underlying Prometheus client is the one raising the error here.

The proposal is to remove the duplicate at the metric level (so the resource will take precedence) and to log it in order to take action if needed/wanted.

In the gRPC version the resource attributes take precedence and the metric is not lost.

Notion Ticket

< Notion Link >

Security

  • The code changed/added as part of this pull request won't create any security issues with how the software is being used.

@codecov
Copy link

codecov bot commented May 26, 2023

Codecov Report

Patch coverage: 80.48% and project coverage change: -0.02 ⚠️

Comparison is base (afa3611) 78.01% compared to head (499ff92) 78.00%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #62      +/-   ##
==========================================
- Coverage   78.01%   78.00%   -0.02%     
==========================================
  Files          56       56              
  Lines        3539     3555      +16     
==========================================
+ Hits         2761     2773      +12     
- Misses        643      646       +3     
- Partials      135      136       +1     
Impacted Files Coverage Δ
stats/otel.go 71.96% <75.00%> (-0.69%) ⬇️
stats/statsd.go 74.71% <84.61%> (+0.70%) ⬆️
stats/stats.go 98.57% <85.71%> (-1.43%) ⬇️
stats/internal/otel/prometheus/exporter.go 57.67% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@fracasula
Copy link
Collaborator Author

I just realized the implementation makes the metric one take precedence. Will fix and increase test coverage.

@fracasula fracasula closed this May 26, 2023
@fracasula
Copy link
Collaborator Author

Fixed, please have a look.

@fracasula fracasula reopened this May 26, 2023
Comment on lines 18 to 20
//
// 5. added logic to remove and detect duplicated attributes (instead of concatenating them to stay compatible
// with gRPC)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would refrain from performing any further customisations to the original exporter. I would prefer extending our existing label deduplication logic in stats package instead, which now detects duplicate labels that the user provides, and include an extra validation for labels managed by our own library.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not a bad idea, although I don't think we'll go back to having the original exporter. It would require too many changes to our dashboards, plus the exporter is fairly small/simple, it shouldn't be much trouble to maintain it.

Anyhow, I moved the logic into stats now, the only concern is the duplication of sanitization logic. Have a look let me know what you think 👍

Comment on lines +168 to +170
if _, ok := s.config.excludedTags[k]; ok {
continue
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need this?

Suggested change
if _, ok := s.config.excludedTags[k]; ok {
continue
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I thought I'd leave it for backwards compatibility in case somewhere there is an exclusion rule that would work only before the tag is sanitized. I thought it wouldn't hurt having for now.

Comment on lines 253 to 255
if _, ok := s.config.excludedTags[k]; ok {
delete(tags, k)
continue
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

do we need this too?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Same as above, better safe than sorry since we might not be the only ones using this lib and I'm not planning to check everywhere if removing it might break an exclusion 🤷‍♂️

@cisse21 cisse21 merged commit 34c9d32 into main May 29, 2023
@cisse21 cisse21 deleted the fix.dupLabels branch May 29, 2023 10:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants