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

Remove unwanted Arc insider PeriodicReader #2579

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions opentelemetry-sdk/src/metrics/periodic_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
let exporter_arc = Arc::new(exporter);
let reader = PeriodicReader {
inner: Arc::new(PeriodicReaderInner {
message_sender: Arc::new(message_sender),
message_sender,
producer: Mutex::new(None),
exporter: exporter_arc.clone(),
}),
Expand Down Expand Up @@ -294,7 +294,7 @@

struct PeriodicReaderInner {
exporter: Arc<dyn PushMetricExporter>,
message_sender: Arc<mpsc::Sender<Message>>,
message_sender: mpsc::Sender<Message>,
producer: Mutex<Option<Weak<dyn SdkProducer>>>,
}

Expand All @@ -320,15 +320,23 @@
}
}

fn collect_and_export(&self, _timeout: Duration) -> MetricResult<()> {
fn collect_and_export(&self, timeout: Duration) -> MetricResult<()> {
// TODO: Reuse the internal vectors. Or refactor to avoid needing any
// owned data structures to be passed to exporters.
let mut rm = ResourceMetrics {
resource: Resource::empty(),
scope_metrics: Vec::new(),
};

// Measure time taken for collect, and subtract it from the timeout.
let current_time = Instant::now();
let collect_result = self.collect(&mut rm);
let time_taken_for_collect = current_time.elapsed();
let _timeout = if time_taken_for_collect > timeout {
Duration::from_secs(0)

Check warning on line 336 in opentelemetry-sdk/src/metrics/periodic_reader.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-sdk/src/metrics/periodic_reader.rs#L336

Added line #L336 was not covered by tests
} else {
timeout - time_taken_for_collect
};
#[allow(clippy::question_mark)]
if let Err(e) = collect_result {
otel_warn!(
Expand All @@ -346,15 +354,10 @@
let metrics_count = rm.scope_metrics.iter().fold(0, |count, scope_metrics| {
count + scope_metrics.metrics.len()
});
otel_debug!(name: "PeriodicReaderMetricsCollected", count = metrics_count);
otel_debug!(name: "PeriodicReaderMetricsCollected", count = metrics_count, time_taken_in_millis = time_taken_for_collect.as_millis());

// TODO: subtract the time taken for collect from the timeout. collect
// involves observable callbacks too, which are user defined and can
// take arbitrary time.
//
// Relying on futures executor to execute async call.
// TODO: Add timeout and pass it to exporter or consider alternative
// design to enforce timeout here.
// TODO: Pass timeout to exporter
Copy link
Member

Choose a reason for hiding this comment

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

Nit

Suggested change
// TODO: Pass timeout to exporter
// TODO: Pass _timeout initialized above to exporter

let exporter_result = futures_executor::block_on(self.exporter.export(&mut rm));
#[allow(clippy::question_mark)]
if let Err(e) = exporter_result {
Expand Down