Skip to content

Commit

Permalink
MetricPoint start and end time as Properties (#2703)
Browse files Browse the repository at this point in the history
  • Loading branch information
cijothomas authored Nov 30, 2021
1 parent a828aa7 commit 1cb9da5
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 28 deletions.
4 changes: 2 additions & 2 deletions src/OpenTelemetry.Exporter.Console/ConsoleMetricExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,9 @@ public override ExportResult Export(in Batch<Metric> 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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())
Expand Down
4 changes: 2 additions & 2 deletions src/OpenTelemetry/.publicApi/net461/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions src/OpenTelemetry/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
24 changes: 18 additions & 6 deletions src/OpenTelemetry/Metrics/MetricPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -70,11 +68,25 @@ internal MetricPoint(
/// </summary>
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()
{
Expand Down

0 comments on commit 1cb9da5

Please sign in to comment.