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

[DO NOT MERGE] Exporter should not be allowed to update MetricPoint in the AggregatorStore #2731

Conversation

utpilla
Copy link
Contributor

@utpilla utpilla commented Dec 7, 2021

The enumerator of Metric.GetMetricPoints() returns a reference to the MetricPoint in the MetricPoint[] used in the AggregatorStore. Since we return a reference to the MetricPoint, an exporter can set its value to default and thus change the original entry in the MetricPoint[]. This can clearly interfere with SDK's working.

Changes

  • Added a unit test to show that an exporter can update the MetricPoint of the MetricPoint[] of AggregatorStore

@utpilla utpilla requested a review from a team December 7, 2021 21:26
{
foreach (ref var metricPoint in metric.GetMetricPoints())
{
metricPoint = default;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is allowed as of today.

Copy link
Member

Choose a reason for hiding this comment

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

Bummer... good catch.

Copy link
Member

Choose a reason for hiding this comment

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

Good call @utpilla! If you change this line...

...to...

            public readonly ref MetricPoint Current

...does that fix it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah ref readonly should fix it. We would have to update the exporters though which should be fine.

{
foreach (var metric in batch)
{
if (invocationCount > 1)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not updating the MetricPoint the first time so that we can test that things were working correctly up until we updated the MetricPoint.


meterProvider.ForceFlush();

Assert.Single(exportedItems);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

At this point, ForceFlush() has called the Export method of the exporter and the exporter has updated the original MetricPoint to default.

@utpilla
Copy link
Contributor Author

utpilla commented Dec 9, 2021

I have created #2736 to fix this issue.

@utpilla utpilla closed this Dec 9, 2021
@utpilla utpilla deleted the utpilla/Update-MetricPoint-Exporter branch November 3, 2023 22:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants