Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,14 @@ public void Record(double value)
Debug.Assert(n == 0, "Increment should always succeed after scale down.");
}

internal void Reset()
internal void Reset(bool isDelta)
{
// TODO: Determine if this is sufficient for delta temporality.
// I'm not sure we should be resetting the scale.
if (isDelta)
{
this.Scale = Metric.DefaultExponentialHistogramMaxScale;
this.RunningSum = 0;
}

this.ZeroCount = 0;
this.PositiveBuckets.Reset();
this.NegativeBuckets.Reset();
Expand Down
6 changes: 2 additions & 4 deletions src/OpenTelemetry/Metrics/MetricPoint/MetricPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -820,8 +820,7 @@ internal void TakeSnapshot(bool outputDelta)
if (outputDelta)
{
this.runningValue.AsLong = 0;
histogram.RunningSum = 0;
histogram.Reset();
histogram.Reset(outputDelta);
}

this.MetricPointStatus = MetricPointStatus.NoCollectPending;
Expand All @@ -848,8 +847,7 @@ internal void TakeSnapshot(bool outputDelta)
if (outputDelta)
{
this.runningValue.AsLong = 0;
histogram.RunningSum = 0;
histogram.Reset();
histogram.Reset(outputDelta);
histogram.RunningMin = double.PositiveInfinity;
histogram.RunningMax = double.NegativeInfinity;
}
Expand Down
7 changes: 6 additions & 1 deletion test/OpenTelemetry.Tests/Metrics/AggregatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -352,10 +352,12 @@ internal void ExponentialHistogramTests(AggregationType aggregationType, Aggrega
var count = metricPoint.GetHistogramCount();
var sum = metricPoint.GetHistogramSum();
var hasMinMax = metricPoint.TryGetHistogramMinMaxValues(out var min, out var max);
var firstScale = metricPoint.GetExponentialHistogramData().Scale;

AssertExponentialBucketsAreCorrect(expectedHistogram, metricPoint.GetExponentialHistogramData());
Assert.Equal(50, sum);
Assert.Equal(6, count);
Assert.True(firstScale <= Metric.DefaultExponentialHistogramMaxScale);

if (aggregationType == AggregationType.Base2ExponentialHistogramWithMinMax)
{
Expand All @@ -373,12 +375,14 @@ internal void ExponentialHistogramTests(AggregationType aggregationType, Aggrega
count = metricPoint.GetHistogramCount();
sum = metricPoint.GetHistogramSum();
hasMinMax = metricPoint.TryGetHistogramMinMaxValues(out min, out max);
var secondScale = metricPoint.GetExponentialHistogramData().Scale;

if (aggregationTemporality == AggregationTemporality.Cumulative)
{
AssertExponentialBucketsAreCorrect(expectedHistogram, metricPoint.GetExponentialHistogramData());
Assert.Equal(50, sum);
Assert.Equal(6, count);
Assert.Equal(firstScale, secondScale);

if (aggregationType == AggregationType.Base2ExponentialHistogramWithMinMax)
{
Expand All @@ -393,10 +397,11 @@ internal void ExponentialHistogramTests(AggregationType aggregationType, Aggrega
}
else
{
expectedHistogram.Reset();
expectedHistogram.Reset(true);
AssertExponentialBucketsAreCorrect(expectedHistogram, metricPoint.GetExponentialHistogramData());
Assert.Equal(0, sum);
Assert.Equal(0, count);
Assert.Equal(Metric.DefaultExponentialHistogramMaxScale, secondScale);

if (aggregationType == AggregationType.Base2ExponentialHistogramWithMinMax)
{
Expand Down
Loading