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

Merge instrument cache to inserter #3724

Merged
merged 8 commits into from
Feb 21, 2023
Merged

Conversation

MrAlias
Copy link
Contributor

@MrAlias MrAlias commented Feb 14, 2023

The current pipeline resolution path will only add the resolved aggregator to the pipeline when it creates one (cache miss). It will not add it if there is a cache hit. This means (since we cache instrument at the meter level, not the pipeline level) the first reader in a multiple-reader setup is the only one that will collect data for that aggregator. All other readers will have a cache hit and nothing is added to the pipeline. This is causing #3720.

This resolves #3720 by moving the instrument caching into the inserter. This means aggregators are cached at the reader level, not the meter.

@MrAlias MrAlias force-pushed the inst-cache branch 3 times, most recently from 47cfeb4 to 71a7bfb Compare February 14, 2023 18:22
@MrAlias MrAlias changed the title WIP of instrument caching Make addSync idempotent Feb 14, 2023
@MrAlias MrAlias added bug Something isn't working pkg:SDK Related to an SDK package area:metrics Part of OpenTelemetry Metrics labels Feb 14, 2023
@MrAlias MrAlias added this to the Metric v0.37.0 milestone Feb 14, 2023
@codecov
Copy link

codecov bot commented Feb 14, 2023

Codecov Report

Merging #3724 (4daba94) into main (cc8bdaa) will decrease coverage by 0.1%.
The diff coverage is 81.8%.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##            main   #3724     +/-   ##
=======================================
- Coverage   81.6%   81.6%   -0.1%     
=======================================
  Files        166     166             
  Lines      12445   12431     -14     
=======================================
- Hits       10165   10148     -17     
- Misses      2065    2067      +2     
- Partials     215     216      +1     
Impacted Files Coverage Δ
sdk/metric/cache.go 100.0% <ø> (ø)
sdk/metric/pipeline.go 90.5% <77.7%> (-0.8%) ⬇️
sdk/metric/meter.go 89.5% <100.0%> (-0.3%) ⬇️
sdk/trace/batch_span_processor.go 81.1% <0.0%> (-0.9%) ⬇️
sdk/metric/periodic_reader.go 91.6% <0.0%> (+1.1%) ⬆️

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Feb 15, 2023

CLA Signed

The committers listed above are authorized under a signed CLA.

@MrAlias

This comment was marked as outdated.

@MrAlias MrAlias changed the title Make addSync idempotent Move instrument cache to insterter Feb 15, 2023
@MrAlias MrAlias changed the title Move instrument cache to insterter Merge instrument cache to insterter Feb 15, 2023
The current pipeline resolution path will only add the resolved
aggregators to the pipeline when it creates one (cache miss). It will
not add it if there is a cache hit. This means (since we cache
instruments at the meter level, not the pipeline level) the first reader
in a multiple-reader setup is the only one that will collect data for
that aggregator. All other readers will have a cache hit and nothing is
added to the pipeline. This is causing open-telemetry#3720.

This resolves open-telemetry#3720 by moving the instrument caching into the inserter.
This means aggregators are cached at the reader level, not the meter.
@MrAlias MrAlias changed the title Merge instrument cache to insterter Merge instrument cache to inserter Feb 15, 2023
@MrAlias MrAlias marked this pull request as ready for review February 15, 2023 18:08
Copy link
Contributor

@dashpole dashpole left a comment

Choose a reason for hiding this comment

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

IIUC, we currently have something like:

Meter > Reader (pipeline) > Instrument > Aggregation

The downside seems to be that two readers that want identical data will duplicate all of the aggregations. I wonder if, in the future it would a good idea to switch to:

Meter > Instrument > Aggregation > Reader (pipeline)

So that identical aggregations would be shared by readers. But I'm not entirely sure that will work, and suspect it would require a large refactor to implement.

sdk/metric/pipeline.go Outdated Show resolved Hide resolved
@MrAlias
Copy link
Contributor Author

MrAlias commented Feb 17, 2023

The downside seems to be that two readers that want identical data will duplicate all of the aggregations. I wonder if, in the future it would a good idea to switch ...

So that identical aggregations would be shared by readers. But I'm not entirely sure that will work, and suspect it would require a large refactor to implement.

True the data is going to be duplicated in memory. We did this because each reader needs to have an unaffected aggregation, when one reader collects it cannot affect the data another reader would collect. Also, when we made this choice views were tied to the reader not the meter provider.

There does seem to be an optimization for when multiple readers use cumulative temporarily and the same aggregation selectors, but state would still need to be held if delta temporality is used by a reader.

Given how long it took for #3720 to be reported, I don't expect there to be many situations using multiple readers. Which makes me think that optimization isn't too high of a priority.

@liufuyang
Copy link

So maybe can we merge this soon? Looking forward to the next release which brings a fix of the memory issue :)

@MrAlias MrAlias merged commit f78f72d into open-telemetry:main Feb 21, 2023
@MrAlias MrAlias deleted the inst-cache branch February 21, 2023 16:07
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 bug Something isn't working pkg:SDK Related to an SDK package
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Meter provider don't work with multiple readers
4 participants