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 exemplars to the metric SDK as an experimental feature #4455

Closed
wants to merge 28 commits into from

Conversation

MrAlias
Copy link
Contributor

@MrAlias MrAlias commented Aug 17, 2023

No description provided.

@MrAlias MrAlias added pkg:SDK Related to an SDK package area:metrics Part of OpenTelemetry Metrics labels Aug 17, 2023
@codecov
Copy link

codecov bot commented Aug 17, 2023

Codecov Report

Attention: 53 lines in your changes are missing coverage. Please review.

Comparison is base (33f5cf4) 82.3% compared to head (4460389) 82.3%.

❗ Current head 4460389 differs from pull request most recent head bb1c495. Consider uploading reports for the commit bb1c495 to get more accurate results

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##            main   #4455     +/-   ##
=======================================
- Coverage   82.3%   82.3%   -0.1%     
=======================================
  Files        226     232      +6     
  Lines      18481   18710    +229     
=======================================
+ Hits       15224   15400    +176     
- Misses      2971    3023     +52     
- Partials     286     287      +1     
Files Coverage Δ
...metric/internal/aggregate/exponential_histogram.go 96.3% <100.0%> (+0.1%) ⬆️
sdk/metric/internal/aggregate/histogram.go 100.0% <100.0%> (ø)
sdk/metric/internal/aggregate/lastvalue.go 100.0% <100.0%> (ø)
sdk/metric/internal/aggregate/sum.go 100.0% <100.0%> (ø)
sdk/metric/internal/exemplar/drop.go 100.0% <100.0%> (ø)
sdk/metric/internal/exemplar/filter.go 100.0% <100.0%> (ø)
sdk/metric/internal/exemplar/fixed.go 100.0% <100.0%> (ø)
sdk/metric/internal/exemplar/hist.go 100.0% <100.0%> (ø)
sdk/metric/internal/exemplar/rand.go 100.0% <100.0%> (ø)
sdk/metric/pipeline.go 86.4% <100.0%> (+<0.1%) ⬆️
... and 2 more


// TODO: This is not defined by the specification, nor is the mechanism to
// configure it.
const defaultFixedSize = 1

Choose a reason for hiding this comment

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

FYI - I'm planning to update the specification here witha MAY. 1 is the fallback default, but we found in Java that a simple optimisation is to set this = the number of available CPUs for the runtime (if that's easy to grab). It can dramatically reduce contention on writing exemplars in extreme cases for not a huge investment of memory.

I'm not sure if Go suffers from the same contention issues, but might be worth benchmarking.

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, that's interesting. I need to look into it.

My guess is this would also benefit in using that value (which is pretty accessible).

}

// https://github.com/open-telemetry/opentelemetry-specification/blob/d4b241f451674e8f611bb589477680341006ad2b/specification/configuration/sdk-environment-variables.md#exemplar
const filterEnvKey = "OTEL_METRICS_EXEMPLAR_FILTER"
Copy link

@jsuereth jsuereth Nov 10, 2023

Choose a reason for hiding this comment

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

FYI - #2421 - I think we're going to recommend that the filter is a configuration setting on the SDK (likely meter provider).

IIUC the architecture, this would still be feasible in Go?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That makes sense to me, but we will have to wait for exemplars to become stable to add it to the stable API interface of the SDK.

I was talking with @dashpole and I was also wondering if we even need exemplar filters to start here. Might be something to consider at the spec level.

Choose a reason for hiding this comment

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

open-telemetry/opentelemetry-specification#3820 <- The interface no longer needs to be exposed to users, but the configuration needs to be SDK-wide.

@MrAlias

This comment was marked as outdated.

@MrAlias
Copy link
Contributor Author

MrAlias commented Dec 18, 2023

Waiting on #3011. That change will influence the design of the exemplar reservoir interface. If it is accepted, the current design should be used. But, if it is not implemented, there is an optimization to be made given the dropped attributes are calculated during each measurement. It is anticipated to be accepted.

@MrAlias
Copy link
Contributor Author

MrAlias commented Jan 17, 2024

It looks like recording dropped attributes during Offer instead of recreating during collection has some performance gains (old.txt: 623ed1b, new.txt: 6a94b22):

$ benchstat old.txt new.txt
goos: linux
goarch: amd64
pkg: go.opentelemetry.io/otel/sdk/metric
cpu: Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
                             │   old.txt   │              new.txt               │
                             │   sec/op    │   sec/op     vs base               │
Exemplars/Int64Counter/8-8     15.20µ ± 2%   13.87µ ± 4%  -8.76% (p=0.000 n=10)
Exemplars/Int64Histogram/8-8   12.35µ ± 3%   11.90µ ± 1%  -3.66% (p=0.000 n=10)
geomean                        13.70µ        12.85µ       -6.24%

                             │   old.txt    │                new.txt                │
                             │     B/op     │     B/op      vs base                 │
Exemplars/Int64Counter/8-8     3.789Ki ± 0%   3.789Ki ± 0%       ~ (p=1.000 n=10) ¹
Exemplars/Int64Histogram/8-8   3.875Ki ± 0%   3.875Ki ± 0%       ~ (p=1.000 n=10) ¹
geomean                        3.832Ki        3.832Ki       +0.00%
¹ all samples are equal

                             │  old.txt   │               new.txt               │
                             │ allocs/op  │ allocs/op   vs base                 │
Exemplars/Int64Counter/8-8     84.00 ± 0%   84.00 ± 0%       ~ (p=1.000 n=10) ¹
Exemplars/Int64Histogram/8-8   72.00 ± 0%   72.00 ± 0%       ~ (p=1.000 n=10) ¹
geomean                        77.77        77.77       +0.00%
¹ all samples are equal

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:metrics Part of OpenTelemetry Metrics pkg:SDK Related to an SDK package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants