From 7ce0c55260ab563e09923933f2ef44c0497aa97d Mon Sep 17 00:00:00 2001 From: Mikel Blanchard Date: Wed, 28 Feb 2024 11:15:13 -0800 Subject: [PATCH] [sdk-metrics] Refactor duplicated update completion code into a helper in MetricPoint (#5398) --- src/OpenTelemetry/Metrics/MetricPoint.cs | 94 +++++++----------------- 1 file changed, 26 insertions(+), 68 deletions(-) diff --git a/src/OpenTelemetry/Metrics/MetricPoint.cs b/src/OpenTelemetry/Metrics/MetricPoint.cs index d9a3eef3a98..8f2f3440c63 100644 --- a/src/OpenTelemetry/Metrics/MetricPoint.cs +++ b/src/OpenTelemetry/Metrics/MetricPoint.cs @@ -445,23 +445,7 @@ internal void Update(long number) } } - // There is a race with Snapshot: - // Update() updates the value - // Snapshot snapshots the value - // Snapshot sets status to NoCollectPending - // Update sets status to CollectPending -- this is not right as the Snapshot - // already included the updated value. - // In the absence of any new Update call until next Snapshot, - // this results in exporting an Update even though - // it had no update. - // TODO: For Delta, this can be mitigated - // by ignoring Zero points - this.MetricPointStatus = MetricPointStatus.CollectPending; - - if (this.aggregatorStore.OutputDeltaWithUnusedMetricPointReclaimEnabled) - { - Interlocked.Decrement(ref this.ReferenceCount); - } + this.CompleteUpdate(); } internal void UpdateWithExemplar(long number, ReadOnlySpan> tags, bool isSampled) @@ -573,23 +557,7 @@ internal void UpdateWithExemplar(long number, ReadOnlySpan> tags, bool isSampled) @@ -785,23 +737,7 @@ internal void UpdateWithExemplar(double number, ReadOnlySpan