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

prometheus: Refactor getAttrs #5937

Merged
merged 2 commits into from
Nov 4, 2024

Conversation

pellared
Copy link
Member

@pellared pellared commented Oct 31, 2024

Addresses #5932 (comment)

I feel that getAttr was doing too much and having:

keys, values := getAttrs(dp.Attributes)
keys = append(keys, kv.keys...)
values = append(values, kv.vals...)
// ...
keys, values := getAttrs(*res.Set())

is more readable than:

keys, values := getAttrs(dp.Attributes, ks, vs, resourceKV)
// ...
keys, values := getAttrs(*res.Set(), [2]string{}, [2]string{}, keyVals{})

Benchmarks results just in case to minimize the possibility of accidental introduction of a performance overhead:

$ benchstat old.txt new.txt 
goos: linux
goarch: amd64
pkg: go.opentelemetry.io/otel/exporters/prometheus
cpu: Intel(R) Core(TM) i9-10885H CPU @ 2.40GHz
                │   old.txt    │               new.txt               │
                │    sec/op    │    sec/op     vs base               │
Collect1-16       29.77µ ± 11%   30.33µ ± 10%       ~ (p=0.529 n=10)
Collect10-16      80.58µ ±  7%   77.93µ ± 15%       ~ (p=0.315 n=10)
Collect100-16     528.5µ ±  7%   511.2µ ±  2%  -3.28% (p=0.015 n=10)
Collect1000-16    3.179m ±  6%   3.344m ± 15%  +5.19% (p=0.003 n=10)
Collect10000-16   31.77m ±  2%   33.14m ±  7%  +4.34% (p=0.004 n=10)
geomean           662.9µ         668.9µ        +0.90%

                │   old.txt    │               new.txt               │
                │     B/op     │     B/op      vs base               │
Collect1-16       36.52Ki ± 0%   36.59Ki ± 0%  +0.17% (p=0.000 n=10)
Collect10-16      64.58Ki ± 0%   64.64Ki ± 0%  +0.09% (p=0.000 n=10)
Collect100-16     349.3Ki ± 0%   349.4Ki ± 0%  +0.03% (p=0.000 n=10)
Collect1000-16    3.163Mi ± 0%   3.163Mi ± 0%       ~ (p=0.247 n=10)
Collect10000-16   31.05Mi ± 0%   31.06Mi ± 0%  +0.02% (p=0.009 n=10)
geomean           610.6Ki        611.0Ki       +0.06%

                │   old.txt   │              new.txt               │
                │  allocs/op  │  allocs/op   vs base               │
Collect1-16        70.00 ± 0%    72.00 ± 0%  +2.86% (p=0.000 n=10)
Collect10-16       396.0 ± 0%    398.0 ± 0%  +0.51% (p=0.000 n=10)
Collect100-16     3.661k ± 0%   3.663k ± 0%  +0.05% (p=0.000 n=10)
Collect1000-16    36.15k ± 0%   36.15k ± 0%  +0.01% (p=0.000 n=10)
Collect10000-16   361.4k ± 0%   361.5k ± 0%  +0.03% (p=0.009 n=10)
geomean           4.212k        4.241k       +0.68%

@pellared pellared added the Skip Changelog PRs that do not require a CHANGELOG.md entry label Oct 31, 2024
Copy link

codecov bot commented Oct 31, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.6%. Comparing base (7fd5942) to head (631cc0b).
Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##            main   #5937     +/-   ##
=======================================
- Coverage   84.6%   84.6%   -0.1%     
=======================================
  Files        272     272             
  Lines      22854   22858      +4     
=======================================
  Hits       19339   19339             
- Misses      3171    3175      +4     
  Partials     344     344             

see 2 files with indirect coverage changes

@pellared pellared marked this pull request as ready for review October 31, 2024 13:10
@pellared
Copy link
Member Author

@dashpole, PTAL

@pellared pellared merged commit 6e4c922 into open-telemetry:main Nov 4, 2024
31 of 32 checks passed
@pellared pellared deleted the prom-refactor-getattrs branch November 4, 2024 10:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Skip Changelog PRs that do not require a CHANGELOG.md entry
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants