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 prometheusexporter droping the OTEL resource labels #2899

Merged

Conversation

krak3n
Copy link
Contributor

@krak3n krak3n commented Apr 7, 2021

Description:
Added support for resource_to_telemetry_conversion to the Promethus Exporter so resource attributes are added as labels to metrics.

Link to tracking Issue: Fixes #2498

Testing:
Added new test cases to ensure resource labels are included in the prometheus metrics output when resource_to_telemetry_conversion is enabled.

Two existing test cases were amended due to their requirement via a type assertion to have access to the underlying prometheusExporter which is no longer the case since this was changed to a *exporterhelper.metricsExporter. To accommodate this a wrapper was added which allowed the type assertion to work and the test cases to pass.

Manual testing was done by building and running the otelcol locally with the following configuration:

receivers:
  otlp:
    protocols:
      grpc:

exporters:
  prometheus:
    endpoint: "0.0.0.0:8889"
    resource_to_telemetry_conversion:
      enabled: true

processors:
  batch:

service:
  pipelines:
    metrics:
      receivers: [otlp]
      processors: [batch]
      exporters: [prometheus]

A service was written to send metrics with a resource to the locally running otelcol and the prometheus metrics endpoint was queried and observed that metrics now had resource labels attached to them, e.g:

# HELP example_bar
# TYPE example_bar counter
example_bar{deployment_environment="development",foo="bar",service_name="foo-srv",service_version="v1.2.3",telemetry_sdk_language="go",telemetry_sdk_name="opentelemetry",telemetry_sdk_version="0.19.0"} 193

Documentation:

The Prometheus Exporter README.md was updated to include documentation about the new resource_to_telemetry_conversion configuration option.

@krak3n krak3n requested a review from a team April 7, 2021 20:30
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Apr 7, 2021

CLA Signed

The committers are authorized under a signed CLA.

@codecov
Copy link

codecov bot commented Apr 7, 2021

Codecov Report

Merging #2899 (1d5a944) into main (13e4566) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #2899   +/-   ##
=======================================
  Coverage   91.63%   91.64%           
=======================================
  Files         312      312           
  Lines       15404    15420   +16     
=======================================
+ Hits        14116    14132   +16     
  Misses        881      881           
  Partials      407      407           
Impacted Files Coverage Δ
exporter/prometheusexporter/config.go 100.00% <ø> (ø)
exporter/prometheusexporter/factory.go 100.00% <100.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 13e4566...1d5a944. Read the comment docs.

@@ -17,6 +17,8 @@ The following settings can be optionally configured:
- `send_timestamps` (default = `false`): if true, sends the timestamp of the underlying
metric sample in the response.
- `metric_expiration` (default = `5m`): defines how long metrics are exposed without updates
- `resource_attributes_as_tag` (default = `false`): if set to true will transform all resource

Choose a reason for hiding this comment

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

I was looking into this exact same feature with the prometheusremotewriteexporter. Was just wondering - strictly speaking it is "resource attributes as labels"? I guess Prometheus uses the term "label" instead of "tag"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As @bogdandrutu I'll switch it to a convention thats used over in the contrib repo so things are kept consistent, so this will change too

        resource_to_telemetry_conversion:
            enabled: true

@@ -17,6 +17,8 @@ The following settings can be optionally configured:
- `send_timestamps` (default = `false`): if true, sends the timestamp of the underlying
metric sample in the response.
- `metric_expiration` (default = `5m`): defines how long metrics are exposed without updates
- `resource_attributes_as_tag` (default = `false`): if set to true will transform all resource
Copy link
Member

Choose a reason for hiding this comment

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

seems to be tags not tag


// ResourceAttributesAsTags, if sMet to true, will use the exporterhelper feature to
// transform all resource attributes into metric labels.
ResourceAttributesAsTags bool `mapstructure:"resource_attributes_as_tags"`
Copy link
Member

Choose a reason for hiding this comment

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

In contrib where we use this, we have config like:

	exporterhelper.ResourceToTelemetrySettings `mapstructure:"resource_to_telemetry_conversion"`

so the config will be:

   resource_to_telemetry_conversion:
      enabled: true

If you don't like that name maybe embed that settings but use the name resource_attributes_as_tags? What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah cool, it should be consistent with existing implementations so happy to switch it up to:

        resource_to_telemetry_conversion:
            enabled: true

@krak3n
Copy link
Contributor Author

krak3n commented Apr 13, 2021

@bogdandrutu I've pushed the required changes, sorry for the delay 👍

@bogdandrutu bogdandrutu merged commit 034902c into open-telemetry:main Apr 21, 2021
@krak3n krak3n deleted the fix/prometheus-exporter-resource-labels branch April 22, 2021 10:26
hughesjj pushed a commit to hughesjj/opentelemetry-collector that referenced this pull request Apr 27, 2023
…#2899)

Bumps [github.com/hashicorp/vault](https://github.com/hashicorp/vault) from 1.13.0 to 1.13.1.
- [Release notes](https://github.com/hashicorp/vault/releases)
- [Changelog](https://github.com/hashicorp/vault/blob/main/CHANGELOG.md)
- [Commits](hashicorp/vault@v1.13.0...v1.13.1)

---
updated-dependencies:
- dependency-name: github.com/hashicorp/vault
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
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.

prometheusexporter droping the OTEL resource lables
6 participants