-
Notifications
You must be signed in to change notification settings - Fork 887
Add support for multiple readers #2596
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
Changes from 6 commits
0b66c01
1a70f55
c6234f6
22004e6
c217a3a
93011e6
6dc3bae
9fb5b7d
da3b955
b5be41b
f428307
b5e568c
3b9fc45
901bbe4
bd61f39
c8d5edf
3b17872
a2bc28f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ | |
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Diagnostics; | ||
| using System.Diagnostics.Metrics; | ||
| using System.Threading; | ||
| using OpenTelemetry.Internal; | ||
|
|
||
|
|
@@ -27,6 +28,7 @@ internal sealed class CompositeMetricReader : MetricReader | |
| private readonly DoublyLinkedListNode head; | ||
| private DoublyLinkedListNode tail; | ||
| private bool disposed; | ||
| private int count; | ||
|
|
||
| public CompositeMetricReader(IEnumerable<MetricReader> readers) | ||
| { | ||
|
|
@@ -40,6 +42,7 @@ public CompositeMetricReader(IEnumerable<MetricReader> readers) | |
|
|
||
| this.head = new DoublyLinkedListNode(iter.Current); | ||
| this.tail = this.head; | ||
| this.count++; | ||
|
|
||
| while (iter.MoveNext()) | ||
| { | ||
|
|
@@ -57,12 +60,117 @@ public CompositeMetricReader AddReader(MetricReader reader) | |
| }; | ||
| this.tail.Next = node; | ||
| this.tail = node; | ||
| this.count++; | ||
|
|
||
| return this; | ||
| } | ||
|
|
||
| public Enumerator GetEnumerator() => new Enumerator(this.head); | ||
|
|
||
| internal List<Metric> AddMetricsWithNoViews(Instrument instrument) | ||
| { | ||
| var metrics = new List<Metric>(); | ||
| for (var cur = this.head; cur != null; cur = cur.Next) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't expect this method to throw any exceptions, right?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| { | ||
| var metric = cur.Value.AddMetricWithNoViews(instrument); | ||
| metrics.Add(metric); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add only if notnull
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm adding In future, if we allow readers to have their own |
||
| } | ||
|
|
||
| return metrics; | ||
| } | ||
|
|
||
| internal void RecordSingleStreamLongMeasurements(List<Metric> metrics, long value, ReadOnlySpan<KeyValuePair<string, object>> tags) | ||
| { | ||
| Debug.Assert(metrics.Count == this.count, "The count of metrics to be updated for a CompositeReader must match the number of individual readers."); | ||
|
|
||
| int index = 0; | ||
| for (var cur = this.head; cur != null; cur = cur.Next) | ||
| { | ||
| if (metrics[index] != null) | ||
| { | ||
| cur.Value.RecordSingleStreamLongMeasurement(metrics[index], value, tags); | ||
| } | ||
|
|
||
| index++; | ||
| } | ||
| } | ||
|
|
||
| internal void RecordSingleStreamDoubleMeasurements(List<Metric> metrics, double value, ReadOnlySpan<KeyValuePair<string, object>> tags) | ||
| { | ||
| Debug.Assert(metrics.Count == this.count, "The count of metrics to be updated for a CompositeReader must match the number of individual readers."); | ||
|
|
||
| int index = 0; | ||
| for (var cur = this.head; cur != null; cur = cur.Next) | ||
| { | ||
| if (metrics[index] != null) | ||
| { | ||
| cur.Value.RecordSingleStreamDoubleMeasurement(metrics[index], value, tags); | ||
| } | ||
|
|
||
| index++; | ||
| } | ||
| } | ||
|
|
||
| internal List<List<Metric>> AddMetricsSuperListWithViews(Instrument instrument, List<MetricStreamConfiguration> metricStreamConfigs) | ||
| { | ||
| var metricsSuperList = new List<List<Metric>>(); | ||
| for (var cur = this.head; cur != null; cur = cur.Next) | ||
| { | ||
| var metrics = cur.Value.AddMetricsListWithViews(instrument, metricStreamConfigs); | ||
| metricsSuperList.Add(metrics); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. only add if the metric.Count > 0
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as #2596 (comment) |
||
| } | ||
|
|
||
| return metricsSuperList; | ||
| } | ||
|
|
||
| internal void RecordLongMeasurements(List<List<Metric>> metricsSuperList, long value, ReadOnlySpan<KeyValuePair<string, object>> tags) | ||
| { | ||
| Debug.Assert(metricsSuperList.Count == this.count, "The count of metrics to be updated for a CompositeReader must match the number of individual readers."); | ||
|
|
||
| int index = 0; | ||
| for (var cur = this.head; cur != null; cur = cur.Next) | ||
| { | ||
| if (metricsSuperList[index].Count > 0) | ||
| { | ||
| cur.Value.RecordLongMeasurement(metricsSuperList[index], value, tags); | ||
| } | ||
|
|
||
| index++; | ||
| } | ||
| } | ||
|
|
||
| internal void RecordDoubleMeasurements(List<List<Metric>> metricsSuperList, double value, ReadOnlySpan<KeyValuePair<string, object>> tags) | ||
| { | ||
| Debug.Assert(metricsSuperList.Count == this.count, "The count of metrics to be updated for a CompositeReader must match the number of individual readers."); | ||
|
|
||
| int index = 0; | ||
| for (var cur = this.head; cur != null; cur = cur.Next) | ||
| { | ||
| if (metricsSuperList[index].Count > 0) | ||
| { | ||
| cur.Value.RecordDoubleMeasurement(metricsSuperList[index], value, tags); | ||
| } | ||
|
|
||
| index++; | ||
| } | ||
| } | ||
|
|
||
| internal void CompleteSingleStreamMeasurements(List<Metric> metrics) | ||
|
utpilla marked this conversation as resolved.
Outdated
|
||
| { | ||
| Debug.Assert(metrics.Count == this.count, "The count of metrics to be updated for a CompositeReader must match the number of individual readers."); | ||
|
|
||
| int index = 0; | ||
| for (var cur = this.head; cur != null; cur = cur.Next) | ||
| { | ||
| if (metrics[index] != null) | ||
| { | ||
| cur.Value.CompleteSingleStreamMeasurement(metrics[index]); | ||
| } | ||
|
|
||
| index++; | ||
| } | ||
| } | ||
|
|
||
| /// <inheritdoc/> | ||
| protected override bool ProcessMetrics(in Batch<Metric> metrics, int timeoutMilliseconds) | ||
| { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.