-
Notifications
You must be signed in to change notification settings - Fork 801
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
[PoC] Mitigation for InMemoryExporter + Metrics (for discussion) #2907
Conversation
src/OpenTelemetry/Metrics/Metric.cs
Outdated
@@ -128,7 +128,10 @@ public sealed class Metric | |||
|
|||
public MetricPointsAccessor GetMetricPoints() |
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 cannot update this method as this would be used by all other exporters for best performance.
We need to add a new method GetClonedMetricPoints
which should call this.aggStore.GetClonedMetricPoints
. The user of InMemoryExporter
has to be aware of this method and call GetClonedMetricPoints
instead of GetMetricPoints
:
foreach (var metric in batch)
{
foreach (ref readonly var metricPoint in metric.GetCloneMetricPoints())
{
...
...
...
}
}
@@ -28,7 +28,8 @@ public struct MetricPoint | |||
{ | |||
private readonly AggregationType aggType; | |||
|
|||
private readonly HistogramBuckets histogramBuckets; | |||
// Note: Removing "readonly" enables DeepCopy using the MemberwiseClone pattern below. | |||
private HistogramBuckets histogramBuckets; |
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 only need to deep copy HistogramBuckets.SnapshotBucketCounts
.
Codecov Report
@@ Coverage Diff @@
## main #2907 +/- ##
==========================================
- Coverage 84.22% 83.89% -0.34%
==========================================
Files 251 253 +2
Lines 8883 8922 +39
==========================================
+ Hits 7482 7485 +3
- Misses 1401 1437 +36
|
// Need to discuss if this is an acceptible change. | ||
if (this.isMetric) | ||
{ | ||
this.exportedItems.Clear(); |
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.
Let's first decide on this. Do we want the collection of exported items to hold the MetricPoint
state corresponding to every export made so far?
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.
Personally, I feel like... no, it shouldn't auto-clear anything. Whoever constructed the InMemoryExporter
owns the collection that was passed in. So they can clear it if needed based on whatever test is being modeled? But yes the exporter should move copies into that collection so the data doesn't continue to change.
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.
Hi @CodeBlanch,
If the InMemoryExporter could deepcopy the Metric
into the export collection, I believe that would fully address this issue.
However, I don't see an obvious way to accomplish this.
I listed here several methods to perform a deepcopy and the blocking issues with each.
If you have any other ideas, I'm eager to get your input!
This is an alternative to DeepCopying the
Metric
.Discussing this in #2361.
Changes
MetricPoint
. This includes minor changes toMetricPoint
andHistogramBuckets
.Metric.GetMetricPoints
changed to always return a deepcopy.This change passes all unit tests locally.
Need to discuss if this change is acceptable.
InMemoryExporter
to clear theexportedItems
collection when exportingMetric
.This mitigates the issue with growing the collection with copies of the same
Metric
.Need to discuss if this change is acceptable.
For significant contributions please make sure you have completed the following items:
CHANGELOG.md
updated for non-trivial changes