MetricReader TemporalityPreference (#3153)

This commit is contained in:
Alan West 2022-04-12 13:00:04 -07:00 committed by GitHub
parent 3bf869ab38
commit 89a740e20a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 181 additions and 129 deletions

View File

@ -71,7 +71,7 @@ namespace Examples.Console
exporterOptions.Protocol = options.UseGrpc ? OtlpExportProtocol.Grpc : OtlpExportProtocol.HttpProtobuf;
metricReaderOptions.PeriodicExportingMetricReaderOptions.ExportIntervalMilliseconds = options.DefaultCollectionPeriodMilliseconds;
metricReaderOptions.Temporality = options.IsDelta ? AggregationTemporality.Delta : AggregationTemporality.Cumulative;
metricReaderOptions.TemporalityPreference = options.IsDelta ? MetricReaderTemporalityPreference.Delta : MetricReaderTemporalityPreference.Cumulative;
});
}
else
@ -82,7 +82,7 @@ namespace Examples.Console
exporterOptions.Targets = ConsoleExporterOutputTargets.Console;
metricReaderOptions.PeriodicExportingMetricReaderOptions.ExportIntervalMilliseconds = options.DefaultCollectionPeriodMilliseconds;
metricReaderOptions.Temporality = options.IsDelta ? AggregationTemporality.Delta : AggregationTemporality.Cumulative;
metricReaderOptions.TemporalityPreference = options.IsDelta ? MetricReaderTemporalityPreference.Delta : MetricReaderTemporalityPreference.Cumulative;
});
}

View File

@ -23,7 +23,6 @@ namespace OpenTelemetry.Exporter
/// <summary>
/// Exporter of OpenTelemetry metrics to Prometheus.
/// </summary>
[AggregationTemporality(AggregationTemporality.Cumulative)]
[ExportModes(ExportModes.Pull)]
public class PrometheusExporter : BaseExporter<Metric>, IPullMetricExporter
{

View File

@ -49,6 +49,7 @@ namespace OpenTelemetry.Metrics
var exporter = new PrometheusExporter(options);
var reader = new BaseExportingMetricReader(exporter);
reader.TemporalityPreference = MetricReaderTemporalityPreference.Cumulative;
return builder.AddReader(reader);
}

View File

@ -5,17 +5,14 @@ OpenTelemetry.Metrics.ExplicitBucketHistogramConfiguration
OpenTelemetry.Metrics.ExplicitBucketHistogramConfiguration.Boundaries.get -> double[]
OpenTelemetry.Metrics.ExplicitBucketHistogramConfiguration.Boundaries.set -> void
OpenTelemetry.Metrics.ExplicitBucketHistogramConfiguration.ExplicitBucketHistogramConfiguration() -> void
OpenTelemetry.Metrics.MetricReader.TemporalityPreference.get -> OpenTelemetry.Metrics.MetricReaderTemporalityPreference
OpenTelemetry.Metrics.MetricReader.TemporalityPreference.set -> void
OpenTelemetry.Metrics.MetricReaderOptions
OpenTelemetry.Metrics.MetricReaderOptions.MetricReaderOptions() -> void
OpenTelemetry.Metrics.MetricReaderOptions.PeriodicExportingMetricReaderOptions.get -> OpenTelemetry.Metrics.PeriodicExportingMetricReaderOptions
OpenTelemetry.Metrics.MetricReaderOptions.Temporality.get -> OpenTelemetry.Metrics.AggregationTemporality
OpenTelemetry.Metrics.MetricReaderOptions.Temporality.set -> void
OpenTelemetry.Metrics.AggregationTemporality
OpenTelemetry.Metrics.AggregationTemporality.Cumulative = 1 -> OpenTelemetry.Metrics.AggregationTemporality
OpenTelemetry.Metrics.AggregationTemporality.Delta = 2 -> OpenTelemetry.Metrics.AggregationTemporality
OpenTelemetry.Metrics.AggregationTemporalityAttribute
OpenTelemetry.Metrics.AggregationTemporalityAttribute.AggregationTemporalityAttribute(OpenTelemetry.Metrics.AggregationTemporality temporality) -> void
OpenTelemetry.Metrics.AggregationTemporalityAttribute.Temporality.get -> OpenTelemetry.Metrics.AggregationTemporality
OpenTelemetry.Metrics.BaseExportingMetricReader
OpenTelemetry.Metrics.BaseExportingMetricReader.BaseExportingMetricReader(OpenTelemetry.BaseExporter<OpenTelemetry.Metrics.Metric> exporter) -> void
OpenTelemetry.Metrics.BaseExportingMetricReader.SupportedExportModes.get -> OpenTelemetry.Metrics.ExportModes
@ -76,8 +73,11 @@ OpenTelemetry.Metrics.MetricReader.Collect(int timeoutMilliseconds = -1) -> bool
OpenTelemetry.Metrics.MetricReader.Dispose() -> void
OpenTelemetry.Metrics.MetricReader.MetricReader() -> void
OpenTelemetry.Metrics.MetricReader.Shutdown(int timeoutMilliseconds = -1) -> bool
OpenTelemetry.Metrics.MetricReader.Temporality.get -> OpenTelemetry.Metrics.AggregationTemporality
OpenTelemetry.Metrics.MetricReader.Temporality.set -> void
OpenTelemetry.Metrics.MetricReaderOptions.TemporalityPreference.get -> OpenTelemetry.Metrics.MetricReaderTemporalityPreference
OpenTelemetry.Metrics.MetricReaderOptions.TemporalityPreference.set -> void
OpenTelemetry.Metrics.MetricReaderTemporalityPreference
OpenTelemetry.Metrics.MetricReaderTemporalityPreference.Cumulative = 1 -> OpenTelemetry.Metrics.MetricReaderTemporalityPreference
OpenTelemetry.Metrics.MetricReaderTemporalityPreference.Delta = 2 -> OpenTelemetry.Metrics.MetricReaderTemporalityPreference
OpenTelemetry.Metrics.MetricStreamConfiguration
OpenTelemetry.Metrics.MetricStreamConfiguration.Description.get -> string
OpenTelemetry.Metrics.MetricStreamConfiguration.Description.set -> void

