Histogram MinMax API fixes (#3822)
This commit is contained in:
parent
004c3f6a1f
commit
88c1864cb7
|
|
@ -98,9 +98,9 @@ namespace OpenTelemetry.Exporter
|
|||
var sum = metricPoint.GetHistogramSum();
|
||||
var count = metricPoint.GetHistogramCount();
|
||||
bucketsBuilder.Append($"Sum: {sum} Count: {count} ");
|
||||
if (metricPoint.HasMinMax())
|
||||
if (metricPoint.TryGetHistogramMinMaxValues(out double min, out double max))
|
||||
{
|
||||
bucketsBuilder.Append($"Min: {metricPoint.GetHistogramMin()} Max: {metricPoint.GetHistogramMax()} ");
|
||||
bucketsBuilder.Append($"Min: {min} Max: {max} ");
|
||||
}
|
||||
|
||||
bucketsBuilder.AppendLine();
|
||||
|
|
|
|||
|
|
@ -257,10 +257,10 @@ namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation
|
|||
dataPoint.Count = (ulong)metricPoint.GetHistogramCount();
|
||||
dataPoint.Sum = metricPoint.GetHistogramSum();
|
||||
|
||||
if (metricPoint.HasMinMax())
|
||||
if (metricPoint.TryGetHistogramMinMaxValues(out double min, out double max))
|
||||
{
|
||||
dataPoint.Min = metricPoint.GetHistogramMin();
|
||||
dataPoint.Max = metricPoint.GetHistogramMax();
|
||||
dataPoint.Min = min;
|
||||
dataPoint.Max = max;
|
||||
}
|
||||
|
||||
foreach (var histogramMeasurement in metricPoint.GetHistogramBuckets())
|
||||
|
|
|
|||
|
|
@ -14,9 +14,7 @@ OpenTelemetry.Metrics.HistogramConfiguration
|
|||
OpenTelemetry.Metrics.HistogramConfiguration.HistogramConfiguration() -> void
|
||||
OpenTelemetry.Metrics.HistogramConfiguration.RecordMinMax.get -> bool
|
||||
OpenTelemetry.Metrics.HistogramConfiguration.RecordMinMax.set -> void
|
||||
OpenTelemetry.Metrics.MetricPoint.GetHistogramMax() -> double
|
||||
OpenTelemetry.Metrics.MetricPoint.GetHistogramMin() -> double
|
||||
OpenTelemetry.Metrics.MetricPoint.HasMinMax() -> bool
|
||||
OpenTelemetry.Metrics.MetricPoint.TryGetHistogramMinMaxValues(out double min, out double max) -> bool
|
||||
OpenTelemetry.Resources.ResourceBuilder.AddDetector(System.Func<System.IServiceProvider?, OpenTelemetry.Resources.IResourceDetector!>! resourceDetectorFactory) -> OpenTelemetry.Resources.ResourceBuilder!
|
||||
OpenTelemetry.Trace.BatchExportActivityProcessorOptions.BatchExportActivityProcessorOptions(Microsoft.Extensions.Configuration.IConfiguration! configuration) -> void
|
||||
static Microsoft.Extensions.DependencyInjection.MeterProviderBuilderServiceCollectionExtensions.ConfigureOpenTelemetryMetrics(this Microsoft.Extensions.DependencyInjection.IServiceCollection! services) -> Microsoft.Extensions.DependencyInjection.IServiceCollection!
|
||||
|
|
|
|||
|
|
@ -14,9 +14,7 @@ OpenTelemetry.Metrics.HistogramConfiguration
|
|||
OpenTelemetry.Metrics.HistogramConfiguration.HistogramConfiguration() -> void
|
||||
OpenTelemetry.Metrics.HistogramConfiguration.RecordMinMax.get -> bool
|
||||
OpenTelemetry.Metrics.HistogramConfiguration.RecordMinMax.set -> void
|
||||
OpenTelemetry.Metrics.MetricPoint.GetHistogramMax() -> double
|
||||
OpenTelemetry.Metrics.MetricPoint.GetHistogramMin() -> double
|
||||
OpenTelemetry.Metrics.MetricPoint.HasMinMax() -> bool
|
||||
OpenTelemetry.Metrics.MetricPoint.TryGetHistogramMinMaxValues(out double min, out double max) -> bool
|
||||
OpenTelemetry.Resources.ResourceBuilder.AddDetector(System.Func<System.IServiceProvider?, OpenTelemetry.Resources.IResourceDetector!>! resourceDetectorFactory) -> OpenTelemetry.Resources.ResourceBuilder!
|
||||
OpenTelemetry.Trace.BatchExportActivityProcessorOptions.BatchExportActivityProcessorOptions(Microsoft.Extensions.Configuration.IConfiguration! configuration) -> void
|
||||
static Microsoft.Extensions.DependencyInjection.MeterProviderBuilderServiceCollectionExtensions.ConfigureOpenTelemetryMetrics(this Microsoft.Extensions.DependencyInjection.IServiceCollection! services) -> Microsoft.Extensions.DependencyInjection.IServiceCollection!
|
||||
|
|
|
|||
|
|
@ -14,9 +14,7 @@ OpenTelemetry.Metrics.HistogramConfiguration
|
|||
OpenTelemetry.Metrics.HistogramConfiguration.HistogramConfiguration() -> void
|
||||
OpenTelemetry.Metrics.HistogramConfiguration.RecordMinMax.get -> bool
|
||||
OpenTelemetry.Metrics.HistogramConfiguration.RecordMinMax.set -> void
|
||||
OpenTelemetry.Metrics.MetricPoint.GetHistogramMax() -> double
|
||||
OpenTelemetry.Metrics.MetricPoint.GetHistogramMin() -> double
|
||||
OpenTelemetry.Metrics.MetricPoint.HasMinMax() -> bool
|
||||
OpenTelemetry.Metrics.MetricPoint.TryGetHistogramMinMaxValues(out double min, out double max) -> bool
|
||||
OpenTelemetry.Resources.ResourceBuilder.AddDetector(System.Func<System.IServiceProvider?, OpenTelemetry.Resources.IResourceDetector!>! resourceDetectorFactory) -> OpenTelemetry.Resources.ResourceBuilder!
|
||||
OpenTelemetry.Trace.BatchExportActivityProcessorOptions.BatchExportActivityProcessorOptions(Microsoft.Extensions.Configuration.IConfiguration! configuration) -> void
|
||||
static Microsoft.Extensions.DependencyInjection.MeterProviderBuilderServiceCollectionExtensions.ConfigureOpenTelemetryMetrics(this Microsoft.Extensions.DependencyInjection.IServiceCollection! services) -> Microsoft.Extensions.DependencyInjection.IServiceCollection!
|
||||
|
|
|
|||
|
|
@ -14,9 +14,7 @@ OpenTelemetry.Metrics.HistogramConfiguration
|
|||
OpenTelemetry.Metrics.HistogramConfiguration.HistogramConfiguration() -> void
|
||||
OpenTelemetry.Metrics.HistogramConfiguration.RecordMinMax.get -> bool
|
||||
OpenTelemetry.Metrics.HistogramConfiguration.RecordMinMax.set -> void
|
||||
OpenTelemetry.Metrics.MetricPoint.GetHistogramMax() -> double
|
||||
OpenTelemetry.Metrics.MetricPoint.GetHistogramMin() -> double
|
||||
OpenTelemetry.Metrics.MetricPoint.HasMinMax() -> bool
|
||||
OpenTelemetry.Metrics.MetricPoint.TryGetHistogramMinMaxValues(out double min, out double max) -> bool
|
||||
OpenTelemetry.Resources.ResourceBuilder.AddDetector(System.Func<System.IServiceProvider?, OpenTelemetry.Resources.IResourceDetector!>! resourceDetectorFactory) -> OpenTelemetry.Resources.ResourceBuilder!
|
||||
OpenTelemetry.Trace.BatchExportActivityProcessorOptions.BatchExportActivityProcessorOptions(Microsoft.Extensions.Configuration.IConfiguration! configuration) -> void
|
||||
static Microsoft.Extensions.DependencyInjection.MeterProviderBuilderServiceCollectionExtensions.ConfigureOpenTelemetryMetrics(this Microsoft.Extensions.DependencyInjection.IServiceCollection! services) -> Microsoft.Extensions.DependencyInjection.IServiceCollection!
|
||||
|
|
|
|||
|
|
@ -243,44 +243,27 @@ namespace OpenTelemetry.Metrics
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the minimum value of the histogram associated with the metric
|
||||
/// point if present. Check by using <see cref="HasMinMax"/>.
|
||||
/// Gets the Histogram Min and Max values.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Applies to <see cref="MetricType.Histogram"/> metric type.
|
||||
/// </remarks>
|
||||
/// <returns>A histogram's maximum value.</returns>
|
||||
/// <param name="min"> The histogram minimum value.</param>
|
||||
/// <param name="max"> The histogram maximum value.</param>
|
||||
/// <returns>True if minimum and maximum value exist, false otherwise.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public double GetHistogramMin()
|
||||
public bool TryGetHistogramMinMaxValues(out double min, out double max)
|
||||
{
|
||||
return this.histogramBuckets.SnapshotMin;
|
||||
}
|
||||
if (this.aggType == AggregationType.HistogramWithMinMax ||
|
||||
this.aggType == AggregationType.HistogramWithMinMaxBuckets)
|
||||
{
|
||||
Debug.Assert(this.histogramBuckets != null, "histogramBuckets was null");
|
||||
|
||||
/// <summary>
|
||||
/// Gets the maximum value of the histogram associated with the metric
|
||||
/// point if present. Check by using <see cref="HasMinMax"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Applies to <see cref="MetricType.Histogram"/> metric type.
|
||||
/// </remarks>
|
||||
/// <returns>A histogram's maximum value.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public double GetHistogramMax()
|
||||
{
|
||||
return this.histogramBuckets.SnapshotMax;
|
||||
}
|
||||
min = this.histogramBuckets.SnapshotMin;
|
||||
max = this.histogramBuckets.SnapshotMax;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether the histogram has a valid Min and Max value.
|
||||
/// Should be used before
|
||||
/// <see cref="GetHistogramMin"/> and <see cref="GetHistogramMax"/> to
|
||||
/// ensure a valid value is returned.
|
||||
/// </summary>
|
||||
/// <returns>A minimum and maximum value exist.</returns>
|
||||
public bool HasMinMax()
|
||||
{
|
||||
return this.aggType == AggregationType.HistogramWithMinMaxBuckets ||
|
||||
this.aggType == AggregationType.HistogramWithMinMax;
|
||||
min = 0;
|
||||
max = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
internal readonly MetricPoint Copy()
|
||||
|
|
|
|||
|
|
@ -599,14 +599,15 @@ namespace OpenTelemetry.Metrics.Tests
|
|||
}
|
||||
|
||||
var histogramPoint = metricPoints[0];
|
||||
var hasMinMax = histogramPoint.HasMinMax();
|
||||
Assert.True(hasMinMax);
|
||||
|
||||
var min = histogramPoint.GetHistogramMin();
|
||||
var max = histogramPoint.GetHistogramMax();
|
||||
|
||||
Assert.Equal(expectedMin, min);
|
||||
Assert.Equal(expectedMax, max);
|
||||
if (histogramPoint.TryGetHistogramMinMaxValues(out double min, out double max))
|
||||
{
|
||||
Assert.Equal(expectedMin, min);
|
||||
Assert.Equal(expectedMax, max);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail("MinMax expected");
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
|
|
@ -636,8 +637,7 @@ namespace OpenTelemetry.Metrics.Tests
|
|||
}
|
||||
|
||||
var histogramPoint = metricPoints[0];
|
||||
|
||||
Assert.False(histogramPoint.HasMinMax());
|
||||
Assert.False(histogramPoint.TryGetHistogramMinMaxValues(out double _, out double _));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
|
|||
Loading…
Reference in New Issue