-
Notifications
You must be signed in to change notification settings - Fork 763
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
Include resource attributes as tags for Prometheus exporters #5489
Include resource attributes as tags for Prometheus exporters #5489
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #5489 +/- ##
==========================================
+ Coverage 83.38% 85.30% +1.92%
==========================================
Files 297 290 -7
Lines 12531 12611 +80
==========================================
+ Hits 10449 10758 +309
+ Misses 2082 1853 -229
Flags with carried forward coverage won't be shown. Click here to find out more.
|
@robertcoltheart Why would users want to do this instead of using the |
I mean, I agree with you. However it is part of the spec (link above) that this feature be supported. The Java version has this ability too. There is one use case I can think of which is for non-OpenMetrics scrapers, since the 'info' type (ie target_info) is only supported in OpenMetrics format. |
@robertcoltheart This bit from the spec?
The "MAY" part seems like an optional thing.
Things like exemplars are only supported in OpenMetrics format right? What I'm trying to gauge is if this is a short-lived thing we shouldn't bother supporting (forever) as everything in the prometheus world seems to be moving to OpenMetrics format. |
@CodeBlanch Yep agree with everything you said. I'll leave it to a maintainer to decide on what to do with this, I'm not heavily invested in it either way, and the otel_collector solves issues like adding common labels to metrics anyway (for example |
@robertcoltheart I added this to the agenda for our next SIG meeting so we can discuss if this is something we should do or not. Feel free to join! https://docs.google.com/document/d/1yjjD6aBcLxlRazYrawukDgrhZMObwHARJbB9glWdHj8/edit |
@robertcoltheart We just discussed this a bit on our SIG meeting. The outcome was more or less no one really has expertise enough in Prometheus to make a call. @alanwest volunteered to look into it and our plan is to make a decision next week. Sorry about the delay! |
No worries thanks for the update. As above, I don't have any skin in this game and only raised the PR as a way of fulfilling the spec as laid out, and to mirror the functionality of the Java version. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an optional feature per the Prometheus exporter spec.
A Prometheus Exporter MAY offer configuration to add resource attributes as metric attributes.
I'd personally be ok moving forward with this change simply to maintain feature parity with other key languages that have implemented it (Java, Go, maybe others). It is part of the spec and thank you @robertcoltheart for the time you've spent on this.
That said, we discussed again in today's meeting, and the opinion of other maintainers is to only implement this if there is user demand, so our plan is to not accept this PR at this time. I will open an issue shortly where folks can express their interest in this feature.
I'm leaving some comments with my thoughts just in case we come back to this in the future.
/// <summary> | ||
/// Gets or sets the allowed resource attributes filter. Default value: null (no attributes allowed). | ||
/// </summary> | ||
public Predicate<string> AllowedResourceAttributesFilter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand this implementation was inspired from Java's. It appears both Java and Go have implemented this as a predicate. That said, the spec is not opinionated in how this is implemented:
The configuration SHOULD allow the user to select which resource attributes to copy (e.g. include / exclude or regular expression based).
I think I'd prefer a simple include list. Something like:
/// <summary>
/// Gets or sets the resource attributes to include on each metric point. By default no resource attributes are included.
/// </summary>
public string[] IncludedResourceAttributes
return this.resource?.Attributes | ||
.Where(attribute => attributeFilter(attribute.Key)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we did keep this as a predicate, we could avoid evaluating the predicate on every single export. The configured resource is immutable. It does not change once the exporter is instantiated.
This PR was marked stale due to lack of activity and will be closed in 7 days. Commenting or Pushing will instruct the bot to automatically remove the label. This bot runs once per day. |
This PR was marked stale due to lack of activity and will be closed in 7 days. Commenting or Pushing will instruct the bot to automatically remove the label. This bot runs once per day. |
Closing. See #5489 (review) for details |
Fixes #3087
Design discussion issue #
See https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/compatibility/prometheus_and_openmetrics.md#resource-attributes-1
Changes
This is an extension of this pull request which adds
target_info
to the output of Prometheus exporters. This PR adds the default resource attributes as tags to each metric. By default, resource attributes are not included, but can be opted in by using the optional filter. This mirrors the Java code functionality.Note that OpenMetrics support is ignored here, since tags/labels are supported in non-OpenMetrics scrapers too.
Merge requirement checklist
CHANGELOG.md
files updated for non-trivial changes