View File

@ -5,17 +5,14 @@ OpenTelemetry.Metrics.ExplicitBucketHistogramConfiguration
OpenTelemetry.Metrics.ExplicitBucketHistogramConfiguration.Boundaries.get -> double[]
OpenTelemetry.Metrics.ExplicitBucketHistogramConfiguration.Boundaries.set -> void
OpenTelemetry.Metrics.ExplicitBucketHistogramConfiguration.ExplicitBucketHistogramConfiguration() -> void
OpenTelemetry.Metrics.MetricReader.TemporalityPreference.get -> OpenTelemetry.Metrics.MetricReaderTemporalityPreference
OpenTelemetry.Metrics.MetricReader.TemporalityPreference.set -> void
OpenTelemetry.Metrics.MetricReaderOptions
OpenTelemetry.Metrics.MetricReaderOptions.MetricReaderOptions() -> void
OpenTelemetry.Metrics.MetricReaderOptions.PeriodicExportingMetricReaderOptions.get -> OpenTelemetry.Metrics.PeriodicExportingMetricReaderOptions
OpenTelemetry.Metrics.MetricReaderOptions.Temporality.get -> OpenTelemetry.Metrics.AggregationTemporality
OpenTelemetry.Metrics.MetricReaderOptions.Temporality.set -> void
OpenTelemetry.Metrics.AggregationTemporality
OpenTelemetry.Metrics.AggregationTemporality.Cumulative = 1 -> OpenTelemetry.Metrics.AggregationTemporality
OpenTelemetry.Metrics.AggregationTemporality.Delta = 2 -> OpenTelemetry.Metrics.AggregationTemporality
OpenTelemetry.Metrics.AggregationTemporalityAttribute
OpenTelemetry.Metrics.AggregationTemporalityAttribute.AggregationTemporalityAttribute(OpenTelemetry.Metrics.AggregationTemporality temporality) -> void
OpenTelemetry.Metrics.AggregationTemporalityAttribute.Temporality.get -> OpenTelemetry.Metrics.AggregationTemporality
OpenTelemetry.Metrics.BaseExportingMetricReader
OpenTelemetry.Metrics.BaseExportingMetricReader.BaseExportingMetricReader(OpenTelemetry.BaseExporter<OpenTelemetry.Metrics.Metric> exporter) -> void
OpenTelemetry.Metrics.BaseExportingMetricReader.SupportedExportModes.get -> OpenTelemetry.Metrics.ExportModes
@ -76,8 +73,11 @@ OpenTelemetry.Metrics.MetricReader.Collect(int timeoutMilliseconds = -1) -> bool
OpenTelemetry.Metrics.MetricReader.Dispose() -> void
OpenTelemetry.Metrics.MetricReader.MetricReader() -> void
OpenTelemetry.Metrics.MetricReader.Shutdown(int timeoutMilliseconds = -1) -> bool
OpenTelemetry.Metrics.MetricReader.Temporality.get -> OpenTelemetry.Metrics.AggregationTemporality
OpenTelemetry.Metrics.MetricReader.Temporality.set -> void
OpenTelemetry.Metrics.MetricReaderOptions.TemporalityPreference.get -> OpenTelemetry.Metrics.MetricReaderTemporalityPreference
OpenTelemetry.Metrics.MetricReaderOptions.TemporalityPreference.set -> void
OpenTelemetry.Metrics.MetricReaderTemporalityPreference
OpenTelemetry.Metrics.MetricReaderTemporalityPreference.Cumulative = 1 -> OpenTelemetry.Metrics.MetricReaderTemporalityPreference
OpenTelemetry.Metrics.MetricReaderTemporalityPreference.Delta = 2 -> OpenTelemetry.Metrics.MetricReaderTemporalityPreference
OpenTelemetry.Metrics.MetricStreamConfiguration
OpenTelemetry.Metrics.MetricStreamConfiguration.Description.get -> string
OpenTelemetry.Metrics.MetricStreamConfiguration.Description.set -> void

