open-telemetry / opentelemetry-collector-contrib

Contrib repository for the OpenTelemetry Collector
https://opentelemetry.io
Apache License 2.0
3.02k stars 2.33k forks source link

Add support for metrics in groupbyattrsprocessor #6232

Closed bertysentry closed 2 years ago

bertysentry commented 2 years ago

Use Case

When ingesting Prometheus metrics with the prometheusreceiver, all metrics are associated to the same Resource, which is simply the scraped target host (which happens to be localhost if you're using prometheusexecreceiver).

But the ingested Prometheus metrics may have a label that indicates that the metric relates to a different host (not the one where the Prometheus exporter is running), and this information cannot be leveraged and properly represented as a different Resource.

Without the proper Resource attachment, it is impossible for exporters to properly expose the Prometheus metrics (except the Prometheus exporters, which do not have such concept). Example: When exporting the metrics to Datadog (for example), only Resources (with a "host.name" label) are considered and displayed as Hosts.

Solution

This problem has already been solved with the groupbyattrs processor, which leverages the labels in a clever way to attach traces and logs to corresponding Resources. But this processor supports Traces and Logs signals only, unfortunately. Adding support for Metrics in the groupbyattrs processor would solve the problem very elegantly and would make Prometheus metrics ingestion much better translated into OTL metrics.

Alternatives

I've considered leveraging the metricstransform processor (which has a Group-By-Metric feature, but that doesn't allow using values coming from labels).

I've also considered the resourcedetection processor, but it doesn't process metrics and associates all metrics to the same Resource.

More information

Example of Prometheus metrics being consumed:

hw_target_ambient_temperature_celsius{host="ecs1-01.internal.sentrysoftware.net",} 19.0
hw_target_ambient_temperature_celsius{host="idrac-dell-ceph.internal.sentrysoftware.net",} 20.0

...do not appear as 2 separate hosts in Datadog, as they are associated to localhost: image

because Datadog simply creates Hosts based on OpenTelemetry Resources (with a proper host.name label).

pmm-sumo commented 2 years ago

Resolved via https://github.com/open-telemetry/opentelemetry-collector-contrib/pull/6248