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
4 changes: 2 additions & 2 deletions docs/metrics/customizing-the-sdk/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static void Main(string[] args)
.AddView(instrumentName: "MyCounter", name: "MyCounterRenamed")

// Change Histogram bounds
.AddView(instrumentName: "MyHistogram", new HistogramConfiguration() { BucketBounds = new double[] { 10, 20 } })
.AddView(instrumentName: "MyHistogram", new HistogramConfiguration() { 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 HistogramConfiguration() { Boundaries = new double[] { 10, 20 } };
}

return null;
Expand Down
5 changes: 3 additions & 2 deletions src/OpenTelemetry/Metrics/HistogramConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ public class HistogramConfiguration : 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; }
cijothomas marked this conversation as resolved.
Show resolved Hide resolved

public override Aggregation Aggregation
{
Expand Down
4 changes: 2 additions & 2 deletions src/OpenTelemetry/Metrics/MeterProviderBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ public static MeterProviderBuilder AddView(this MeterProviderBuilder meterProvid
if (metricStreamConfiguration is HistogramConfiguration histogramConfiguration)
{
// Validate histogram bounds
if (histogramConfiguration.BucketBounds != null && !IsSortedAndDistinct(histogramConfiguration.BucketBounds))
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 bounds must be in ascending order with distinct values", nameof(histogramConfiguration.Boundaries));
}
}

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

this.metrics[index] = metric;
Expand Down
4 changes: 2 additions & 2 deletions test/OpenTelemetry.Tests/Metrics/MetricViewTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void AddViewWithNullMetricStreamConfigurationThrowsArgumentnullException(
public void AddViewWithInvalidHistogramBoundsThrowsArgumentException(double[] bounds)
{
var ex = Assert.Throws<ArgumentException>(() => Sdk.CreateMeterProviderBuilder()
.AddView("name1", new HistogramConfiguration { BucketBounds = bounds }));
.AddView("name1", new HistogramConfiguration { Boundaries = bounds }));

Assert.Contains("Histogram bounds must be in ascending order with distinct values", ex.Message);
}
Expand Down Expand Up @@ -359,7 +359,7 @@ public void ViewToProduceCustomHistogramBound()
using var meterProvider = Sdk.CreateMeterProviderBuilder()
.AddMeter(meter.Name)
.AddView("MyHistogram", new HistogramConfiguration() { Name = "MyHistogramDefaultBound" })
.AddView("MyHistogram", new HistogramConfiguration() { BucketBounds = bounds })
.AddView("MyHistogram", new HistogramConfiguration() { Boundaries = bounds })
cijothomas marked this conversation as resolved.
Show resolved Hide resolved
.AddInMemoryExporter(exportedItems)
.Build();

Expand Down