Unify metric SDK caching #3245
Labels
area:metrics
Part of OpenTelemetry Metrics
bug
Something isn't working
enhancement
New feature or request
pkg:SDK
Related to an SDK package
Milestone
Currently, the only place caching is used is the
meterRegistry
.There are currently two reported bugs (#3229 and #3240) that would be resolved by adding caching to instrument aggregation determination. If done correctly the same request for compatible instruments would return the same
Aggregator
instance and conflicting, but resolvable, instruments would also get the same instance.Finally, there is an optimization opportunity at the instrument provider level to cache returned instruments. Adding a cache at this level would prevent duplicate resolutions of aggregations.
Propoasal
A proof-of-concept with all three caching situations can be found here: https://github.com/MrAlias/opentelemetry-go/pull/662/files
The proposed approach is to add a unified
cache
type that handles synchronized lookup in amap
:This type can be wrapped to provide convenient lookup of aggregator caching: https://github.com/MrAlias/opentelemetry-go/blob/0d925dcfc651811318155a16bcc59c615ff119cf/sdk/metric/cache.go#L71-L147
Or it can be used to directly cache meter or instrument values.
The plan is to break this work into 3 PRs:
cache
type and cache instrument aggregators: Handle duplicate Aggregators and log instrument conflicts #3251meterRegistry
with thecache
type: Replace meterRegistry with cache #3255The text was updated successfully, but these errors were encountered: