Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
prometheus: Refactor getAttrs (#5937)
Addresses #5932 (comment) I feel that `getAttr` was doing too much and having: ```go keys, values := getAttrs(dp.Attributes) keys = append(keys, kv.keys...) values = append(values, kv.vals...) // ... keys, values := getAttrs(*res.Set()) ``` is more readable than: ```go 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% ```
- Loading branch information