-
Notifications
You must be signed in to change notification settings - Fork 516
Adding a dynamic dispatch to Aggregator Selector #497
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
Adding a dynamic dispatch to Aggregator Selector #497
Conversation
|
examples/basic-otlp/src/main.rs
Outdated
use std::sync::Arc; | ||
|
||
#[derive(Debug)] | ||
struct NOPAggregator(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style nits: this should be named NopAggregator
(maybe NoopAggregator
is even easier to understand for most readers?) and you should just leave off the ()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think we most used Noop[Component Name]
to name the no-op components.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think i will keep this example as is and add another example with a custom aggregator selector.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed altogether
examples/basic-otlp/src/main.rs
Outdated
use opentelemetry::metrics::Descriptor; | ||
use opentelemetry::sdk::export::metrics::Aggregator; | ||
use opentelemetry::sdk::export::metrics::AggregatorSelector; | ||
use std::sync::Arc; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe move this part to the top to keep the imports at the same place?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved to a different example and moved to the top
f23311c
to
2eb9af1
Compare
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM:+1: Thanks
…s://github.com/dawid-nowak/opentelemetry-rust into adding_dynamic_dispatch_to_aggregator_selector
opentelemetry-otlp/src/metric.rs
Outdated
ES: ExportKindFor + Send + Sync + Clone + 'static, | ||
SP: Fn(PushControllerWorker) -> SO, | ||
I: Fn(time::Duration) -> IO, | ||
{ | ||
aggregator_selector: AS, | ||
aggregator_selector: Box<dyn AggregatorSelector + Send + Sync + 'static>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are all these other box changes still needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so. I tried it before and was running into problems. If my understanding is correct if you remove Box::dyn then the compiler does static dispatch and turns T into a concrete type. So without dyns, it works in a situation where both opentelemetry_otlp::new_metrics_pipeline(tokio::spawn, delayed_interval)
and .with_aggregator_selector()
use the same type T.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you replace the method body with the full:
pub fn with_aggregator_selector<T>(
self,
aggregator_selector: T,
) -> OtlpMetricPipelineBuilder<T, ES, SP, SO, I, IO>
where
T: AggregatorSelector + Send + Sync + 'static,
{
OtlpMetricPipelineBuilder {
aggregator_selector,
export_selector: self.export_selector,
spawn: self.spawn,
interval: self.interval,
export_config: self.export_config,
tonic_config: self.tonic_config,
resource: self.resource,
stateful: self.stateful,
period: self.period,
timeout: self.timeout,
}
}
Then you don't need any other change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a feeling I am missing something here.
If I use the snippet from above I am getting compilation errors on both the main and this branch.
If I remove Box::dyns
I am pretty much back to the code that is currently on the main branch. In there the aggregator selector in new_metrics_pipeline
must be of the same type as in with_aggreagtor_selector
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i have removed more dyns from new_metrics_pipeline_with_selector
but i am not sure if i can remove the remaining ones
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something along the lines of 88b1904 should work
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jtescher I have missed that. The code is much simpler indeed, thanks. I have merged your suggestions, so hopefully, we are good now.
…s://github.com/dawid-nowak/opentelemetry-rust into adding_dynamic_dispatch_to_aggregator_selector
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thanks @dawid-nowak
Follow up on open-telemetry#497, which allows users to bring their own aggregator selector. Also updated the name of examples.
@TommyCpp
Have a look and let me know if something like this could work?
Rationale:
As a user, I would like to be able to supply my own aggregator selector so I can better control how data is aggregated.
If no aggregator is set by a user, sensible defaults are provided.