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

feat: Hide MetricReader and friends #2928

Merged

Conversation

cijothomas
Copy link
Member

@cijothomas cijothomas commented Apr 11, 2025

Option2 from #2917

Trimming public API, by hiding MetricReader+friends under feature flag. This won't affect normal usage of Metrics, but only custom MetricReader authors. It is unclear what scenario requires custom MetricReaders.....
Ability to write custom Exporter is still maintained.
Also removed Aggregation enum to existing View feature, as that was the only use for Aggregation.

Hoping to trim the questionable public API before declaring Metrics SDK as stable.

@cijothomas cijothomas requested a review from a team as a code owner April 11, 2025 02:39
Copy link

codecov bot commented Apr 11, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.3%. Comparing base (64cf291) to head (76cb13d).
Report is 1 commits behind head on main.

Additional details and impacted files
@@          Coverage Diff          @@
##            main   #2928   +/-   ##
=====================================
  Coverage   81.3%   81.3%           
=====================================
  Files        126     126           
  Lines      24254   24254           
=====================================
  Hits       19736   19736           
  Misses      4518    4518           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@cijothomas cijothomas changed the title Hide MetricReader feat: Hide MetricReader Apr 11, 2025
@fraillt
Copy link
Contributor

fraillt commented Apr 11, 2025

I have looked a bit deeper into this and here's my understanding (maybe not correct :)) about the situation.
If we ignore code for a bit and look philosophically, the purpose of Metrics SDK is to allow a user to specify how and when metrics should be exported.
How - is solved by PushMetricExporter.
When - is solved by MetricReader.
The how part is done nicely: it has export, temporality and few more to deal with technical stuff ("flush" and "shutdown").
The when part looks a bit more complex (for my taste at least) than it should be.
Ideally, user should accept some sort of CollectTrigger instance and provide implementation which would call fn collect(&mut self) either in the loop (for PeriodicReader) or some other way (e.g. pull based reader for Prometheus).

So if we could achieve something similar in #2917 , then probably we could stabilize this in Metrics SDK :)

P.S. maybe we should think about naming for PushMetricExporter and MetricReader interfaces before stabilization as well?
I would suggest to rename PushMetricExporter to MetricExporter (because Push part is actually controlled by collector), and would rename MetricReader to MetricCollector.

@cijothomas
Copy link
Member Author

I have looked a bit deeper into this and here's my understanding (maybe not correct :)) about the situation. If we ignore code for a bit and look philosophically, the purpose of Metrics SDK is to allow a user to specify how and when metrics should be exported. How - is solved by PushMetricExporter. When - is solved by MetricReader. The how part is done nicely: it has export, temporality and few more to deal with technical stuff ("flush" and "shutdown"). The when part looks a bit more complex (for my taste at least) than it should be. Ideally, user should accept some sort of CollectTrigger instance and provide implementation which would call fn collect(&mut self) either in the loop (for PeriodicReader) or some other way (e.g. pull based reader for Prometheus).

Yes, Users should be in control of export interval - #2928 (comment)
i.e, they can control how often collect/export should get triggered automatically.
Additionally, users can trigger export/collect ad-hoc too, by invoking meter_provider.flush() themselves.
Most users don't need to even know that there is a thing/concept called MetricReader at all.

@cijothomas
Copy link
Member Author

I would suggest to rename PushMetricExporter to MetricExporter (because Push part is actually controlled by collector), and would rename MetricReader to MetricCollector.

Agree with removing "Push" from MetricExporter.
The other one - not so sure. Spec calls it MetricReader. But Reader is being proposed to be hidden from end-users via feature flag in this PR, so we can alter it later too.

@cijothomas cijothomas changed the title feat: Hide MetricReader feat: Hide MetricReader and friends Apr 11, 2025
- *Breaking* `MetricError`, `MetricResult` no longer public (except when
`spec_unstable_metrics_views` feature flag is enabled). `OTelSdkResult` should
be used instead, wherever applicable.
- *Breaking* change, affecting custom MetricReader authors: The
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
- *Breaking* change, affecting custom MetricReader authors: The
- *Breaking* change, affecting custom `MetricReader` authors: The

- *Breaking* change, affecting custom MetricReader authors: The
`shutdown_with_timeout` method is added to `MetricReader` trait. `collect`
method on `MetricReader` modified to return `OTelSdkResult`.
[#2905](https://github.com/open-telemetry/opentelemetry-rust/pull/2905)
Copy link
Contributor

Choose a reason for hiding this comment

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

This PR link is added twice.

pub(crate) mod aggregation;
pub mod data;
mod error;
pub mod exporter;
pub(crate) mod instrument;
pub(crate) mod internal;
#[cfg(feature = "experimental_metrics_custom_reader")]
pub(crate) mod manual_reader;
Copy link
Contributor

Choose a reason for hiding this comment

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

We should probably just delete manual_reader.rs file instead of providing it under a feature. There doesn't seem to be any use case for it.

Copy link
Contributor

@utpilla utpilla left a comment

Choose a reason for hiding this comment

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

Left some suggestions.

@cijothomas cijothomas merged commit 4ce7655 into open-telemetry:main Apr 11, 2025
27 checks passed
@cijothomas cijothomas deleted the cijothomas/metricreader-hide branch April 11, 2025 23:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants