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

Rename histogram configuration bucketbounds to boundaries #2638

Merged
merged 12 commits into from
Nov 18, 2021
6 changes: 3 additions & 3 deletions docs/metrics/customizing-the-sdk/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public static void Main(string[] args)
// Rename an instrument to new name.
.AddView(instrumentName: "MyCounter", name: "MyCounterRenamed")

// Change Histogram bounds
.AddView(instrumentName: "MyHistogram", new HistogramConfiguration() { BucketBounds = new double[] { 10, 20 } })
// Change Histogram boundaries
.AddView(instrumentName: "MyHistogram", new ExplicitBucketHistogramConfiguration() { Boundaries = new double[] { 10, 20 } })

// For the instrument "MyCounterCustomTags", aggregate with only the keys "tag1", "tag2".
.AddView(instrumentName: "MyCounterCustomTags", new MetricStreamConfiguration() { TagKeys = new string[] { "tag1", "tag2" } })
Expand All @@ -48,7 +48,7 @@ public static void Main(string[] args)
if (instrument.Meter.Name.Equals("CompanyA.ProductB.Library2") &&
instrument.GetType().Name.Contains("Histogram"))
{
return new HistogramConfiguration() { BucketBounds = new double[] { 10, 20 } };
return new ExplicitBucketHistogramConfiguration() { Boundaries = new double[] { 10, 20 } };
}

return null;
Expand Down
25 changes: 13 additions & 12 deletions docs/metrics/customizing-the-sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,30 +218,31 @@ with the metric are of interest to you.
})
```

#### Specify custom bounds for Histogram
#### Specify custom boundaries for Histogram

By default, the bounds used for a Histogram are [`{ 0, 5, 10, 25, 50, 75, 100,
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).
Views can be used to provide custom bounds for a Histogram. The measurements are
then aggregated using the custom bounds provided instead of the the default
bounds. This requires the use of `HistogramConfiguration`.
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 `ExplicitBucketHistogramConfiguration`.

```csharp
// Change Histogram bounds to count measurements under the following buckets:
// Change Histogram boundaries to count measurements under the following buckets:
// (-inf, 10]
// (10, 20]
// (20, +inf)
.AddView(
instrumentName: "MyHistogram",
new HistogramConfiguration{ BucketBounds = new double[] { 10, 20 } })
new ExplicitBucketHistogramConfiguration
{ Boundaries = new double[] { 10, 20 } })

// If you provide an empty `double` array as `BucketBounds` to the `HistogramConfiguration`,
// If you provide an empty `double` array as `Boundaries` to the `ExplicitBucketHistogramConfiguration`,
// the SDK will only export the sum and count for the measurements.
// There are no buckets exported in this case.
.AddView(
instrumentName: "MyHistogram",
new HistogramConfiguration { BucketBounds = new double[] { } })
new ExplicitBucketHistogramConfiguration { Boundaries = new double[] { } })
```

