From 1cb9da5e41de0fedecb46ad0128b043b7ff873a8 Mon Sep 17 00:00:00 2001 From: Cijo Thomas Date: Mon, 29 Nov 2021 20:41:27 -0800 Subject: [PATCH] MetricPoint start and end time as Properties (#2703) --- .../ConsoleMetricExporter.cs | 4 ++-- .../Implementation/MetricItemExtensions.cs | 20 ++++++++-------- .../Implementation/PrometheusSerializerExt.cs | 4 ++-- .../.publicApi/net461/PublicAPI.Unshipped.txt | 4 ++-- .../netstandard2.0/PublicAPI.Unshipped.txt | 4 ++-- src/OpenTelemetry/CHANGELOG.md | 7 +++--- src/OpenTelemetry/Metrics/MetricPoint.cs | 24 ++++++++++++++----- 7 files changed, 39 insertions(+), 28 deletions(-) diff --git a/src/OpenTelemetry.Exporter.Console/ConsoleMetricExporter.cs b/src/OpenTelemetry.Exporter.Console/ConsoleMetricExporter.cs index 9ec0747555..cd045f089d 100644 --- a/src/OpenTelemetry.Exporter.Console/ConsoleMetricExporter.cs +++ b/src/OpenTelemetry.Exporter.Console/ConsoleMetricExporter.cs @@ -161,9 +161,9 @@ public override ExportResult Export(in Batch batch) msg = new StringBuilder(); msg.Append('('); - msg.Append(metricPoint.GetStartTime().ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ", CultureInfo.InvariantCulture)); + msg.Append(metricPoint.StartTime.ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ", CultureInfo.InvariantCulture)); msg.Append(", "); - msg.Append(metricPoint.GetEndTime().ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ", CultureInfo.InvariantCulture)); + msg.Append(metricPoint.EndTime.ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ", CultureInfo.InvariantCulture)); msg.Append("] "); msg.Append(tags); if (tags != string.Empty) diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/MetricItemExtensions.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/MetricItemExtensions.cs index 7f570b63f2..5ec44df3c1 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/MetricItemExtensions.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/MetricItemExtensions.cs @@ -152,8 +152,8 @@ internal static OtlpMetrics.Metric ToOtlpMetric(this Metric metric) { var dataPoint = new OtlpMetrics.NumberDataPoint { - StartTimeUnixNano = (ulong)metricPoint.GetStartTime().ToUnixTimeNanoseconds(), - TimeUnixNano = (ulong)metricPoint.GetEndTime().ToUnixTimeNanoseconds(), + StartTimeUnixNano = (ulong)metricPoint.StartTime.ToUnixTimeNanoseconds(), + TimeUnixNano = (ulong)metricPoint.EndTime.ToUnixTimeNanoseconds(), }; AddAttributes(metricPoint.Tags, dataPoint.Attributes); @@ -176,8 +176,8 @@ internal static OtlpMetrics.Metric ToOtlpMetric(this Metric metric) { var dataPoint = new OtlpMetrics.NumberDataPoint { - StartTimeUnixNano = (ulong)metricPoint.GetStartTime().ToUnixTimeNanoseconds(), - TimeUnixNano = (ulong)metricPoint.GetEndTime().ToUnixTimeNanoseconds(), + StartTimeUnixNano = (ulong)metricPoint.StartTime.ToUnixTimeNanoseconds(), + TimeUnixNano = (ulong)metricPoint.EndTime.ToUnixTimeNanoseconds(), }; AddAttributes(metricPoint.Tags, dataPoint.Attributes); @@ -197,8 +197,8 @@ internal static OtlpMetrics.Metric ToOtlpMetric(this Metric metric) { var dataPoint = new OtlpMetrics.NumberDataPoint { - StartTimeUnixNano = (ulong)metricPoint.GetStartTime().ToUnixTimeNanoseconds(), - TimeUnixNano = (ulong)metricPoint.GetEndTime().ToUnixTimeNanoseconds(), + StartTimeUnixNano = (ulong)metricPoint.StartTime.ToUnixTimeNanoseconds(), + TimeUnixNano = (ulong)metricPoint.EndTime.ToUnixTimeNanoseconds(), }; AddAttributes(metricPoint.Tags, dataPoint.Attributes); @@ -218,8 +218,8 @@ internal static OtlpMetrics.Metric ToOtlpMetric(this Metric metric) { var dataPoint = new OtlpMetrics.NumberDataPoint { - StartTimeUnixNano = (ulong)metricPoint.GetStartTime().ToUnixTimeNanoseconds(), - TimeUnixNano = (ulong)metricPoint.GetEndTime().ToUnixTimeNanoseconds(), + StartTimeUnixNano = (ulong)metricPoint.StartTime.ToUnixTimeNanoseconds(), + TimeUnixNano = (ulong)metricPoint.EndTime.ToUnixTimeNanoseconds(), }; AddAttributes(metricPoint.Tags, dataPoint.Attributes); @@ -241,8 +241,8 @@ internal static OtlpMetrics.Metric ToOtlpMetric(this Metric metric) { var dataPoint = new OtlpMetrics.HistogramDataPoint { - StartTimeUnixNano = (ulong)metricPoint.GetStartTime().ToUnixTimeNanoseconds(), - TimeUnixNano = (ulong)metricPoint.GetEndTime().ToUnixTimeNanoseconds(), + StartTimeUnixNano = (ulong)metricPoint.StartTime.ToUnixTimeNanoseconds(), + TimeUnixNano = (ulong)metricPoint.EndTime.ToUnixTimeNanoseconds(), }; AddAttributes(metricPoint.Tags, dataPoint.Attributes); diff --git a/src/OpenTelemetry.Exporter.Prometheus/Implementation/PrometheusSerializerExt.cs b/src/OpenTelemetry.Exporter.Prometheus/Implementation/PrometheusSerializerExt.cs index 9f8c2dc426..226c45ad55 100644 --- a/src/OpenTelemetry.Exporter.Prometheus/Implementation/PrometheusSerializerExt.cs +++ b/src/OpenTelemetry.Exporter.Prometheus/Implementation/PrometheusSerializerExt.cs @@ -43,7 +43,7 @@ public static int WriteMetric(byte[] buffer, int cursor, Metric metric) foreach (ref var metricPoint in metric.GetMetricPoints()) { var tags = metricPoint.Tags; - var timestamp = metricPoint.GetEndTime().ToUnixTimeMilliseconds(); + var timestamp = metricPoint.EndTime.ToUnixTimeMilliseconds(); // Counter and Gauge cursor = WriteMetricName(buffer, cursor, metric.Name, metric.Unit); @@ -106,7 +106,7 @@ public static int WriteMetric(byte[] buffer, int cursor, Metric metric) foreach (ref var metricPoint in metric.GetMetricPoints()) { var tags = metricPoint.Tags; - var timestamp = metricPoint.GetEndTime().ToUnixTimeMilliseconds(); + var timestamp = metricPoint.EndTime.ToUnixTimeMilliseconds(); long totalCount = 0; foreach (var histogramMeasurement in metricPoint.GetHistogramBuckets()) diff --git a/src/OpenTelemetry/.publicApi/net461/PublicAPI.Unshipped.txt b/src/OpenTelemetry/.publicApi/net461/PublicAPI.Unshipped.txt index 8e88730f63..6d96498598 100644 --- a/src/OpenTelemetry/.publicApi/net461/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry/.publicApi/net461/PublicAPI.Unshipped.txt @@ -20,13 +20,13 @@ OpenTelemetry.Metrics.HistogramBuckets.Enumerator.Current.get -> OpenTelemetry.M OpenTelemetry.Metrics.HistogramBuckets.Enumerator.Enumerator() -> void OpenTelemetry.Metrics.HistogramBuckets.Enumerator.MoveNext() -> bool OpenTelemetry.Metrics.HistogramBuckets.GetEnumerator() -> OpenTelemetry.Metrics.HistogramBuckets.Enumerator +OpenTelemetry.Metrics.MetricPoint.EndTime.get -> System.DateTimeOffset OpenTelemetry.Metrics.MetricPoint.GetSumDouble() -> double OpenTelemetry.Metrics.MetricPoint.GetSumLong() -> long -OpenTelemetry.Metrics.MetricPoint.GetEndTime() -> System.DateTimeOffset OpenTelemetry.Metrics.MetricPoint.GetGaugeLastValueDouble() -> double OpenTelemetry.Metrics.MetricPoint.GetGaugeLastValueLong() -> long OpenTelemetry.Metrics.MetricPoint.GetHistogramBuckets() -> OpenTelemetry.Metrics.HistogramBuckets -OpenTelemetry.Metrics.MetricPoint.GetStartTime() -> System.DateTimeOffset +OpenTelemetry.Metrics.MetricPoint.StartTime.get -> System.DateTimeOffset OpenTelemetry.Metrics.MetricPointsAccessor OpenTelemetry.Metrics.MetricPointsAccessor.MetricPointsAccessor() -> void OpenTelemetry.Metrics.MetricPointsAccessor.Enumerator diff --git a/src/OpenTelemetry/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt b/src/OpenTelemetry/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt index 8e88730f63..6d96498598 100644 --- a/src/OpenTelemetry/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt @@ -20,13 +20,13 @@ OpenTelemetry.Metrics.HistogramBuckets.Enumerator.Current.get -> OpenTelemetry.M OpenTelemetry.Metrics.HistogramBuckets.Enumerator.Enumerator() -> void OpenTelemetry.Metrics.HistogramBuckets.Enumerator.MoveNext() -> bool OpenTelemetry.Metrics.HistogramBuckets.GetEnumerator() -> OpenTelemetry.Metrics.HistogramBuckets.Enumerator +OpenTelemetry.Metrics.MetricPoint.EndTime.get -> System.DateTimeOffset OpenTelemetry.Metrics.MetricPoint.GetSumDouble() -> double OpenTelemetry.Metrics.MetricPoint.GetSumLong() -> long -OpenTelemetry.Metrics.MetricPoint.GetEndTime() -> System.DateTimeOffset OpenTelemetry.Metrics.MetricPoint.GetGaugeLastValueDouble() -> double OpenTelemetry.Metrics.MetricPoint.GetGaugeLastValueLong() -> long OpenTelemetry.Metrics.MetricPoint.GetHistogramBuckets() -> OpenTelemetry.Metrics.HistogramBuckets -OpenTelemetry.Metrics.MetricPoint.GetStartTime() -> System.DateTimeOffset +OpenTelemetry.Metrics.MetricPoint.StartTime.get -> System.DateTimeOffset OpenTelemetry.Metrics.MetricPointsAccessor OpenTelemetry.Metrics.MetricPointsAccessor.MetricPointsAccessor() -> void OpenTelemetry.Metrics.MetricPointsAccessor.Enumerator diff --git a/src/OpenTelemetry/CHANGELOG.md b/src/OpenTelemetry/CHANGELOG.md index 7ff4abb2f1..e7aa0ad596 100644 --- a/src/OpenTelemetry/CHANGELOG.md +++ b/src/OpenTelemetry/CHANGELOG.md @@ -28,10 +28,9 @@ * Refactored temporality setting to align with the latest spec. ([#2666](https://github.com/open-telemetry/opentelemetry-dotnet/pull/2666)) -* Removed the public properties `LongValue`, `DoubleValue`, `StartTime`, and - `EndTime` in favor of their counterpart public methods `GetSumLong`, - `GetSumDouble`, `GetGaugeLastValueLong`, `GetGaugeLastValueDouble`, - `GetStartTime`, and `GetEndTime`. +* Removed the public properties `LongValue`, `DoubleValue`, in favor of their + counterpart public methods `GetSumLong`, `GetSumDouble`, + `GetGaugeLastValueLong`, `GetGaugeLastValueDouble`. ([#2667](https://github.com/open-telemetry/opentelemetry-dotnet/pull/2667)) * MetricType modified to reserve bits for future types. diff --git a/src/OpenTelemetry/Metrics/MetricPoint.cs b/src/OpenTelemetry/Metrics/MetricPoint.cs index 4d48c23551..c8b88755a1 100644 --- a/src/OpenTelemetry/Metrics/MetricPoint.cs +++ b/src/OpenTelemetry/Metrics/MetricPoint.cs @@ -16,15 +16,13 @@ using System; using System.Diagnostics; +using System.Runtime.CompilerServices; using System.Threading; namespace OpenTelemetry.Metrics { public struct MetricPoint { - internal DateTimeOffset StartTime; - internal DateTimeOffset EndTime; - private readonly AggregationType aggType; private readonly HistogramBuckets histogramBuckets; @@ -70,11 +68,25 @@ internal MetricPoint( /// public ReadOnlyTagCollection Tags { get; } - internal MetricPointStatus MetricPointStatus { get; private set; } + public DateTimeOffset StartTime + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get; - public DateTimeOffset GetStartTime() => this.StartTime; + [MethodImpl(MethodImplOptions.AggressiveInlining)] + internal set; + } - public DateTimeOffset GetEndTime() => this.EndTime; + public DateTimeOffset EndTime + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + internal set; + } + + internal MetricPointStatus MetricPointStatus { get; private set; } public long GetSumLong() {