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

[Metrics] Update default buckets for Explicit Bucket Histogram from spec #3722

Merged
merged 15 commits into from
Oct 13, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 1 addition & 2 deletions docs/metrics/customizing-the-sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,7 @@ with the metric are of interest to you.
#### Specify custom boundaries for Histogram

By default, the boundaries used for a Histogram are [`{ 0, 5, 10, 25, 50, 75,
100, 250, 500,
1000}`](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/sdk.md#explicit-bucket-histogram-aggregation).
100, 250, 500, 750, 1000, 2500, 5000, 7500, 10000}`](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.14.0/specification/metrics/sdk.md#explicit-bucket-histogram-aggregation).
Views can be used to provide custom boundaries for a Histogram. The measurements
are then aggregated using the custom boundaries provided instead of the the
default boundaries. This requires the use of
Expand Down
5 changes: 5 additions & 0 deletions src/OpenTelemetry/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## Unreleased

* Changed default bucket boundaries for Explicit Bucket Histogram from [0, 5,
10, 25, 50, 75, 100, 250, 500, 1000] to [0, 5, 10, 25, 50, 75, 100, 250, 500,
750, 1000, 2500, 5000, 7500, 10000].
([#3722](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3722))

* Fixed an issue where `LogRecord.ForEachScope` may return scopes from a
previous log if accessed in a custom processor before
`BatchLogRecordExportProcessor.OnEnd` is fired.
Expand Down
2 changes: 1 addition & 1 deletion src/OpenTelemetry/Metrics/Metric.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace OpenTelemetry.Metrics
/// </summary>
public sealed class Metric
{
internal static readonly double[] DefaultHistogramBounds = new double[] { 0, 5, 10, 25, 50, 75, 100, 250, 500, 1000 };
internal static readonly double[] DefaultHistogramBounds = new double[] { 0, 5, 10, 25, 50, 75, 100, 250, 500, 750, 1000, 2500, 5000, 7500, 10000 };

private readonly AggregatorStore aggStore;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,12 @@ public void HistogramZeroDimension()
+ "test_histogram_bucket{le='100'} 2 \\d+\n"
+ "test_histogram_bucket{le='250'} 2 \\d+\n"
+ "test_histogram_bucket{le='500'} 2 \\d+\n"
+ "test_histogram_bucket{le='750'} 2 \\d+\n"
+ "test_histogram_bucket{le='1000'} 2 \\d+\n"
+ "test_histogram_bucket{le='2500'} 2 \\d+\n"
+ "test_histogram_bucket{le='5000'} 2 \\d+\n"
+ "test_histogram_bucket{le='7500'} 2 \\d+\n"
+ "test_histogram_bucket{le='10000'} 2 \\d+\n"
+ "test_histogram_bucket{le='\\+Inf'} 2 \\d+\n"
+ "test_histogram_sum 118 \\d+\n"
+ "test_histogram_count 2 \\d+\n"
Expand Down Expand Up @@ -312,7 +317,12 @@ public void HistogramOneDimension()
+ "test_histogram_bucket{x='1',le='100'} 2 \\d+\n"
+ "test_histogram_bucket{x='1',le='250'} 2 \\d+\n"
+ "test_histogram_bucket{x='1',le='500'} 2 \\d+\n"
+ "test_histogram_bucket{x='1',le='750'} 2 \\d+\n"
+ "test_histogram_bucket{x='1',le='1000'} 2 \\d+\n"
+ "test_histogram_bucket{x='1',le='2500'} 2 \\d+\n"
+ "test_histogram_bucket{x='1',le='5000'} 2 \\d+\n"
+ "test_histogram_bucket{x='1',le='7500'} 2 \\d+\n"
+ "test_histogram_bucket{x='1',le='10000'} 2 \\d+\n"
+ "test_histogram_bucket{x='1',le='\\+Inf'} 2 \\d+\n"
+ "test_histogram_sum{x='1'} 118 \\d+\n"
+ "test_histogram_count{x='1'} 2 \\d+\n"
Expand Down Expand Up @@ -351,7 +361,12 @@ public void HistogramTwoDimensions()
+ "test_histogram_bucket{x='1',y='2',le='100'} 2 \\d+\n"
+ "test_histogram_bucket{x='1',y='2',le='250'} 2 \\d+\n"
+ "test_histogram_bucket{x='1',y='2',le='500'} 2 \\d+\n"
+ "test_histogram_bucket{x='1',y='2',le='750'} 2 \\d+\n"
+ "test_histogram_bucket{x='1',y='2',le='1000'} 2 \\d+\n"
+ "test_histogram_bucket{x='1',y='2',le='2500'} 2 \\d+\n"
+ "test_histogram_bucket{x='1',y='2',le='5000'} 2 \\d+\n"
+ "test_histogram_bucket{x='1',y='2',le='7500'} 2 \\d+\n"
+ "test_histogram_bucket{x='1',y='2',le='10000'} 2 \\d+\n"
+ "test_histogram_bucket{x='1',y='2',le='\\+Inf'} 2 \\d+\n"
+ "test_histogram_sum{x='1',y='2'} 118 \\d+\n"
+ "test_histogram_count{x='1',y='2'} 2 \\d+\n"
Expand Down Expand Up @@ -391,7 +406,12 @@ public void HistogramInfinities()
+ "test_histogram_bucket{le='100'} 1 \\d+\n"
+ "test_histogram_bucket{le='250'} 1 \\d+\n"
+ "test_histogram_bucket{le='500'} 1 \\d+\n"
+ "test_histogram_bucket{le='750'} 1 \\d+\n"
+ "test_histogram_bucket{le='1000'} 1 \\d+\n"
+ "test_histogram_bucket{le='2500'} 1 \\d+\n"
+ "test_histogram_bucket{le='5000'} 1 \\d+\n"
+ "test_histogram_bucket{le='7500'} 1 \\d+\n"
+ "test_histogram_bucket{le='10000'} 1 \\d+\n"
+ "test_histogram_bucket{le='\\+Inf'} 3 \\d+\n"
+ "test_histogram_sum \\+Inf \\d+\n"
+ "test_histogram_count 3 \\d+\n"
Expand Down Expand Up @@ -431,7 +451,12 @@ public void HistogramNaN()
+ "test_histogram_bucket{le='100'} 1 \\d+\n"
+ "test_histogram_bucket{le='250'} 1 \\d+\n"
+ "test_histogram_bucket{le='500'} 1 \\d+\n"
+ "test_histogram_bucket{le='750'} 1 \\d+\n"
+ "test_histogram_bucket{le='1000'} 1 \\d+\n"
+ "test_histogram_bucket{le='2500'} 1 \\d+\n"
+ "test_histogram_bucket{le='5000'} 1 \\d+\n"
+ "test_histogram_bucket{le='7500'} 1 \\d+\n"
+ "test_histogram_bucket{le='10000'} 1 \\d+\n"
+ "test_histogram_bucket{le='\\+Inf'} 3 \\d+\n"
+ "test_histogram_sum Nan \\d+\n"
+ "test_histogram_count 3 \\d+\n"
Expand Down
14 changes: 12 additions & 2 deletions test/OpenTelemetry.Tests/Metrics/AggregatorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,25 @@ public void HistogramDistributeToAllBucketsDefault()
histogramPoint.Update(250);
histogramPoint.Update(499);
histogramPoint.Update(500);
histogramPoint.Update(999);
histogramPoint.Update(501);
histogramPoint.Update(750);
histogramPoint.Update(751);
histogramPoint.Update(1000);
histogramPoint.Update(1001);
histogramPoint.Update(2500);
histogramPoint.Update(2501);
histogramPoint.Update(5000);
histogramPoint.Update(5001);
histogramPoint.Update(7500);
histogramPoint.Update(7501);
histogramPoint.Update(10000);
histogramPoint.Update(10001);
histogramPoint.Update(10000000);
histogramPoint.TakeSnapshot(true);

var count = histogramPoint.GetHistogramCount();

Assert.Equal(22, count);
Assert.Equal(32, count);

int actualCount = 0;
foreach (var histogramMeasurement in histogramPoint.GetHistogramBuckets())
Expand Down
12 changes: 6 additions & 6 deletions test/OpenTelemetry.Tests/Metrics/MetricAPITest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1404,29 +1404,29 @@ public void MultithreadedDoubleCounterTest()
[Fact]
public void MultithreadedLongHistogramTest()
{
var expected = new long[11];
var expected = new long[16];
for (var i = 0; i < expected.Length; i++)
{
expected[i] = NumberOfThreads * NumberOfMetricUpdateByEachThread;
}

// Metric.DefaultHistogramBounds: 0, 5, 10, 25, 50, 75, 100, 250, 500, 1000
var values = new long[] { -1, 1, 6, 20, 40, 60, 80, 200, 300, 600, 1001 };
// Metric.DefaultHistogramBounds: 0, 5, 10, 25, 50, 75, 100, 250, 500, 750, 1000, 2500, 5000, 7500, 10000
var values = new long[] { -1, 1, 6, 20, 40, 60, 80, 200, 300, 600, 800, 1001, 3000, 6000, 8000, 10001 };

this.MultithreadedHistogramTest(expected, values);
}

[Fact]
public void MultithreadedDoubleHistogramTest()
{
var expected = new long[11];
var expected = new long[16];
for (var i = 0; i < expected.Length; i++)
{
expected[i] = NumberOfThreads * NumberOfMetricUpdateByEachThread;
}

// Metric.DefaultHistogramBounds: 0, 5, 10, 25, 50, 75, 100, 250, 500, 1000
var values = new double[] { -1.0, 1.0, 6.0, 20.0, 40.0, 60.0, 80.0, 200.0, 300.0, 600.0, 1001.0 };
// Metric.DefaultHistogramBounds: 0, 5, 10, 25, 50, 75, 100, 250, 500, 750, 1000, 2500, 5000, 7500, 10000
var values = new double[] { -1.0, 1.0, 6.0, 20.0, 40.0, 60.0, 80.0, 200.0, 300.0, 600.0, 800.0, 1001.0, 3000.0, 6000.0, 8000.0, 10001.0 };

this.MultithreadedHistogramTest(expected, values);
}
Expand Down
2 changes: 1 addition & 1 deletion test/OpenTelemetry.Tests/Metrics/MetricViewTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ public void ViewToProduceCustomHistogramBound()

int index = 0;
int actualCount = 0;
var expectedBucketCounts = new long[] { 2, 1, 2, 2, 0, 0, 0, 0, 0, 0, 0 };
var expectedBucketCounts = new long[] { 2, 1, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
foreach (var histogramMeasurement in histogramPoint.GetHistogramBuckets())
{
Assert.Equal(expectedBucketCounts[index], histogramMeasurement.BucketCount);
Expand Down