-
Notifications
You must be signed in to change notification settings - Fork 790
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
Add support for multiple readers #2596
Add support for multiple readers #2596
Conversation
Codecov Report
@@ Coverage Diff @@
## main #2596 +/- ##
==========================================
+ Coverage 80.97% 81.33% +0.35%
==========================================
Files 243 245 +2
Lines 8547 8614 +67
==========================================
+ Hits 6921 7006 +85
+ Misses 1626 1608 -18
|
Is there a benchmark result? |
// * Summary * BenchmarkDotNet=v0.13.1, OS=Windows 10.0.19043.1348 (21H1/May2021Update) MetricsBenchmarks original:
MetricsBenchmarks with this PR:
MetricCollectBenchmarks original:
MetricCollectBenchmarks with this PR:
MetricViewBenchmarks original:
MetricViewBenchmarks with this PR:
The numbers are significantly low for MetricViewBenchmarks as the benchmark code does not have any reader. With this PR, we do not enable measurements if there is no reader added to the |
f137aba
to
f428307
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 with some suggestions (doesn't have to block this PR).
// TODO: Revisit to see if we need to do metrics.TrimExcess() | ||
var metrics = new List<Metric>(maxCountMetricsToBeCreated); | ||
lock (this.instrumentCreationLock) | ||
if (this.reader != null) |
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.
Is this.reader == null
a valid case? Thinking maybe ctor should throw in that case so we don't need to check it.
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 it's fine. Similar discussion here #2476.
for (var cur = this.head; cur != null; cur = cur.Next) | ||
{ | ||
var metric = cur.Value.AddMetricWithNoViews(instrument); | ||
metrics.Add(metric); |
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.
add only if notnull
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.
and in the provider, you can check the list.Count > 0 before enable measurement event is called.
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'm adding null
to preserve the order in which we process the metrics when we have multiple readers. CompositeMetricReader
checks for null
before calling the reader to update the value.
In future, if we allow readers to have their own MaxMetrics
limit, this would still work as we will know which readers need to update the value and which don't.
internal List<Metric> AddMetricsWithNoViews(Instrument instrument) | ||
{ | ||
var metrics = new List<Metric>(); | ||
for (var cur = this.head; cur != null; cur = cur.Next) |
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.
for a followup/todo - see if we need to catch exceptions from individual readers, so that anyone of them throwing won't affect the others.
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.
We don't expect this method to throw any exceptions, right?
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.
not sure. As a general principle, one reader's bad behaviour shouldn't affect other readers
Debug.Assert(instrument != null, "instrument must be non-null."); | ||
if (metric == null) | ||
|
||
if (this.compositeMetricReader == null) |
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.
the name of the method no longer makes sense as it handles single stream(Metric) and multiple (List).
We should make 3 separate methods for Metric, List of Metic, List of (list of metric). Might save all the if-checks in hot path.
Good for a follow up to avoid making this PR bigger.
for (var cur = this.head; cur != null; cur = cur.Next) | ||
{ | ||
var metrics = cur.Value.AddMetricsListWithViews(instrument, metricStreamConfigs); | ||
metricsSuperList.Add(metrics); |
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.
only add if the metric.Count > 0
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.
Same as #2596 (comment)
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.
Overall looks good. Left few comments.
Will do another round of review later today before merge
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.
merging to make progress and pave way for others PR, potentially with merge conflicts!. Have few non-blocking items for follow up.
…hub.com/utpilla/opentelemetry-dotnet into utpilla/Add-Support-For-MultipleReaders
Fixes #2398
Changes
Please provide a brief description of the changes here.
For significant contributions please make sure you have completed the following items:
CHANGELOG.md
updated for non-trivial changes