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

Allow ability to override max Metric streams and MetricPoints per stream #2635

Merged

Conversation

cijothomas
Copy link
Member

@cijothomas cijothomas commented Nov 17, 2021

Fixes #2358
This allows user to specify a max limit of number of Metric streams. This is to prevent indefinite memory growth, if a user keeps creating new instruments, instead of reusing for each measurement.

This also allows user to specify a max limit of the number of MetricPoints, per metric stream. This is to prevent indefinite memory usage growth, when high cardinality values are uses in metric tags. This limit is applied independently to every metric stream for this meter provider. In the future, we could add ability to configure separate MaxMetricPoint limit per instrument, by leveraging Views, which can override the MeterProvider level limits.

Note that, in the current implementation, MetricPoints are pre-allocated upto max limit when an instrument is created. So user pays upfront memory cost for MaxMetricPoints even though only subset of them is used. In the future, when per-instrument config is allowed, users can tune this number to reduce wastage.

Also as this, is not addressed, there is no ability to "reclaim" a MetricPoint if it has been inactive for some time.

TODO:
Public API
Unit Tests
Decide if the defaults 1000, 2000 are good enough.

@cijothomas cijothomas requested a review from a team November 17, 2021 22:12
@cijothomas cijothomas changed the title Allow ability to override max Metric stream and MetricPoints per stream Allow ability to override max Metric streams and MetricPoints per stream Nov 17, 2021
this.metricPoints = new MetricPoint[MaxMetricPoints];
this.currentMetricPointBatch = new int[MaxMetricPoints];
this.metricPointLimit = metricPointLimit;
this.metricPoints = new MetricPoint[metricPointLimit];
Copy link
Member Author

Choose a reason for hiding this comment

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

I think metricPoinLimit+1 should be used, as we reserve one point for zero dimension case.

Copy link
Contributor

Choose a reason for hiding this comment

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

Would it not be misleading for the user if we add +1 here? Maybe we could update the remarks for the public method SetMetricPointPerMetricStreamLimit in that case?

Copy link
Member

@reyang reyang Nov 18, 2021

Choose a reason for hiding this comment

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

I think metricPoinLimit+1 should be used, as we reserve one point for zero dimension case.

That doesn't seem to be mathematically correct? (I guess we should throw if the provided value is 0).

Copy link
Contributor

Choose a reason for hiding this comment

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

We would throw if the provided value is less than 1 as the method validates the input:
Guard.Range(metricPointLimit, min: 1);

I think what could be confusing is that the user provides a value thinking that it will be maximum number of time-series allowed but internally we would be allowing an additional time-series.

Copy link
Member

Choose a reason for hiding this comment

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

Should we consider doing away with the reservation of the zero dimension case? I guess I don't know the history of why we do it.

@codecov
Copy link

codecov bot commented Nov 17, 2021

Codecov Report

Merging #2635 (aa0d210) into main (ca29142) will decrease coverage by 0.06%.
The diff coverage is 72.72%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2635      +/-   ##
==========================================
- Coverage   81.37%   81.31%   -0.07%     
==========================================
  Files         245      245              
  Lines        8614     8645      +31     
==========================================
+ Hits         7010     7030      +20     
- Misses       1604     1615      +11     
Impacted Files Coverage Δ
...elemetry/Metrics/MeterProviderBuilderExtensions.cs 69.23% <0.00%> (-12.59%) ⬇️
.../OpenTelemetry/Metrics/MeterProviderBuilderBase.cs 88.23% <40.00%> (-11.77%) ⬇️
src/OpenTelemetry/Metrics/AggregatorStore.cs 86.98% <100.00%> (+0.18%) ⬆️
src/OpenTelemetry/Metrics/MeterProviderSdk.cs 89.42% <100.00%> (+0.18%) ⬆️
src/OpenTelemetry/Metrics/Metric.cs 95.83% <100.00%> (+0.05%) ⬆️
src/OpenTelemetry/Metrics/MetricReaderExt.cs 90.42% <100.00%> (+0.77%) ⬆️
src/OpenTelemetry/Metrics/MetricReader.cs 87.83% <0.00%> (+0.16%) ⬆️
...ZPages/Implementation/ZPagesExporterEventSource.cs 62.50% <0.00%> (+6.25%) ⬆️

}

/// <summary>
/// Sets the maximum number of MetricPoints allowed per metric stream.
Copy link
Member

Choose a reason for hiding this comment

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

Bit of a nit, but this is the first time we're publicly introducing the term MetricPoint. So maybe

Suggested change
/// Sets the maximum number of MetricPoints allowed per metric stream.
/// Sets the maximum number of metric points allowed per metric stream.

I think the name of the method is fine SetMetricPointPerMetricStreamLimit ... unless there's a better term from the spec for describing the MetricPoint concept?

Copy link
Member

Choose a reason for hiding this comment

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

Personal gut feeling - maybe for the user "cardinality" is something easier to digest?

Copy link
Contributor

Choose a reason for hiding this comment

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

How about SetTimeSeriesLimit?

Copy link
Member Author

Choose a reason for hiding this comment

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

maxTimeseries seems a good option.

Copy link
Member Author

Choose a reason for hiding this comment

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

cardinality - i think this would be a better fit, if the limit was for limiting the cardinality of an individual tag.

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

lets me proceed as is now, to unblock release.
Will discuss the naming issues in next SIG meeting. We have ~10 more days before planned stable release, for coming up with better names)

Copy link
Member

@alanwest alanwest left a comment

Choose a reason for hiding this comment

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

No reason to hold up this PR, but I'm wondering if we should change the name MetricPoint to something else?

The term "metric stream" seems pretty well established in the specification, but "metric point" is not as well established. In fact there is a section of the specification here titled Metric Point, but it refers to a different concept than what we've modeled with the MetricPoint class.

We had used the term DataPoint in the past. Searching that data model specification "data point" is a term that is often used. So, what do folks think about maybe DataPoint or MetricDataPoint?

@cijothomas cijothomas merged commit 5dcf29f into open-telemetry:main Nov 19, 2021
@cijothomas cijothomas deleted the cijothomas/configuremetriclimits branch November 19, 2021 18:50
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.

Allow configuring max Metrics allowed, max MetricPoints allowed per Metric
5 participants