Skip to content

Commit

Permalink
[sdk-metrics] Refactor AggregatorStore (#5509)
Browse files Browse the repository at this point in the history
  • Loading branch information
utpilla committed Apr 4, 2024
1 parent 2c421a0 commit 3f4c73a
Showing 1 changed file with 17 additions and 40 deletions.
57 changes: 17 additions & 40 deletions src/OpenTelemetry/Metrics/AggregatorStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,14 +221,7 @@ internal void SnapshotDelta(int indexSnapshot)
continue;
}

if (this.IsExemplarEnabled())
{
metricPoint.TakeSnapshotWithExemplar(outputDelta: true);
}
else
{
metricPoint.TakeSnapshot(outputDelta: true);
}
this.TakeMetricPointSnapshot(ref metricPoint, outputDelta: true);

this.currentMetricPointBatch[this.batchSize] = i;
this.batchSize++;
Expand All @@ -246,14 +239,7 @@ internal void SnapshotDeltaWithMetricPointReclaim()
ref var metricPointWithNoTags = ref this.metricPoints[0];
if (metricPointWithNoTags.MetricPointStatus != MetricPointStatus.NoCollectPending)
{
if (this.IsExemplarEnabled())
{
metricPointWithNoTags.TakeSnapshotWithExemplar(outputDelta: true);
}
else
{
metricPointWithNoTags.TakeSnapshot(outputDelta: true);
}
this.TakeMetricPointSnapshot(ref metricPointWithNoTags, outputDelta: true);

this.currentMetricPointBatch[this.batchSize] = 0;
this.batchSize++;
Expand All @@ -265,14 +251,7 @@ internal void SnapshotDeltaWithMetricPointReclaim()
ref var metricPointForOverflow = ref this.metricPoints[1];
if (metricPointForOverflow.MetricPointStatus != MetricPointStatus.NoCollectPending)
{
if (this.IsExemplarEnabled())
{
metricPointForOverflow.TakeSnapshotWithExemplar(outputDelta: true);
}
else
{
metricPointForOverflow.TakeSnapshot(outputDelta: true);
}
this.TakeMetricPointSnapshot(ref metricPointForOverflow, outputDelta: true);

this.currentMetricPointBatch[this.batchSize] = 1;
this.batchSize++;
Expand Down Expand Up @@ -329,14 +308,7 @@ internal void SnapshotDeltaWithMetricPointReclaim()
continue;
}

if (this.IsExemplarEnabled())
{
metricPoint.TakeSnapshotWithExemplar(outputDelta: true);
}
else
{
metricPoint.TakeSnapshot(outputDelta: true);
}
this.TakeMetricPointSnapshot(ref metricPoint, outputDelta: true);

this.currentMetricPointBatch[this.batchSize] = i;
this.batchSize++;
Expand All @@ -358,14 +330,7 @@ internal void SnapshotCumulative(int indexSnapshot)
continue;
}

if (this.IsExemplarEnabled())
{
metricPoint.TakeSnapshotWithExemplar(outputDelta: false);
}
else
{
metricPoint.TakeSnapshot(outputDelta: false);
}
this.TakeMetricPointSnapshot(ref metricPoint, outputDelta: false);

this.currentMetricPointBatch[this.batchSize] = i;
this.batchSize++;
Expand Down Expand Up @@ -395,6 +360,18 @@ private static double[] FindDefaultHistogramBounds(in MetricStreamIdentity metri
return Metric.DefaultHistogramBounds;
}

private void TakeMetricPointSnapshot(ref MetricPoint metricPoint, bool outputDelta)
{
if (this.IsExemplarEnabled())
{
metricPoint.TakeSnapshotWithExemplar(outputDelta);
}
else
{
metricPoint.TakeSnapshot(outputDelta);
}
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void InitializeZeroTagPointIfNotInitialized()
{
Expand Down

0 comments on commit 3f4c73a

Please sign in to comment.