-
Notifications
You must be signed in to change notification settings - Fork 773
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
Refactor MeterProvider to be similar to TracerProvider #2141
Refactor MeterProvider to be similar to TracerProvider #2141
Conversation
/// <returns><see cref="MeterProvider"/>.</returns> | ||
public static MeterProviderBuilder AddProcessor(this MeterProviderBuilder meterProviderBuilder, MeasurementProcessor processor) | ||
public static MeterProviderBuilder AddMeasurementProcessor(this MeterProviderBuilder meterProviderBuilder, MeasurementProcessor processor) |
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.
this might be removed from the spec. if that happens, we'll also remove here.
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 we need it, it might be SetMeasurementProcessor
since we don't allow multiple processors.
@@ -138,43 +127,21 @@ protected override void Dispose(bool disposing) | |||
} | |||
} | |||
|
|||
private async Task CollectorTask(CancellationToken token, int collectionPeriodMilliseconds, MetricProcessor[] processors) | |||
private MetricItem Collect() |
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.
MeterProvider has this method, but it never calls this. Its called by MetricProcessors, whenever they want. Typically in fixed time intervals (PushExporter) or in response to Scrape requests (PullExporter). Eitherway, MeterProvider doesn't care.
this.getMetrics = getMetrics; | ||
} | ||
|
||
public void PullRequest() |
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.
Method called in response to some scrap request.
@@ -28,73 +28,6 @@ public class MetricApiTest | |||
[Fact] | |||
public void SimpleTest() | |||
{ |
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 as this was not doing any Tests. Will be adding unit tests for all features in subsequent PRs.
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>(); |
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.
Inside the SDK it might make sense to have one single MetricProcessor, which can be a CompositeProcessor
(similar like what we did for log/trace). Not a blocker though.
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.
yes! that's the plan. Will orchestrate it in such a way that one processor read the state, and provides it to the next ones.. Needs some non-trivial change, so making it in coming PRs.
this.MeasurementProcessors.AddRange(measurementProcessors); | ||
|
||
this.ExportProcessors.AddRange(metricExportProcessors); | ||
foreach (var processor in this.metricProcessors) |
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.
Remember the linked list?
It might save the foreach heap allocation.
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.
yes. (this is at build time only, but yes will optimize)
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.
Codecov Report
@@ Coverage Diff @@
## metrics #2141 +/- ##
===========================================
- Coverage 83.66% 78.24% -5.43%
===========================================
Files 211 212 +1
Lines 6641 6632 -9
===========================================
- Hits 5556 5189 -367
- Misses 1085 1443 +358
|
namespace OpenTelemetry.Metrics | ||
{ | ||
public abstract class MetricProcessor : BaseProcessor<MetricItem> | ||
{ | ||
// GetMetric or GetMemoryState or GetAggregatedMetrics.. | ||
// ...or some other names | ||
public abstract void SetGetMetricFunction(Func<MetricItem> getMetrics); |
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 might not be thinking about things right, but would it make sense for a MetricProcessor to have a handle on the ParentProvider kinda like how we do for traces? That way instead of calling SetGetMetricFunction(this.Collect)
in the MeterProviderSdk you'd have a handle on the provider to call Collect
directly.
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 like this idea. Will explore more on and try it in the subsequent PRs.
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.
These are some great improvements!
Changes
Sorry about the long list of changes in single PR! All of this was interconnected, and I felt it was not worth the effort to split them. After this refactor, hoping to get very localized changes only :)