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

Small cleanup on MeterProvider #2172

Merged
merged 1 commit into from
Jul 21, 2021
Merged
Show file tree
Hide file tree
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
17 changes: 10 additions & 7 deletions src/OpenTelemetry/Metrics/MeterProviderSdk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ public class MeterProviderSdk

private readonly List<object> instrumentations = new List<object>();
private readonly object collectLock = new object();
private readonly CancellationTokenSource cts = new CancellationTokenSource();
private readonly List<Task> collectorTasks = new List<Task>();
private readonly MeterListener listener;
private readonly List<MeasurementProcessor> measurementProcessors = new List<MeasurementProcessor>();
private readonly List<MetricProcessor> metricProcessors = new List<MetricProcessor>();
Expand All @@ -46,6 +44,8 @@ internal MeterProviderSdk(
MetricProcessor[] metricProcessors)
{
this.Resource = resource;

// TODO: Replace with single CompositeProcessor.
this.measurementProcessors.AddRange(measurementProcessors);
this.metricProcessors.AddRange(metricProcessors);

Expand Down Expand Up @@ -142,14 +142,17 @@ protected override void Dispose(bool disposing)
this.instrumentations.Clear();
}

this.listener.Dispose();

this.cts.Cancel();
foreach (var processor in this.metricProcessors)
{
processor.Dispose();
}

foreach (var collectorTask in this.collectorTasks)
foreach (var processor in this.measurementProcessors)
{
collectorTask.Wait();
processor.Dispose();
}

this.listener.Dispose();
}

private MetricItem Collect(bool isDelta)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ protected override void Dispose(bool disposing)
{
this.token.Cancel();
this.exporter.Dispose();
this.exportTask.Wait();
Copy link
Member

Choose a reason for hiding this comment

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

Btw, do we see the real difference between push/pull metric processors? I personally don't (and I'm thinking maybe we should remove push/pull concept from the draft spec).

Copy link
Member Author

Choose a reason for hiding this comment

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

Not much, since the MeterProvider provided a way to "Collect". PushProcessor calls this Collect every N seconds. PullProcessor calls this Collect whenever its asked to.

}
catch (Exception)
{
Expand Down