From d71e1149ccac765ee93f7fa44e8af2d0ccc65f9a Mon Sep 17 00:00:00 2001 From: Reiley Yang Date: Fri, 15 Oct 2021 21:15:28 -0700 Subject: [PATCH 1/2] Simplify code --- .../Metrics/DropConfiguration.cs | 35 ------------------- .../Metrics/MetricStreamConfiguration.cs | 9 +++++ 2 files changed, 9 insertions(+), 35 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 { } + } + } } } From 4d560cfa7fab431c8bbdcd5d0f229016f93a0c15 Mon Sep 17 00:00:00 2001 From: Reiley Yang Date: Sun, 17 Oct 2021 18:54:55 -0700 Subject: [PATCH 2/2] update test case --- test/OpenTelemetry.Tests/Metrics/MetricViewTests.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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