From 84bdf38fe1b4ce39b49c0a8564a72b50daeb687b Mon Sep 17 00:00:00 2001 From: Reiley Yang Date: Mon, 18 Oct 2021 10:12:08 -0700 Subject: [PATCH] Simplify code (#2491) --- .../Metrics/DropConfiguration.cs | 35 ------------------- .../Metrics/MetricStreamConfiguration.cs | 9 +++++ .../Metrics/MetricViewTests.cs | 3 +- 3 files changed, 11 insertions(+), 36 deletions(-) delete mode 100644 src/OpenTelemetry/Metrics/DropConfiguration.cs diff --git a/src/OpenTelemetry/Metrics/DropConfiguration.cs b/src/OpenTelemetry/Metrics/DropConfiguration.cs deleted file mode 100644 index 1245367219e..00000000000 --- a/src/OpenTelemetry/Metrics/DropConfiguration.cs +++ /dev/null @@ -1,35 +0,0 @@ -// -// 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. -// - -using System; - -namespace OpenTelemetry.Metrics -{ - internal class DropConfiguration : MetricStreamConfiguration - { - private Aggregation aggregation = Aggregation.Drop; - - public override Aggregation Aggregation - { - get => this.aggregation; - - set - { - throw new ArgumentException($"Aggregation cannot be set."); - } - } - } -} diff --git a/src/OpenTelemetry/Metrics/MetricStreamConfiguration.cs b/src/OpenTelemetry/Metrics/MetricStreamConfiguration.cs index 3b60abe8bfa..4e5140510a0 100644 --- a/src/OpenTelemetry/Metrics/MetricStreamConfiguration.cs +++ b/src/OpenTelemetry/Metrics/MetricStreamConfiguration.cs @@ -41,5 +41,14 @@ public class MetricStreamConfiguration public virtual Aggregation Aggregation { get; set; } // TODO: MetricPoints caps can be configured here + + private sealed class DropConfiguration : MetricStreamConfiguration + { + public override Aggregation Aggregation + { + get => Aggregation.Drop; + set { } + } + } } } diff --git a/test/OpenTelemetry.Tests/Metrics/MetricViewTests.cs b/test/OpenTelemetry.Tests/Metrics/MetricViewTests.cs index 7a825252513..c426e84b6c9 100644 --- a/test/OpenTelemetry.Tests/Metrics/MetricViewTests.cs +++ b/test/OpenTelemetry.Tests/Metrics/MetricViewTests.cs @@ -370,7 +370,8 @@ public void ViewToDropAndRetainInstrument() [Fact] public void MetricStreamConfigurationForDropMustNotAllowOverriding() { - Assert.Throws(() => MetricStreamConfiguration.Drop.Aggregation = Aggregation.Histogram); + MetricStreamConfiguration.Drop.Aggregation = Aggregation.Histogram; + Assert.Equal(Aggregation.Drop, MetricStreamConfiguration.Drop.Aggregation); } } #pragma warning restore SA1000 // KeywordsMustBeSpacedCorrectly