From abea4b60f6b176a0beadea8b3e789f0dd2c2e3ee Mon Sep 17 00:00:00 2001 From: Utkarsh Umesan Pillai Date: Mon, 7 Mar 2022 20:29:17 -0800 Subject: [PATCH] Minor refactoring (#2987) Co-authored-by: Cijo Thomas --- src/OpenTelemetry/Metrics/AggregatorStore.cs | 10 ++++------ .../Metrics/PeriodicExportingMetricReader.cs | 8 ++++---- test/Benchmarks/Metrics/HistogramBenchmarks.cs | 1 - 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/OpenTelemetry/Metrics/AggregatorStore.cs b/src/OpenTelemetry/Metrics/AggregatorStore.cs index d3e0842bb..f087f10f5 100644 --- a/src/OpenTelemetry/Metrics/AggregatorStore.cs +++ b/src/OpenTelemetry/Metrics/AggregatorStore.cs @@ -33,7 +33,6 @@ namespace OpenTelemetry.Metrics private readonly ConcurrentDictionary tagsToMetricPointIndexDictionary = new ConcurrentDictionary(); - private readonly AggregationTemporality temporality; private readonly string name; private readonly string metricPointCapHitMessage; private readonly bool outputDelta; @@ -65,8 +64,7 @@ namespace OpenTelemetry.Metrics this.metricPoints = new MetricPoint[maxMetricPoints]; this.currentMetricPointBatch = new int[maxMetricPoints]; this.aggType = aggType; - this.temporality = temporality; - this.outputDelta = temporality == AggregationTemporality.Delta ? true : false; + this.outputDelta = temporality == AggregationTemporality.Delta; this.histogramBounds = histogramBounds; this.startTimeExclusive = DateTimeOffset.UtcNow; if (tagKeysInteresting == null) @@ -102,7 +100,7 @@ namespace OpenTelemetry.Metrics { this.batchSize = 0; var indexSnapshot = Math.Min(this.metricPointIndex, this.maxMetricPoints - 1); - if (this.temporality == AggregationTemporality.Delta) + if (this.outputDelta) { this.SnapshotDelta(indexSnapshot); } @@ -125,7 +123,7 @@ namespace OpenTelemetry.Metrics continue; } - metricPoint.TakeSnapshot(this.outputDelta); + metricPoint.TakeSnapshot(outputDelta: true); this.currentMetricPointBatch[this.batchSize] = i; this.batchSize++; } @@ -146,7 +144,7 @@ namespace OpenTelemetry.Metrics continue; } - metricPoint.TakeSnapshot(this.outputDelta); + metricPoint.TakeSnapshot(outputDelta: false); this.currentMetricPointBatch[this.batchSize] = i; this.batchSize++; } diff --git a/src/OpenTelemetry/Metrics/PeriodicExportingMetricReader.cs b/src/OpenTelemetry/Metrics/PeriodicExportingMetricReader.cs index 9c4803e39..dd7546984 100644 --- a/src/OpenTelemetry/Metrics/PeriodicExportingMetricReader.cs +++ b/src/OpenTelemetry/Metrics/PeriodicExportingMetricReader.cs @@ -111,14 +111,14 @@ namespace OpenTelemetry.Metrics private void ExporterProc() { - var sw = Stopwatch.StartNew(); + int index; + int timeout; var triggers = new WaitHandle[] { this.exportTrigger, this.shutdownTrigger }; + var sw = Stopwatch.StartNew(); while (true) { - var timeout = (int)(this.exportIntervalMilliseconds - (sw.ElapsedMilliseconds % this.exportIntervalMilliseconds)); - - int index; + timeout = (int)(this.exportIntervalMilliseconds - (sw.ElapsedMilliseconds % this.exportIntervalMilliseconds)); try { diff --git a/test/Benchmarks/Metrics/HistogramBenchmarks.cs b/test/Benchmarks/Metrics/HistogramBenchmarks.cs index 4bf98b164..656c3a1ad 100644 --- a/test/Benchmarks/Metrics/HistogramBenchmarks.cs +++ b/test/Benchmarks/Metrics/HistogramBenchmarks.cs @@ -18,7 +18,6 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.Diagnostics.Metrics; -using System.Threading; using BenchmarkDotNet.Attributes; using OpenTelemetry; using OpenTelemetry.Metrics;