Simplify code (#2491)

This commit is contained in:
Reiley Yang 2021-10-18 10:12:08 -07:00 committed by GitHub
parent d119447e07
commit 84bdf38fe1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 36 deletions

View File

@ -1,35 +0,0 @@
// <copyright file="DropConfiguration.cs" company="OpenTelemetry Authors">
// 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.
// </copyright>
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.");
}
}
}
}

View File

@ -41,5 +41,14 @@ namespace OpenTelemetry.Metrics
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 { }
}
}
}
}

View File

@ -370,7 +370,8 @@ namespace OpenTelemetry.Metrics.Tests
[Fact]
public void MetricStreamConfigurationForDropMustNotAllowOverriding()
{
Assert.Throws<ArgumentException>(() => MetricStreamConfiguration.Drop.Aggregation = Aggregation.Histogram);
MetricStreamConfiguration.Drop.Aggregation = Aggregation.Histogram;
Assert.Equal(Aggregation.Drop, MetricStreamConfiguration.Drop.Aggregation);
}
}
#pragma warning restore SA1000 // KeywordsMustBeSpacedCorrectly