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

[metricstransform] Add resource attribute copy to metric label #2630

Closed
wants to merge 1 commit into from

Conversation

seanhoughton
Copy link
Contributor

Description:

Add the ability to copy resource attributes into metric labels. This allows users to use resource attributes like "hostname" or "pod name" as labels in metrics without having to re-instrument the application.

This is a WIP as I can't get the tests to pass yet and I would like some feedback before spending any more time on it.

Link to tracking Issue:

#2568

Testing:

I added a test case for the new operation

Documentation:

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Mar 10, 2021

CLA Signed

The committers are authorized under a signed CLA.

  • ✅ Sean Houghton (618f235670d147d72425dec8ec7724e28a6919d2)

@seanhoughton
Copy link
Contributor Author

I can't figure out how to reference the v1.Resource instance from inside a transform op processor but it's not available inside the processor. I've also tried putting an instance on the internaldata.MetricsData instance but it seems to be stripped away inside ConsumeMetrics and is nil by the time it reaches the processor.

@seanhoughton seanhoughton force-pushed the fix/2568 branch 2 times, most recently from 9177f37 to 6ae6d63 Compare March 12, 2021 19:39
@codecov
Copy link

codecov bot commented Mar 12, 2021

Codecov Report

Merging #2630 (b0d74d7) into main (047b1d9) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #2630   +/-   ##
=======================================
  Coverage   91.47%   91.47%           
=======================================
  Files         439      440    +1     
  Lines       21855    21870   +15     
=======================================
+ Hits        19991    20005   +14     
- Misses       1394     1395    +1     
  Partials      470      470           
Flag Coverage Δ
integration 69.18% <ø> (-0.07%) ⬇️
unit 90.39% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
processor/metricstransformprocessor/config.go 100.00% <ø> (ø)
processor/metricstransformprocessor/factory.go 98.88% <100.00%> (+0.02%) ⬆️
...stransformprocessor/metrics_transform_processor.go 99.30% <100.00%> (+<0.01%) ⬆️
...formprocessor/operation_copy_resource_attribute.go 100.00% <100.00%> (ø)
receiver/carbonreceiver/transport/tcp_server.go 66.00% <0.00%> (-1.00%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 047b1d9...b0d74d7. Read the comment docs.

@seanhoughton seanhoughton force-pushed the fix/2568 branch 7 times, most recently from 9abaa9b to 14e30b1 Compare March 15, 2021 05:11
@seanhoughton
Copy link
Contributor Author

This PR works in my tests, is documented, and has tests.

@seanhoughton seanhoughton marked this pull request as ready for review March 15, 2021 15:53
@seanhoughton seanhoughton requested a review from a team March 15, 2021 15:53
@mxiamxia
Copy link
Member

mxiamxia commented Mar 16, 2021

This should be done by enabling resource_to_telemetry_conversion config in each metric exporter, which has been designed for this specific purpose.

exporterhelper.ResourceToTelemetrySettings `mapstructure:"resource_to_telemetry_conversion"`

https://github.com/open-telemetry/opentelemetry-collector/blob/main/exporter/exporterhelper/resource_to_label.go#L23

kisieland pushed a commit to kisieland/opentelemetry-collector-contrib that referenced this pull request Mar 16, 2021
@seanhoughton
Copy link
Contributor Author

The resource_to_telemetry_conversion copies every resource attribute to metric labels which is not desirable if you want to manage the number of unique metric series produced. Would it be better to extend that option to include an optional list of labels to be copied instead of using the transform approach?

@github-actions
Copy link
Contributor

This PR was marked stale due to lack of activity. It will be closed in 7 days.

@github-actions github-actions bot added the Stale label Mar 24, 2021
@seanhoughton
Copy link
Contributor Author

The resource_to_telemetry_conversion is not supported by many exporters (including the prometheus exporter). I'll close this PR in favor of using the resource_to_telemetry_conversion config - but it will require some work to implement in multiple exporters.

@pmalek-sumo
Copy link
Contributor

resource_to_telemetry_conversion

What should one do if further data processing is required? This being at the exporter stage doesn't allow that.

Perhaps we could revisit this and think of adding similar feature at the processor stage? WDYT @mxiamxia ?

@awiddersheim
Copy link

awiddersheim commented Jul 15, 2022

I still see value in this functionality. I can certainly see how adding this functionality can be confusing when resource_to_telemetry_conversion exists but think there is room for both.

Let me see if I can describe my use case. I'm scraping metrics from services using the prometheus receiver and enriching those metrics with the resourcedetectionprocessor. With the resource_to_telemetry_conversion option enabled this tends to greatly increase cardinality.

One option I considered was to instead use the target informational metric the prometheusremotewrite exporter emits. Each attribute seems to get added to target as a label. You could then turn off the resource_to_telemetry_conversion configuration option and each metric scraped would only have the labels added by the services without the enrichment.

It seems a common pattern to do joins against an information metric to help expand context when necessary while also reducing cardinality/active series. Typically you would do this with some unique node ID.

The problem is I would now need to build logic into each service to have a node ID label as a default for every metric emitted to do that join. Essentially, in each service I would need to do what the otel-collector is doing when it is detecting resources so the target metric's node label has the same value as all of my metrics. Instead, it would be nice to just have the collector add that label for me with the metricstransformprocessor.

Perhaps there are better approaches for what I'm looking to achieve, so open to other options.

@singku
Copy link
Contributor

singku commented Jul 25, 2022

I'd love to see this feature as well. resource_to_telemetry_conversion doesn't meet our needs if we do not need that extra metrics label.

@TylerHelmuth
Copy link
Member

TylerHelmuth commented Jul 26, 2022

@awiddersheim and @singku the transformprocessor may be able to meet your needs. It is able to set the attribute of data points using a resource attribute. It looks like set(attributes["the name the new attribute"], resource.attributes["the name of the resource attribute you want to copy"]). It also has the ability to delete attributes using the delete_key function.

@singku
Copy link
Contributor

singku commented Aug 17, 2022

Thank you Tyler, I will give it a try

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants