@@ -13,6 +13,8 @@ internal sealed class AggregatorStore
1313{
1414 internal readonly bool OutputDelta ;
1515 internal readonly bool OutputDeltaWithUnusedMetricPointReclaimEnabled ;
16+ internal readonly int CardinalityLimit ;
17+ internal readonly bool EmitOverflowAttribute ;
1618 internal long DroppedMeasurements = 0 ;
1719
1820 private static readonly string MetricPointCapHitFixMessage = "Consider opting in for the experimental SDK feature to emit all the throttled metrics under the overflow attribute by setting env variable OTEL_DOTNET_EXPERIMENTAL_METRICS_EMIT_OVERFLOW_ATTRIBUTE = true. You could also modify instrumentation to reduce the number of unique key/value pair combinations. Or use Views to drop unwanted tags. Or use MeterProviderBuilder.SetMaxMetricPointsPerMetricStream to set higher limit." ;
@@ -42,8 +44,6 @@ internal sealed class AggregatorStore
4244 private readonly int exponentialHistogramMaxScale ;
4345 private readonly UpdateLongDelegate updateLongCallback ;
4446 private readonly UpdateDoubleDelegate updateDoubleCallback ;
45- private readonly int maxMetricPoints ;
46- private readonly bool emitOverflowAttribute ;
4747 private readonly ExemplarFilter exemplarFilter ;
4848 private readonly Func < KeyValuePair < string , object ? > [ ] , int , int > lookupAggregatorStore ;
4949
@@ -57,17 +57,17 @@ internal AggregatorStore(
5757 MetricStreamIdentity metricStreamIdentity ,
5858 AggregationType aggType ,
5959 AggregationTemporality temporality ,
60- int maxMetricPoints ,
60+ int cardinalityLimit ,
6161 bool emitOverflowAttribute ,
6262 bool shouldReclaimUnusedMetricPoints ,
6363 ExemplarFilter ? exemplarFilter = null )
6464 {
6565 this . name = metricStreamIdentity . InstrumentName ;
66- this . maxMetricPoints = maxMetricPoints ;
66+ this . CardinalityLimit = cardinalityLimit ;
6767
68- this . metricPointCapHitMessage = $ "Maximum MetricPoints limit reached for this Metric stream. Configured limit: { this . maxMetricPoints } ";
69- this . metricPoints = new MetricPoint [ maxMetricPoints ] ;
70- this . currentMetricPointBatch = new int [ maxMetricPoints ] ;
68+ this . metricPointCapHitMessage = $ "Maximum MetricPoints limit reached for this Metric stream. Configured limit: { this . CardinalityLimit } ";
69+ this . metricPoints = new MetricPoint [ cardinalityLimit ] ;
70+ this . currentMetricPointBatch = new int [ cardinalityLimit ] ;
7171 this . aggType = aggType ;
7272 this . OutputDelta = temporality == AggregationTemporality . Delta ;
7373 this . histogramBounds = metricStreamIdentity . HistogramBucketBounds ?? FindDefaultHistogramBounds ( in metricStreamIdentity ) ;
@@ -89,7 +89,7 @@ internal AggregatorStore(
8989 this . tagsKeysInterestingCount = hs . Count ;
9090 }
9191
92- this . emitOverflowAttribute = emitOverflowAttribute ;
92+ this . EmitOverflowAttribute = emitOverflowAttribute ;
9393
9494 var reservedMetricPointsCount = 1 ;
9595
@@ -105,17 +105,17 @@ internal AggregatorStore(
105105
106106 if ( this . OutputDeltaWithUnusedMetricPointReclaimEnabled )
107107 {
108- this . availableMetricPoints = new Queue < int > ( maxMetricPoints - reservedMetricPointsCount ) ;
108+ this . availableMetricPoints = new Queue < int > ( cardinalityLimit - reservedMetricPointsCount ) ;
109109
110110 // There is no overload which only takes capacity as the parameter
111111 // Using the DefaultConcurrencyLevel defined in the ConcurrentDictionary class: https://github.com/dotnet/runtime/blob/v7.0.5/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/ConcurrentDictionary.cs#L2020
112112 // We expect at the most (maxMetricPoints - reservedMetricPointsCount) * 2 entries- one for sorted and one for unsorted input
113113 this . tagsToMetricPointIndexDictionaryDelta =
114- new ConcurrentDictionary < Tags , LookupData > ( concurrencyLevel : Environment . ProcessorCount , capacity : ( maxMetricPoints - reservedMetricPointsCount ) * 2 ) ;
114+ new ConcurrentDictionary < Tags , LookupData > ( concurrencyLevel : Environment . ProcessorCount , capacity : ( cardinalityLimit - reservedMetricPointsCount ) * 2 ) ;
115115
116116 // Add all the indices except for the reserved ones to the queue so that threads have
117117 // readily available access to these MetricPoints for their use.
118- for ( int i = reservedMetricPointsCount ; i < this . maxMetricPoints ; i ++ )
118+ for ( int i = reservedMetricPointsCount ; i < this . CardinalityLimit ; i ++ )
119119 {
120120 this . availableMetricPoints . Enqueue ( i ) ;
121121 }
@@ -164,12 +164,12 @@ internal int Snapshot()
164164 }
165165 else if ( this . OutputDelta )
166166 {
167- var indexSnapshot = Math . Min ( this . metricPointIndex , this . maxMetricPoints - 1 ) ;
167+ var indexSnapshot = Math . Min ( this . metricPointIndex , this . CardinalityLimit - 1 ) ;
168168 this . SnapshotDelta ( indexSnapshot ) ;
169169 }
170170 else
171171 {
172- var indexSnapshot = Math . Min ( this . metricPointIndex , this . maxMetricPoints - 1 ) ;
172+ var indexSnapshot = Math . Min ( this . metricPointIndex , this . CardinalityLimit - 1 ) ;
173173 this . SnapshotCumulative ( indexSnapshot ) ;
174174 }
175175
@@ -227,7 +227,7 @@ internal void SnapshotDeltaWithMetricPointReclaim()
227227
228228 int startIndexForReclaimableMetricPoints = 1 ;
229229
230- if ( this . emitOverflowAttribute )
230+ if ( this . EmitOverflowAttribute )
231231 {
232232 startIndexForReclaimableMetricPoints = 2 ; // Index 0 and 1 are reserved for no tags and overflow
233233
@@ -249,7 +249,7 @@ internal void SnapshotDeltaWithMetricPointReclaim()
249249 }
250250 }
251251
252- for ( int i = startIndexForReclaimableMetricPoints ; i < this . maxMetricPoints ; i ++ )
252+ for ( int i = startIndexForReclaimableMetricPoints ; i < this . CardinalityLimit ; i ++ )
253253 {
254254 ref var metricPoint = ref this . metricPoints [ i ] ;
255255
@@ -440,7 +440,7 @@ private int LookupAggregatorStore(KeyValuePair<string, object?>[] tagKeysAndValu
440440 if ( ! this . tagsToMetricPointIndexDictionary . TryGetValue ( sortedTags , out aggregatorIndex ) )
441441 {
442442 aggregatorIndex = this . metricPointIndex ;
443- if ( aggregatorIndex >= this . maxMetricPoints )
443+ if ( aggregatorIndex >= this . CardinalityLimit )
444444 {
445445 // sorry! out of data points.
446446 // TODO: Once we support cleanup of
@@ -469,7 +469,7 @@ private int LookupAggregatorStore(KeyValuePair<string, object?>[] tagKeysAndValu
469469 if ( ! this . tagsToMetricPointIndexDictionary . TryGetValue ( sortedTags , out aggregatorIndex ) )
470470 {
471471 aggregatorIndex = ++ this . metricPointIndex ;
472- if ( aggregatorIndex >= this . maxMetricPoints )
472+ if ( aggregatorIndex >= this . CardinalityLimit )
473473 {
474474 // sorry! out of data points.
475475 // TODO: Once we support cleanup of
@@ -496,7 +496,7 @@ private int LookupAggregatorStore(KeyValuePair<string, object?>[] tagKeysAndValu
496496 {
497497 // This else block is for tag length = 1
498498 aggregatorIndex = this . metricPointIndex ;
499- if ( aggregatorIndex >= this . maxMetricPoints )
499+ if ( aggregatorIndex >= this . CardinalityLimit )
500500 {
501501 // sorry! out of data points.
502502 // TODO: Once we support cleanup of
@@ -518,7 +518,7 @@ private int LookupAggregatorStore(KeyValuePair<string, object?>[] tagKeysAndValu
518518 if ( ! this . tagsToMetricPointIndexDictionary . TryGetValue ( givenTags , out aggregatorIndex ) )
519519 {
520520 aggregatorIndex = ++ this . metricPointIndex ;
521- if ( aggregatorIndex >= this . maxMetricPoints )
521+ if ( aggregatorIndex >= this . CardinalityLimit )
522522 {
523523 // sorry! out of data points.
524524 // TODO: Once we support cleanup of
@@ -929,7 +929,7 @@ private void UpdateLong(long value, ReadOnlySpan<KeyValuePair<string, object?>>
929929 {
930930 Interlocked . Increment ( ref this . DroppedMeasurements ) ;
931931
932- if ( this . emitOverflowAttribute )
932+ if ( this . EmitOverflowAttribute )
933933 {
934934 this . InitializeOverflowTagPointIfNotInitialized ( ) ;
935935 this . metricPoints [ 1 ] . Update ( value ) ;
@@ -973,7 +973,7 @@ private void UpdateLongCustomTags(long value, ReadOnlySpan<KeyValuePair<string,
973973 {
974974 Interlocked . Increment ( ref this . DroppedMeasurements ) ;
975975
976- if ( this . emitOverflowAttribute )
976+ if ( this . EmitOverflowAttribute )
977977 {
978978 this . InitializeOverflowTagPointIfNotInitialized ( ) ;
979979 this . metricPoints [ 1 ] . Update ( value ) ;
@@ -1017,7 +1017,7 @@ private void UpdateDouble(double value, ReadOnlySpan<KeyValuePair<string, object
10171017 {
10181018 Interlocked . Increment ( ref this . DroppedMeasurements ) ;
10191019
1020- if ( this . emitOverflowAttribute )
1020+ if ( this . EmitOverflowAttribute )
10211021 {
10221022 this . InitializeOverflowTagPointIfNotInitialized ( ) ;
10231023 this . metricPoints [ 1 ] . Update ( value ) ;
@@ -1061,7 +1061,7 @@ private void UpdateDoubleCustomTags(double value, ReadOnlySpan<KeyValuePair<stri
10611061 {
10621062 Interlocked . Increment ( ref this . DroppedMeasurements ) ;
10631063
1064- if ( this . emitOverflowAttribute )
1064+ if ( this . EmitOverflowAttribute )
10651065 {
10661066 this . InitializeOverflowTagPointIfNotInitialized ( ) ;
10671067 this . metricPoints [ 1 ] . Update ( value ) ;
0 commit comments