View File

@ -2,6 +2,19 @@
## Unreleased
* Removed the `Temporality` setting on `MetricReader` and replaced it with
`TemporalityPreference`. This is a breaking change.
`TemporalityPreference` is used to determine the `AggregationTemporality`
used on a per-instrument kind basis. Currently, there are two preferences:
* `Cumulative`: Measurements from all instrument kinds are aggregated using
`AggregationTemporality.Cumulative`.
* `Delta`: Measurements from `Counter`, `ObservableCounter`, and `Histogram`
instruments are aggregated using `AggregationTemporality.Delta`. When
UpDownCounters are supported with
[DiagnosticSource version 7.0 onwards](https://www.nuget.org/packages/System.Diagnostics.DiagnosticSource/7.0.0-preview.2.22152.2),
they will be aggregated using `AggregationTemporality.Cumulative`.
([#3153](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3153))
* Fix issue where `ExplicitBucketHistogramConfiguration` could be used to
configure metric streams for instruments that are not histograms. Currently,
it is not possible to change the aggregation of an instrument with views. This

View File

@ -34,7 +34,7 @@ internal static class PeriodicExportingMetricReaderHelper
var metricReader = new PeriodicExportingMetricReader(exporter, exportInterval, exportTimeout)
{
Temporality = options.Temporality,
TemporalityPreference = options.TemporalityPreference,
};
return metricReader;

View File

@ -1,33 +0,0 @@
// <copyright file="AggregationTemporalityAttribute.cs" company="OpenTelemetry Authors">
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
using System;
namespace OpenTelemetry.Metrics
{
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
public sealed class AggregationTemporalityAttribute : Attribute
{
private readonly AggregationTemporality temporality;
public AggregationTemporalityAttribute(AggregationTemporality temporality)
{
this.temporality = temporality;
}
public AggregationTemporality Temporality => this.temporality;
}
}

View File

@ -45,14 +45,7 @@ namespace OpenTelemetry.Metrics
this.exporter = exporter;
var exportorType = exporter.GetType();
var attributes = exportorType.GetCustomAttributes(typeof(AggregationTemporalityAttribute), true);
if (attributes.Length > 0)
{
var attr = (AggregationTemporalityAttribute)attributes[attributes.Length - 1];
this.Temporality = attr.Temporality;
}
attributes = exportorType.GetCustomAttributes(typeof(ExportModesAttribute), true);
var attributes = exportorType.GetCustomAttributes(typeof(ExportModesAttribute), true);
if (attributes.Length > 0)
{
var attr = (ExportModesAttribute)attributes[attributes.Length - 1];

View File

@ -16,6 +16,7 @@
using System;
using System.Diagnostics;
using System.Diagnostics.Metrics;
using System.Threading;
using System.Threading.Tasks;
using OpenTelemetry.Internal;
@ -27,35 +28,74 @@ namespace OpenTelemetry.Metrics
/// </summary>
public abstract partial class MetricReader : IDisposable
{
private const AggregationTemporality AggregationTemporalityUnspecified = (AggregationTemporality)0;
private const MetricReaderTemporalityPreference MetricReaderTemporalityPreferenceUnspecified = (MetricReaderTemporalityPreference)0;
private static Func<Type, AggregationTemporality> cumulativeTemporatlityPreferenceFunc =
(instrumentType) => AggregationTemporality.Cumulative;
private static Func<Type, AggregationTemporality> monotonicDeltaTemporatlityPreferenceFunc = (instrumentType) =>
{
return instrumentType.GetGenericTypeDefinition() switch
{
var type when type == typeof(Counter<>) => AggregationTemporality.Delta,
var type when type == typeof(ObservableCounter<>) => AggregationTemporality.Delta,
var type when type == typeof(Histogram<>) => AggregationTemporality.Delta,
// Temporatlity is not defined for gauges, so this does not really affect anything.
var type when type == typeof(ObservableGauge<>) => AggregationTemporality.Delta,
// With .NET 7 the OpenTelemetry .NET SDK will support UpDownCounters.
// These will be aggregated using Cumulative temporatlity.
// See:
// https://docs.microsoft.com/dotnet/api/system.diagnostics.metrics.updowncounter-1
// https://docs.microsoft.com/dotnet/api/system.diagnostics.metrics.observableupdowncounter-1
// var type when type == typeof(UpDownCounter<>) => AggregationTemporality.Cumulative,
// var type when type == typeof(ObservableUpDownCounter<>) => AggregationTemporality.Cumulative,
// TODO: Consider logging here because we should not fall through to this case.
_ => AggregationTemporality.Delta,
};
};
private readonly object newTaskLock = new();
private readonly object onCollectLock = new();
private readonly TaskCompletionSource<bool> shutdownTcs = new();
private AggregationTemporality temporality = AggregationTemporalityUnspecified;
private MetricReaderTemporalityPreference temporalityPreference = MetricReaderTemporalityPreferenceUnspecified;
private Func<Type, AggregationTemporality> temporatlityFunc = cumulativeTemporatlityPreferenceFunc;
private int shutdownCount;
private TaskCompletionSource<bool> collectionTcs;
private BaseProvider parentProvider;
public AggregationTemporality Temporality
public MetricReaderTemporalityPreference TemporalityPreference
{
get
{
if (this.temporality == AggregationTemporalityUnspecified)
if (this.temporalityPreference == MetricReaderTemporalityPreferenceUnspecified)
{
this.temporality = AggregationTemporality.Cumulative;
this.temporalityPreference = MetricReaderTemporalityPreference.Cumulative;
}
return this.temporality;
return this.temporalityPreference;
}
set
{
if (this.temporality != AggregationTemporalityUnspecified)
if (this.temporalityPreference != MetricReaderTemporalityPreferenceUnspecified)
{
throw new NotSupportedException($"The temporality cannot be modified (the current value is {this.temporality}).");
throw new NotSupportedException($"The temporality preference cannot be modified (the current value is {this.temporalityPreference}).");
}
this.temporality = value;
this.temporalityPreference = value;
switch (value)
{
case MetricReaderTemporalityPreference.Delta:
this.temporatlityFunc = monotonicDeltaTemporatlityPreferenceFunc;
break;
case MetricReaderTemporalityPreference.Cumulative:
default:
this.temporatlityFunc = cumulativeTemporatlityPreferenceFunc;
break;
}
}
}

View File

@ -36,6 +36,11 @@ namespace OpenTelemetry.Metrics
private Metric[] metricsCurrentBatch;
private int metricIndex = -1;
internal AggregationTemporality GetAggregationTemporality(Type instrumentType)
{
return this.temporatlityFunc(instrumentType);
}
internal Metric AddMetricWithNoViews(Instrument instrument)
{
var metricStreamIdentity = new MetricStreamIdentity(instrument, metricStreamConfiguration: null);
@ -66,7 +71,7 @@ namespace OpenTelemetry.Metrics
Metric metric = null;
try
{
metric = new Metric(metricStreamIdentity, this.Temporality, this.maxMetricPointsPerMetricStream);
metric = new Metric(metricStreamIdentity, this.GetAggregationTemporality(metricStreamIdentity.InstrumentType), this.maxMetricPointsPerMetricStream);
}
catch (NotSupportedException nse)
{
@ -152,7 +157,7 @@ namespace OpenTelemetry.Metrics
else
{
Metric metric;
metric = new Metric(metricStreamIdentity, this.Temporality, this.maxMetricPointsPerMetricStream, metricStreamIdentity.HistogramBucketBounds, metricStreamIdentity.TagKeys);
metric = new Metric(metricStreamIdentity, this.GetAggregationTemporality(metricStreamIdentity.InstrumentType), this.maxMetricPointsPerMetricStream, metricStreamIdentity.HistogramBucketBounds, metricStreamIdentity.TagKeys);
this.instrumentIdentityToMetric[metricStreamIdentity] = metric;
this.metrics[index] = metric;

View File

@ -22,10 +22,9 @@ namespace OpenTelemetry.Metrics;
public class MetricReaderOptions
{
/// <summary>
/// Gets or sets the AggregationTemporality used for Histogram
/// and Sum metrics.
/// Gets or sets the <see cref="MetricReaderTemporalityPreference" />.
/// </summary>
public AggregationTemporality Temporality { get; set; } = AggregationTemporality.Cumulative;
public MetricReaderTemporalityPreference TemporalityPreference { get; set; } = MetricReaderTemporalityPreference.Cumulative;
/// <summary>
/// Gets the <see cref="PeriodicExportingMetricReaderOptions" /> options.

View File

@ -0,0 +1,35 @@
// <copyright file="MetricReaderTemporalityPreference.cs" company="OpenTelemetry Authors">
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
namespace OpenTelemetry.Metrics;
/// <summary>
/// Defines the behavior of a <see cref="MetricReader" />
/// with respect to <see cref="AggregationTemporality" />.
/// </summary>
public enum MetricReaderTemporalityPreference
{
/// <summary>
/// All aggregations are performed using cumulative temporatlity.
/// </summary>
Cumulative = 1,
/// <summary>
/// All measurements that are monotnic in nature are aggregated using delta temporality.
/// Aggregations of non-monotonic measurements use cumulative temporality.
/// </summary>
Delta = 2,
}

View File

@ -88,7 +88,7 @@ namespace Benchmarks.Metrics
this.reader = new BaseExportingMetricReader(metricExporter)
{
Temporality = AggregationTemporality.Cumulative,
TemporalityPreference = MetricReaderTemporalityPreference.Cumulative,
};
this.meter = new Meter(Utils.GetCurrentMethodName());

View File

@ -61,8 +61,8 @@ namespace Benchmarks.Metrics
private MeterProvider provider;
private Meter meter;
[Params(AggregationTemporality.Cumulative, AggregationTemporality.Delta)]
public AggregationTemporality AggregationTemporality { get; set; }
[Params(MetricReaderTemporalityPreference.Cumulative, MetricReaderTemporalityPreference.Delta)]
public MetricReaderTemporalityPreference AggregationTemporality { get; set; }
[GlobalSetup]
public void Setup()
@ -75,7 +75,7 @@ namespace Benchmarks.Metrics
.AddInMemoryExporter(exportedItems, metricReaderOptions =>
{
metricReaderOptions.PeriodicExportingMetricReaderOptions.ExportIntervalMilliseconds = 1000;
metricReaderOptions.Temporality = this.AggregationTemporality;
metricReaderOptions.TemporalityPreference = this.AggregationTemporality;
})
.Build();

View File

@ -260,12 +260,12 @@ namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests
}
[Theory]
[InlineData("test_counter", null, null, 123, null, AggregationTemporality.Cumulative, true)]
[InlineData("test_counter", null, null, null, 123.45, AggregationTemporality.Cumulative, true)]
[InlineData("test_counter", null, null, 123, null, AggregationTemporality.Delta, true)]
[InlineData("test_counter", "description", "unit", 123, null, AggregationTemporality.Cumulative, true)]
[InlineData("test_counter", null, null, 123, null, AggregationTemporality.Delta, true, "key1", "value1", "key2", 123)]
public void TestCounterToOtlpMetric(string name, string description, string unit, long? longValue, double? doubleValue, AggregationTemporality aggregationTemporality, bool isMonotonic, params object[] keysValues)
[InlineData("test_counter", null, null, 123, null, MetricReaderTemporalityPreference.Cumulative, true)]
[InlineData("test_counter", null, null, null, 123.45, MetricReaderTemporalityPreference.Cumulative, true)]
[InlineData("test_counter", null, null, 123, null, MetricReaderTemporalityPreference.Delta, true)]
[InlineData("test_counter", "description", "unit", 123, null, MetricReaderTemporalityPreference.Cumulative, true)]
[InlineData("test_counter", null, null, 123, null, MetricReaderTemporalityPreference.Delta, true, "key1", "value1", "key2", 123)]
public void TestCounterToOtlpMetric(string name, string description, string unit, long? longValue, double? doubleValue, MetricReaderTemporalityPreference aggregationTemporality, bool isMonotonic, params object[] keysValues)
{
var metrics = new List<Metric>();
@ -274,7 +274,7 @@ namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests
.AddMeter(meter.Name)
.AddInMemoryExporter(metrics, metricReaderOptions =>
{
metricReaderOptions.Temporality = aggregationTemporality;
metricReaderOptions.TemporalityPreference = aggregationTemporality;
})
.Build();
@ -315,7 +315,7 @@ namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests
Assert.Equal(isMonotonic, actual.Sum.IsMonotonic);
var otlpAggregationTemporality = aggregationTemporality == AggregationTemporality.Cumulative
var otlpAggregationTemporality = aggregationTemporality == MetricReaderTemporalityPreference.Cumulative
? OtlpMetrics.AggregationTemporality.Cumulative
: OtlpMetrics.AggregationTemporality.Delta;
Assert.Equal(otlpAggregationTemporality, actual.Sum.AggregationTemporality);
@ -356,12 +356,12 @@ namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests
}
[Theory]
[InlineData("test_histogram", null, null, 123, null, AggregationTemporality.Cumulative)]
[InlineData("test_histogram", null, null, null, 123.45, AggregationTemporality.Cumulative)]
[InlineData("test_histogram", null, null, 123, null, AggregationTemporality.Delta)]
[InlineData("test_histogram", "description", "unit", 123, null, AggregationTemporality.Cumulative)]
[InlineData("test_histogram", null, null, 123, null, AggregationTemporality.Delta, "key1", "value1", "key2", 123)]
public void TestHistogramToOtlpMetric(string name, string description, string unit, long? longValue, double? doubleValue, AggregationTemporality aggregationTemporality, params object[] keysValues)
[InlineData("test_histogram", null, null, 123, null, MetricReaderTemporalityPreference.Cumulative)]
[InlineData("test_histogram", null, null, null, 123.45, MetricReaderTemporalityPreference.Cumulative)]
[InlineData("test_histogram", null, null, 123, null, MetricReaderTemporalityPreference.Delta)]
[InlineData("test_histogram", "description", "unit", 123, null, MetricReaderTemporalityPreference.Cumulative)]
[InlineData("test_histogram", null, null, 123, null, MetricReaderTemporalityPreference.Delta, "key1", "value1", "key2", 123)]
public void TestHistogramToOtlpMetric(string name, string description, string unit, long? longValue, double? doubleValue, MetricReaderTemporalityPreference aggregationTemporality, params object[] keysValues)
{
var metrics = new List<Metric>();
@ -370,7 +370,7 @@ namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests
.AddMeter(meter.Name)
.AddInMemoryExporter(metrics, metricReaderOptions =>
{
metricReaderOptions.Temporality = aggregationTemporality;
metricReaderOptions.TemporalityPreference = aggregationTemporality;
})
.Build();
@ -409,7 +409,7 @@ namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests
Assert.Null(actual.ExponentialHistogram);
Assert.Null(actual.Summary);
var otlpAggregationTemporality = aggregationTemporality == AggregationTemporality.Cumulative
var otlpAggregationTemporality = aggregationTemporality == MetricReaderTemporalityPreference.Cumulative
? OtlpMetrics.AggregationTemporality.Cumulative
: OtlpMetrics.AggregationTemporality.Delta;
Assert.Equal(otlpAggregationTemporality, actual.Histogram.AggregationTemporality);

View File

@ -33,7 +33,7 @@ namespace OpenTelemetry.Metrics.Tests
.AddMeter(meter.Name)
.AddInMemoryExporter(exportedItems, metricReaderOptions =>
{
metricReaderOptions.Temporality = AggregationTemporality.Delta;
metricReaderOptions.TemporalityPreference = MetricReaderTemporalityPreference.Delta;
})
.Build();

View File

@ -24,9 +24,9 @@ namespace OpenTelemetry.Metrics.Tests
public class MemoryEfficiencyTests
{
[Theory]
[InlineData(AggregationTemporality.Cumulative)]
[InlineData(AggregationTemporality.Delta)]
public void ExportOnlyWhenPointChanged(AggregationTemporality temporality)
[InlineData(MetricReaderTemporalityPreference.Cumulative)]
[InlineData(MetricReaderTemporalityPreference.Delta)]
public void ExportOnlyWhenPointChanged(MetricReaderTemporalityPreference temporality)
{
using var meter = new Meter($"{Utils.GetCurrentMethodName()}.{temporality}");
@ -36,7 +36,7 @@ namespace OpenTelemetry.Metrics.Tests
.AddMeter(meter.Name)
.AddInMemoryExporter(exportedItems, metricReaderOptions =>
{
metricReaderOptions.Temporality = temporality;
metricReaderOptions.TemporalityPreference = temporality;
})
.Build();
@ -48,7 +48,7 @@ namespace OpenTelemetry.Metrics.Tests
exportedItems.Clear();
meterProvider.ForceFlush();
if (temporality == AggregationTemporality.Cumulative)
if (temporality == MetricReaderTemporalityPreference.Cumulative)
{
Assert.Single(exportedItems);
}

View File

@ -396,11 +396,11 @@ namespace OpenTelemetry.Metrics.Tests
}
[Theory]
[InlineData(AggregationTemporality.Cumulative, true)]
[InlineData(AggregationTemporality.Cumulative, false)]
[InlineData(AggregationTemporality.Delta, true)]
[InlineData(AggregationTemporality.Delta, false)]
public void DuplicateInstrumentNamesFromDifferentMetersAreAllowed(AggregationTemporality temporality, bool hasView)
[InlineData(MetricReaderTemporalityPreference.Cumulative, true)]
[InlineData(MetricReaderTemporalityPreference.Cumulative, false)]
[InlineData(MetricReaderTemporalityPreference.Delta, true)]
[InlineData(MetricReaderTemporalityPreference.Delta, false)]
public void DuplicateInstrumentNamesFromDifferentMetersAreAllowed(MetricReaderTemporalityPreference temporality, bool hasView)
{
var exportedItems = new List<Metric>();
@ -411,7 +411,7 @@ namespace OpenTelemetry.Metrics.Tests
.AddMeter(meter2.Name)
.AddInMemoryExporter(exportedItems, metricReaderOptions =>
{
metricReaderOptions.Temporality = temporality;
metricReaderOptions.TemporalityPreference = temporality;
});
if (hasView)
@ -532,7 +532,7 @@ namespace OpenTelemetry.Metrics.Tests
.AddMeter(meter.Name)
.AddInMemoryExporter(exportedItems, metricReaderOptions =>
{
metricReaderOptions.Temporality = exportDelta ? AggregationTemporality.Delta : AggregationTemporality.Cumulative;
metricReaderOptions.TemporalityPreference = exportDelta ? MetricReaderTemporalityPreference.Delta : MetricReaderTemporalityPreference.Cumulative;
})
.Build();
@ -634,7 +634,7 @@ namespace OpenTelemetry.Metrics.Tests
.AddMeter(meter.Name)
.AddInMemoryExporter(exportedItems, metricReaderOptions =>
{
metricReaderOptions.Temporality = exportDelta ? AggregationTemporality.Delta : AggregationTemporality.Cumulative;
metricReaderOptions.TemporalityPreference = exportDelta ? MetricReaderTemporalityPreference.Delta : MetricReaderTemporalityPreference.Cumulative;
})
.Build();
@ -708,7 +708,7 @@ namespace OpenTelemetry.Metrics.Tests
.AddMeter(meter.Name)
.AddInMemoryExporter(exportedItems, metricReaderOptions =>
{
metricReaderOptions.Temporality = exportDelta ? AggregationTemporality.Delta : AggregationTemporality.Cumulative;
metricReaderOptions.TemporalityPreference = exportDelta ? MetricReaderTemporalityPreference.Delta : MetricReaderTemporalityPreference.Cumulative;
})
.Build();
@ -805,7 +805,7 @@ namespace OpenTelemetry.Metrics.Tests
.AddMeter(meter.Name)
.AddInMemoryExporter(exportedItems, metricReaderOptions =>
{
metricReaderOptions.Temporality = exportDelta ? AggregationTemporality.Delta : AggregationTemporality.Cumulative;
metricReaderOptions.TemporalityPreference = exportDelta ? MetricReaderTemporalityPreference.Delta : MetricReaderTemporalityPreference.Cumulative;
})
.AddView("requestCount", new MetricStreamConfiguration() { TagKeys = Array.Empty<string>() })
.Build();
@ -844,7 +844,7 @@ namespace OpenTelemetry.Metrics.Tests
.AddMeter(meter.Name)
.AddInMemoryExporter(exportedItems, metricReaderOptions =>
{
metricReaderOptions.Temporality = exportDelta ? AggregationTemporality.Delta : AggregationTemporality.Cumulative;
metricReaderOptions.TemporalityPreference = exportDelta ? MetricReaderTemporalityPreference.Delta : MetricReaderTemporalityPreference.Cumulative;
})
.Build();
@ -935,7 +935,7 @@ namespace OpenTelemetry.Metrics.Tests
.AddMeter(meter.Name)
.AddInMemoryExporter(exportedItems, metricReaderOptions =>
{
metricReaderOptions.Temporality = exportDelta ? AggregationTemporality.Delta : AggregationTemporality.Cumulative;
metricReaderOptions.TemporalityPreference = exportDelta ? MetricReaderTemporalityPreference.Delta : MetricReaderTemporalityPreference.Cumulative;
})
.Build();
@ -1014,9 +1014,9 @@ namespace OpenTelemetry.Metrics.Tests
}
[Theory]
[InlineData(AggregationTemporality.Cumulative)]
[InlineData(AggregationTemporality.Delta)]
public void TestInstrumentDisposal(AggregationTemporality temporality)
[InlineData(MetricReaderTemporalityPreference.Cumulative)]
[InlineData(MetricReaderTemporalityPreference.Delta)]
public void TestInstrumentDisposal(MetricReaderTemporalityPreference temporality)
{
var exportedItems = new List<Metric>();
@ -1029,7 +1029,7 @@ namespace OpenTelemetry.Metrics.Tests
.AddMeter(meter2.Name)
.AddInMemoryExporter(exportedItems, metricReaderOptions =>
{
metricReaderOptions.Temporality = temporality;
metricReaderOptions.TemporalityPreference = temporality;
})
.Build();
@ -1069,9 +1069,9 @@ namespace OpenTelemetry.Metrics.Tests
}
[Theory]
[InlineData(AggregationTemporality.Cumulative)]
[InlineData(AggregationTemporality.Delta)]
public void TestMetricPointCap(AggregationTemporality temporality)
[InlineData(MetricReaderTemporalityPreference.Cumulative)]
[InlineData(MetricReaderTemporalityPreference.Delta)]
public void TestMetricPointCap(MetricReaderTemporalityPreference temporality)
{
var exportedItems = new List<Metric>();
@ -1096,7 +1096,7 @@ namespace OpenTelemetry.Metrics.Tests
.AddMeter(meter.Name)
.AddInMemoryExporter(exportedItems, metricReaderOptions =>
{
metricReaderOptions.Temporality = temporality;
metricReaderOptions.TemporalityPreference = temporality;
})
.Build();

View File

@ -24,11 +24,11 @@ namespace OpenTelemetry.Metrics.Tests
public class MultipleReadersTests
{
[Theory]
[InlineData(AggregationTemporality.Delta, false)]
[InlineData(AggregationTemporality.Delta, true)]
[InlineData(AggregationTemporality.Cumulative, false)]
[InlineData(AggregationTemporality.Cumulative, true)]
public void SdkSupportsMultipleReaders(AggregationTemporality aggregationTemporality, bool hasViews)
[InlineData(MetricReaderTemporalityPreference.Delta, false)]
[InlineData(MetricReaderTemporalityPreference.Delta, true)]
[InlineData(MetricReaderTemporalityPreference.Cumulative, false)]
[InlineData(MetricReaderTemporalityPreference.Cumulative, true)]
public void SdkSupportsMultipleReaders(MetricReaderTemporalityPreference aggregationTemporality, bool hasViews)
{
var exportedItems1 = new List<Metric>();
var exportedItems2 = new List<Metric>();
@ -51,11 +51,11 @@ namespace OpenTelemetry.Metrics.Tests
.AddMeter(meter.Name)
.AddInMemoryExporter(exportedItems1, metricReaderOptions =>
{
metricReaderOptions.Temporality = AggregationTemporality.Delta;
metricReaderOptions.TemporalityPreference = MetricReaderTemporalityPreference.Delta;
})
.AddInMemoryExporter(exportedItems2, metricReaderOptions =>
{
metricReaderOptions.Temporality = aggregationTemporality;
metricReaderOptions.TemporalityPreference = aggregationTemporality;
});
if (hasViews)
@ -107,7 +107,7 @@ namespace OpenTelemetry.Metrics.Tests
// Check value exported for ObservableCounter
AssertLongSumValueForMetric(exportedItems1[2], 1000);
if (aggregationTemporality == AggregationTemporality.Delta)
if (aggregationTemporality == MetricReaderTemporalityPreference.Delta)
{
AssertLongSumValueForMetric(exportedItems2[2], 1200);
}
@ -128,7 +128,7 @@ namespace OpenTelemetry.Metrics.Tests
// Check value exported for Counter
AssertLongSumValueForMetric(exportedItems1[0], 15);
if (aggregationTemporality == AggregationTemporality.Delta)
if (aggregationTemporality == MetricReaderTemporalityPreference.Delta)
{
AssertLongSumValueForMetric(exportedItems2[0], 15);
}
@ -143,7 +143,7 @@ namespace OpenTelemetry.Metrics.Tests
// Check value exported for ObservableCounter
AssertLongSumValueForMetric(exportedItems1[2], 300);
if (aggregationTemporality == AggregationTemporality.Delta)
if (aggregationTemporality == MetricReaderTemporalityPreference.Delta)
{
AssertLongSumValueForMetric(exportedItems2[2], 200);
}