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

add option for resource attributes in metrics for prometheus exporter #4733

Merged

Conversation

codeboten
Copy link
Contributor

This PR adds the WithResourceAsConstantLabels option to the Prometheus exporter to allow users to configure resource attributes to be applied on every metric.

Fixes #4732

Copy link

codecov bot commented Nov 29, 2023

Codecov Report

Merging #4733 (b7cb11c) into main (0405492) will increase coverage by 0.0%.
The diff coverage is 90.6%.

Additional details and impacted files

Impacted file tree graph

@@          Coverage Diff          @@
##            main   #4733   +/-   ##
=====================================
  Coverage   81.9%   81.9%           
=====================================
  Files        224     224           
  Lines      18116   18136   +20     
=====================================
+ Hits       14847   14865   +18     
- Misses      2982    2984    +2     
  Partials     287     287           
Files Coverage Δ
exporters/prometheus/config.go 100.0% <100.0%> (ø)
exporters/prometheus/exporter.go 84.7% <89.4%> (+0.7%) ⬆️

... and 1 file with indirect coverage changes

Copy link
Contributor

@MadVikingGod MadVikingGod left a comment

Choose a reason for hiding this comment

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

It looks good so far.

exporters/prometheus/config.go Outdated Show resolved Hide resolved
exporters/prometheus/exporter.go Outdated Show resolved Hide resolved
exporters/prometheus/exporter_test.go Outdated Show resolved Hide resolved
exporters/prometheus/config.go Outdated Show resolved Hide resolved
exporters/prometheus/exporter.go Outdated Show resolved Hide resolved
exporters/prometheus/exporter.go Outdated Show resolved Hide resolved
exporters/prometheus/exporter.go Outdated Show resolved Hide resolved
Alex Boten and others added 6 commits November 29, 2023 15:47
This PR adds the `WithResourceAsConstantLabels` option to the Prometheus exporter to allow users to configure resource attributes to be applied on every metric.

Fixes open-telemetry#4732

Signed-off-by: Alex Boten <aboten@lightstep.com>
Signed-off-by: Alex Boten <aboten@lightstep.com>
Signed-off-by: Alex Boten <aboten@lightstep.com>
Co-authored-by: David Ashpole <dashpole@google.com>
Signed-off-by: Alex Boten <aboten@lightstep.com>
Signed-off-by: Alex Boten <aboten@lightstep.com>
@codeboten codeboten force-pushed the codeboten/prom-resource-labels branch from 9b765b1 to 0237d61 Compare November 29, 2023 23:48
Signed-off-by: Alex Boten <aboten@lightstep.com>
Copy link
Contributor

@MadVikingGod MadVikingGod left a comment

Choose a reason for hiding this comment

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

With there being minimal change to the no-filter path I think this is gtg.

There is a cost to add these attributes in the filter path. Adding a service.name filter I got these results:

benchstat bench-no-filter.txt bench-with-filter.txt
name             old time/op    new time/op    delta
Collect1-16        32.3µs ± 5%    33.4µs ± 3%   +3.45%  (p=0.002 n=10+10)
Collect10-16       93.2µs ± 3%   101.7µs ± 2%   +9.04%  (p=0.000 n=11+9)
Collect100-16       529µs ± 1%     613µs ± 4%  +15.95%  (p=0.000 n=9+10)
Collect1000-16     4.97ms ± 2%    5.64ms ± 5%  +13.63%  (p=0.000 n=11+10)
Collect10000-16    43.4ms ± 5%    50.3ms ± 7%  +15.83%  (p=0.000 n=11+9)

name             old alloc/op   new alloc/op   delta
Collect1-16        35.5kB ± 0%    35.8kB ± 0%   +0.74%  (p=0.000 n=11+10)
Collect10-16       48.4kB ± 0%    51.1kB ± 0%   +5.45%  (p=0.000 n=11+10)
Collect100-16       193kB ± 0%     219kB ± 0%  +13.70%  (p=0.000 n=11+10)
Collect1000-16     1.57MB ± 0%    1.83MB ± 0%  +16.85%  (p=0.000 n=10+10)
Collect10000-16    15.1MB ± 0%    17.8MB ± 0%  +17.57%  (p=0.000 n=11+10)

name             old allocs/op  new allocs/op  delta
Collect1-16          72.0 ± 0%      78.0 ± 0%   +8.33%  (p=0.000 n=11+10)
Collect10-16          407 ± 0%       467 ± 0%  +14.74%  (p=0.000 n=11+10)
Collect100-16       3.76k ± 0%     4.36k ± 0%  +15.97%  (p=0.000 n=11+10)
Collect1000-16      37.1k ± 0%     43.1k ± 0%  +16.16%  (p=0.000 n=11+10)
Collect10000-16      372k ± 0%      432k ± 0%  +16.20%  (p=0.000 n=11+10)

@dashpole
Copy link
Contributor

@MadVikingGod note that it is benchmarking only the first scrape of an endpoint (a single Collect for the exporter). Since the result is cached, it should have minimal impact on subsequent scrapes.

Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
Signed-off-by: Alex Boten <aboten@lightstep.com>
@MrAlias MrAlias merged commit 6027c1a into open-telemetry:main Dec 1, 2023
25 checks passed
@codeboten codeboten deleted the codeboten/prom-resource-labels branch December 1, 2023 17:39
@MrAlias MrAlias added this to the v1.22.0 milestone Jan 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Allow configuration of prometheus exporter to apply resource attributes as labels
4 participants