```csharp
Expand All @@ -251,10 +252,10 @@ bounds. This requires the use of `HistogramConfiguration`.
if (instrument.Meter.Name == "CompanyA.ProductB.LibraryC" &&
instrument.Name == "MyHistogram")
{
// `HistogramConfiguration` is a child class of `MetricStreamConfiguration`
return new HistogramConfiguration
// `ExplicitBucketHistogramConfiguration` is a child class of `MetricStreamConfiguration`
return new ExplicitBucketHistogramConfiguration
{
BucketBounds = new double[] { 10, 20 },
Boundaries = new double[] { 10, 20 },
};
}

Expand Down
12 changes: 6 additions & 6 deletions src/OpenTelemetry/.publicApi/net461/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ OpenTelemetry.Metrics.ExportModes.Push = 1 -> OpenTelemetry.Metrics.ExportModes
OpenTelemetry.Metrics.ExportModesAttribute
OpenTelemetry.Metrics.ExportModesAttribute.ExportModesAttribute(OpenTelemetry.Metrics.ExportModes supported) -> void
OpenTelemetry.Metrics.ExportModesAttribute.Supported.get -> OpenTelemetry.Metrics.ExportModes
OpenTelemetry.Metrics.HistogramConfiguration
OpenTelemetry.Metrics.HistogramConfiguration.BucketBounds.get -> double[]
OpenTelemetry.Metrics.HistogramConfiguration.BucketBounds.set -> void
OpenTelemetry.Metrics.HistogramConfiguration.HistogramConfiguration() -> void
OpenTelemetry.Metrics.ExplicitBucketHistogramConfiguration
OpenTelemetry.Metrics.ExplicitBucketHistogramConfiguration.Boundaries.get -> double[]
OpenTelemetry.Metrics.ExplicitBucketHistogramConfiguration.Boundaries.set -> void
OpenTelemetry.Metrics.ExplicitBucketHistogramConfiguration.ExplicitBucketHistogramConfiguration() -> void
OpenTelemetry.Metrics.IPullMetricExporter
OpenTelemetry.Metrics.IPullMetricExporter.Collect.get -> System.Func<int, bool>
OpenTelemetry.Metrics.IPullMetricExporter.Collect.set -> void
Expand Down Expand Up @@ -100,8 +100,8 @@ override OpenTelemetry.Metrics.BaseExportingMetricReader.Dispose(bool disposing)
override OpenTelemetry.Metrics.BaseExportingMetricReader.OnCollect(int timeoutMilliseconds) -> bool
override OpenTelemetry.Metrics.BaseExportingMetricReader.OnShutdown(int timeoutMilliseconds) -> bool
override OpenTelemetry.Metrics.BaseExportingMetricReader.ProcessMetrics(in OpenTelemetry.Batch<OpenTelemetry.Metrics.Metric> metrics, int timeoutMilliseconds) -> bool
override OpenTelemetry.Metrics.HistogramConfiguration.Aggregation.get -> OpenTelemetry.Metrics.Aggregation
override OpenTelemetry.Metrics.HistogramConfiguration.Aggregation.set -> void
override OpenTelemetry.Metrics.ExplicitBucketHistogramConfiguration.Aggregation.get -> OpenTelemetry.Metrics.Aggregation
override OpenTelemetry.Metrics.ExplicitBucketHistogramConfiguration.Aggregation.set -> void
override OpenTelemetry.Metrics.MeterProviderBuilderBase.AddInstrumentation<TInstrumentation>(System.Func<TInstrumentation> instrumentationFactory) -> OpenTelemetry.Metrics.MeterProviderBuilder
override OpenTelemetry.Metrics.MeterProviderBuilderBase.AddMeter(params string[] names) -> OpenTelemetry.Metrics.MeterProviderBuilder
override OpenTelemetry.Metrics.PeriodicExportingMetricReader.Dispose(bool disposing) -> void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ OpenTelemetry.Metrics.ExportModes.Push = 1 -> OpenTelemetry.Metrics.ExportModes
OpenTelemetry.Metrics.ExportModesAttribute
OpenTelemetry.Metrics.ExportModesAttribute.ExportModesAttribute(OpenTelemetry.Metrics.ExportModes supported) -> void
OpenTelemetry.Metrics.ExportModesAttribute.Supported.get -> OpenTelemetry.Metrics.ExportModes
OpenTelemetry.Metrics.HistogramConfiguration
OpenTelemetry.Metrics.HistogramConfiguration.BucketBounds.get -> double[]
OpenTelemetry.Metrics.HistogramConfiguration.BucketBounds.set -> void
OpenTelemetry.Metrics.HistogramConfiguration.HistogramConfiguration() -> void
OpenTelemetry.Metrics.ExplicitBucketHistogramConfiguration
OpenTelemetry.Metrics.ExplicitBucketHistogramConfiguration.Boundaries.get -> double[]
OpenTelemetry.Metrics.ExplicitBucketHistogramConfiguration.Boundaries.set -> void
OpenTelemetry.Metrics.ExplicitBucketHistogramConfiguration.ExplicitBucketHistogramConfiguration() -> void
OpenTelemetry.Metrics.IPullMetricExporter
OpenTelemetry.Metrics.IPullMetricExporter.Collect.get -> System.Func<int, bool>
OpenTelemetry.Metrics.IPullMetricExporter.Collect.set -> void
Expand Down Expand Up @@ -100,8 +100,8 @@ override OpenTelemetry.Metrics.BaseExportingMetricReader.Dispose(bool disposing)
override OpenTelemetry.Metrics.BaseExportingMetricReader.OnCollect(int timeoutMilliseconds) -> bool
override OpenTelemetry.Metrics.BaseExportingMetricReader.OnShutdown(int timeoutMilliseconds) -> bool
override OpenTelemetry.Metrics.BaseExportingMetricReader.ProcessMetrics(in OpenTelemetry.Batch<OpenTelemetry.Metrics.Metric> metrics, int timeoutMilliseconds) -> bool
override OpenTelemetry.Metrics.HistogramConfiguration.Aggregation.get -> OpenTelemetry.Metrics.Aggregation
override OpenTelemetry.Metrics.HistogramConfiguration.Aggregation.set -> void
override OpenTelemetry.Metrics.ExplicitBucketHistogramConfiguration.Aggregation.get -> OpenTelemetry.Metrics.Aggregation
override OpenTelemetry.Metrics.ExplicitBucketHistogramConfiguration.Aggregation.set -> void
override OpenTelemetry.Metrics.MeterProviderBuilderBase.AddInstrumentation<TInstrumentation>(System.Func<TInstrumentation> instrumentationFactory) -> OpenTelemetry.Metrics.MeterProviderBuilder
override OpenTelemetry.Metrics.MeterProviderBuilderBase.AddMeter(params string[] names) -> OpenTelemetry.Metrics.MeterProviderBuilder
override OpenTelemetry.Metrics.PeriodicExportingMetricReader.Dispose(bool disposing) -> void
Expand Down
4 changes: 4 additions & 0 deletions src/OpenTelemetry/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

* HistogramConfiguration renamed to ExplicitBucketHistogramConfiguration.
cijothomas marked this conversation as resolved.
Show resolved Hide resolved
* BucketBounds renamed to Boundaries for HistogramConfiguration.
([#2638](https://github.com/open-telemetry/opentelemetry-dotnet/pull/2638))

* Metrics with the same name but from different meters are allowed.
([#2634](https://github.com/open-telemetry/opentelemetry-dotnet/pull/2634))

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// <copyright file="HistogramConfiguration.cs" company="OpenTelemetry Authors">
// <copyright file="ExplicitBucketHistogramConfiguration.cs" company="OpenTelemetry Authors">
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -18,17 +18,18 @@

namespace OpenTelemetry.Metrics
{
public class HistogramConfiguration : MetricStreamConfiguration
public class ExplicitBucketHistogramConfiguration : MetricStreamConfiguration
{
private Aggregation aggregation = Aggregation.Histogram;

/// <summary>
/// Gets or sets the custom histogram bounds.
/// Gets or sets the values representing explicit histogram bucket
/// boundary values.
/// </summary>
/// <remarks>
/// The array must be in ascending order with distinct values.
/// </remarks>
public double[] BucketBounds { get; set; }
public double[] Boundaries { get; set; }

public override Aggregation Aggregation
{
Expand Down
8 changes: 4 additions & 4 deletions src/OpenTelemetry/Metrics/MeterProviderBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ public static MeterProviderBuilder AddView(this MeterProviderBuilder meterProvid
throw new ArgumentException($"Custom view name {metricStreamConfiguration.Name} is invalid.", nameof(metricStreamConfiguration.Name));
}

if (metricStreamConfiguration is HistogramConfiguration histogramConfiguration)
if (metricStreamConfiguration is ExplicitBucketHistogramConfiguration histogramConfiguration)
{
// Validate histogram bounds
if (histogramConfiguration.BucketBounds != null && !IsSortedAndDistinct(histogramConfiguration.BucketBounds))
// Validate histogram boundaries
if (histogramConfiguration.Boundaries != null && !IsSortedAndDistinct(histogramConfiguration.Boundaries))
{
throw new ArgumentException($"Histogram bounds must be in ascending order with distinct values", nameof(histogramConfiguration.BucketBounds));
throw new ArgumentException($"Histogram boundaries must be in ascending order with distinct values", nameof(histogramConfiguration.Boundaries));
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/OpenTelemetry/Metrics/MeterProviderSdk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ internal MeterProviderSdk(
Metric metric;
var metricDescription = metricStreamConfig?.Description ?? instrument.Description;
string[] tagKeysInteresting = metricStreamConfig?.TagKeys;
double[] histogramBucketBounds = (metricStreamConfig is HistogramConfiguration histogramConfig
&& histogramConfig.BucketBounds != null) ? histogramConfig.BucketBounds : null;
double[] histogramBucketBounds = (metricStreamConfig is ExplicitBucketHistogramConfiguration histogramConfig
&& histogramConfig.Boundaries != null) ? histogramConfig.Boundaries : null;
metric = new Metric(instrument, temporality, metricName, metricDescription, histogramBucketBounds, tagKeysInteresting);

this.metrics[index] = metric;
Expand Down
10 changes: 5 additions & 5 deletions test/OpenTelemetry.Tests/Metrics/AggregatorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ public void HistogramDistributeToAllBucketsDefault()
[Fact]
public void HistogramDistributeToAllBucketsCustom()
{
var bounds = new double[] { 10, 20 };
var histogramPoint = new MetricPoint(AggregationType.Histogram, DateTimeOffset.Now, null, null, bounds);
var boundaries = new double[] { 10, 20 };
var histogramPoint = new MetricPoint(AggregationType.Histogram, DateTimeOffset.Now, null, null, boundaries);

// 5 recordings <=10
histogramPoint.Update(-10);
Expand All @@ -80,7 +80,7 @@ public void HistogramDistributeToAllBucketsCustom()

// Count = # of recordings
Assert.Equal(7, histogramPoint.LongValue);
Assert.Equal(bounds.Length + 1, histogramPoint.BucketCounts.Length);
Assert.Equal(boundaries.Length + 1, histogramPoint.BucketCounts.Length);
Assert.Equal(5, histogramPoint.BucketCounts[0]);
Assert.Equal(2, histogramPoint.BucketCounts[1]);
Assert.Equal(0, histogramPoint.BucketCounts[2]);
Expand All @@ -89,8 +89,8 @@ public void HistogramDistributeToAllBucketsCustom()
[Fact]
public void HistogramWithOnlySumCount()
{
var bounds = new double[] { };
var histogramPoint = new MetricPoint(AggregationType.HistogramSumCount, DateTimeOffset.Now, null, null, bounds);
var boundaries = new double[] { };
var histogramPoint = new MetricPoint(AggregationType.HistogramSumCount, DateTimeOffset.Now, null, null, boundaries);

histogramPoint.Update(-10);
histogramPoint.Update(0);
Expand Down
2 changes: 1 addition & 1 deletion test/OpenTelemetry.Tests/Metrics/MetricTestData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static IEnumerable<object[]> ValidInstrumentNames
new object[] { new string('m', 63) },
};

public static IEnumerable<object[]> InvalidHistogramBounds
public static IEnumerable<object[]> InvalidHistogramBoundaries
=> new List<object[]>
{
new object[] { new double[] { 0, 0 } },
Expand Down
16 changes: 8 additions & 8 deletions test/OpenTelemetry.Tests/Metrics/MetricViewTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,13 @@ public void AddViewWithNullMetricStreamConfigurationThrowsArgumentnullException(
}

[Theory]
[MemberData(nameof(MetricTestData.InvalidHistogramBounds), MemberType = typeof(MetricTestData))]
public void AddViewWithInvalidHistogramBoundsThrowsArgumentException(double[] bounds)
[MemberData(nameof(MetricTestData.InvalidHistogramBoundaries), MemberType = typeof(MetricTestData))]
public void AddViewWithInvalidHistogramBoundsThrowsArgumentException(double[] boundaries)
{
var ex = Assert.Throws<ArgumentException>(() => Sdk.CreateMeterProviderBuilder()
.AddView("name1", new HistogramConfiguration { BucketBounds = bounds }));
.AddView("name1", new ExplicitBucketHistogramConfiguration { Boundaries = boundaries }));

Assert.Contains("Histogram bounds must be in ascending order with distinct values", ex.Message);
Assert.Contains("Histogram boundaries must be in ascending order with distinct values", ex.Message);
}

[Theory]
Expand Down Expand Up @@ -355,11 +355,11 @@ public void ViewToProduceCustomHistogramBound()
{
using var meter = new Meter(Utils.GetCurrentMethodName());
var exportedItems = new List<Metric>();
var bounds = new double[] { 10, 20 };
var boundaries = new double[] { 10, 20 };
using var meterProvider = Sdk.CreateMeterProviderBuilder()
.AddMeter(meter.Name)
.AddView("MyHistogram", new HistogramConfiguration() { Name = "MyHistogramDefaultBound" })
.AddView("MyHistogram", new HistogramConfiguration() { BucketBounds = bounds })
.AddView("MyHistogram", new ExplicitBucketHistogramConfiguration() { Name = "MyHistogramDefaultBound" })
.AddView("MyHistogram", new ExplicitBucketHistogramConfiguration() { Boundaries = boundaries })
.AddInMemoryExporter(exportedItems)
.Build();

Expand Down Expand Up @@ -409,7 +409,7 @@ public void ViewToProduceCustomHistogramBound()

Assert.Equal(40, histogramPoint.DoubleValue);
Assert.Equal(7, histogramPoint.LongValue);
Assert.Equal(bounds.Length + 1, histogramPoint.BucketCounts.Length);
Assert.Equal(boundaries.Length + 1, histogramPoint.BucketCounts.Length);
Assert.Equal(5, histogramPoint.BucketCounts[0]);
Assert.Equal(2, histogramPoint.BucketCounts[1]);
Assert.Equal(0, histogramPoint.BucketCounts[2]);
Expand Down