From ae89669d4f9bb09c81c5d466345486d87404ad44 Mon Sep 17 00:00:00 2001 From: Zhou Date: Fri, 13 Dec 2024 10:09:16 -0800 Subject: [PATCH] Rename files --- .../aggregation_mutator.go | 8 ++++---- .../aggregation_mutator_test.go | 11 +++++++---- .../metric_pruner.go => metrichandlers/pruner.go} | 10 +++++----- .../pruner_test.go} | 8 ++++---- plugins/processors/awsapplicationsignals/processor.go | 9 ++++----- 5 files changed, 24 insertions(+), 22 deletions(-) rename plugins/processors/awsapplicationsignals/internal/{aggregation => metrichandlers}/aggregation_mutator.go (91%) rename plugins/processors/awsapplicationsignals/internal/{aggregation => metrichandlers}/aggregation_mutator_test.go (92%) rename plugins/processors/awsapplicationsignals/internal/{prune/metric_pruner.go => metrichandlers/pruner.go} (84%) rename plugins/processors/awsapplicationsignals/internal/{prune/metric_pruner_test.go => metrichandlers/pruner_test.go} (96%) diff --git a/plugins/processors/awsapplicationsignals/internal/aggregation/aggregation_mutator.go b/plugins/processors/awsapplicationsignals/internal/metrichandlers/aggregation_mutator.go similarity index 91% rename from plugins/processors/awsapplicationsignals/internal/aggregation/aggregation_mutator.go rename to plugins/processors/awsapplicationsignals/internal/metrichandlers/aggregation_mutator.go index edb1e5ff13..7580168e30 100644 --- a/plugins/processors/awsapplicationsignals/internal/aggregation/aggregation_mutator.go +++ b/plugins/processors/awsapplicationsignals/internal/metrichandlers/aggregation_mutator.go @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: MIT -package aggregation +package metrichandlers import ( "context" @@ -17,16 +17,16 @@ const ( lastValueAggregation ) -// AggregationMutator is used to convert predefined ObservableUpDownCounter metrics to use LastValue aggregation. This +// AggregationMutator is used to convert predefined ObservableUpDownCounter metrics to use LastValue metrichandlers. This // is necessary for cases where metrics are instrumented as cumulative, yet reported with snapshot values. // // For example, metrics like DotNetGCGen0HeapSize may report values such as 1000, 2000, 1000, with cumulative temporality // When exporters, such as the EMF exporter, detect these as cumulative, they convert the values to deltas, // resulting in outputs like -, 1000, -1000, which misrepresent the data. // -// Normally, this issue could be resolved by configuring a view with LastValue aggregation within the SDK. +// Normally, this issue could be resolved by configuring a view with LastValue metrichandlers within the SDK. // However, since the view feature is not fully supported in .NET, this workaround implements the required -// conversion to LastValue aggregation to ensure accurate metric reporting. +// conversion to LastValue metrichandlers to ensure accurate metric reporting. // See https://github.com/open-telemetry/opentelemetry-dotnet/issues/2618. type AggregationMutator struct { includes map[string]aggregationType diff --git a/plugins/processors/awsapplicationsignals/internal/aggregation/aggregation_mutator_test.go b/plugins/processors/awsapplicationsignals/internal/metrichandlers/aggregation_mutator_test.go similarity index 92% rename from plugins/processors/awsapplicationsignals/internal/aggregation/aggregation_mutator_test.go rename to plugins/processors/awsapplicationsignals/internal/metrichandlers/aggregation_mutator_test.go index 0bcfb30a14..31f8f69cfa 100644 --- a/plugins/processors/awsapplicationsignals/internal/aggregation/aggregation_mutator_test.go +++ b/plugins/processors/awsapplicationsignals/internal/metrichandlers/aggregation_mutator_test.go @@ -1,9 +1,10 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: MIT -package aggregation +package metrichandlers import ( + "context" "testing" "github.com/stretchr/testify/assert" @@ -49,12 +50,14 @@ func TestAggregationMutator_ProcessMetrics(t *testing.T) { }, }, } + + ctx := context.Background() for _, tt := range tests { t.Run(tt.name, func(t1 *testing.T) { mutator := newAggregationMutatorWithConfig(tt.config) for _, m := range tt.metrics { - mutator.ProcessMetrics(nil, m, pcommon.NewMap()) + mutator.ProcessMetrics(ctx, m, pcommon.NewMap()) assert.Equal(t1, tt.expectedTemporality[m.Name()], m.Sum().AggregationTemporality()) } }) @@ -63,13 +66,13 @@ func TestAggregationMutator_ProcessMetrics(t *testing.T) { mutator := NewAggregationMutator() m := generateMetricWithSumAggregation("DotNetGCGen0HeapSize", pmetric.AggregationTemporalityCumulative) - mutator.ProcessMetrics(nil, m, pcommon.NewMap()) + mutator.ProcessMetrics(ctx, m, pcommon.NewMap()) assert.Equal(t, pmetric.MetricTypeSum, m.Type()) assert.Equal(t, pmetric.AggregationTemporalityDelta, m.Sum().AggregationTemporality()) m.SetEmptyHistogram() m.Histogram().SetAggregationTemporality(pmetric.AggregationTemporalityCumulative) - mutator.ProcessMetrics(nil, m, pcommon.NewMap()) + mutator.ProcessMetrics(ctx, m, pcommon.NewMap()) assert.Equal(t, pmetric.MetricTypeHistogram, m.Type()) assert.Equal(t, pmetric.AggregationTemporalityCumulative, m.Histogram().AggregationTemporality()) diff --git a/plugins/processors/awsapplicationsignals/internal/prune/metric_pruner.go b/plugins/processors/awsapplicationsignals/internal/metrichandlers/pruner.go similarity index 84% rename from plugins/processors/awsapplicationsignals/internal/prune/metric_pruner.go rename to plugins/processors/awsapplicationsignals/internal/metrichandlers/pruner.go index 31e5d5a048..acd342afc8 100644 --- a/plugins/processors/awsapplicationsignals/internal/prune/metric_pruner.go +++ b/plugins/processors/awsapplicationsignals/internal/metrichandlers/pruner.go @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: MIT -package prune +package metrichandlers import ( "errors" @@ -12,10 +12,10 @@ import ( "github.com/aws/amazon-cloudwatch-agent/plugins/processors/awsapplicationsignals/common" ) -type MetricPruner struct { +type Pruner struct { } -func (p *MetricPruner) ShouldBeDropped(attributes pcommon.Map) (bool, error) { +func (p *Pruner) ShouldBeDropped(attributes pcommon.Map) (bool, error) { for _, attributeKey := range common.CWMetricAttributes { if val, ok := attributes.Get(attributeKey); ok { if !isAsciiPrintable(val.Str()) { @@ -29,8 +29,8 @@ func (p *MetricPruner) ShouldBeDropped(attributes pcommon.Map) (bool, error) { return false, nil } -func NewPruner() *MetricPruner { - return &MetricPruner{} +func NewPruner() *Pruner { + return &Pruner{} } func isAsciiPrintable(val string) bool { diff --git a/plugins/processors/awsapplicationsignals/internal/prune/metric_pruner_test.go b/plugins/processors/awsapplicationsignals/internal/metrichandlers/pruner_test.go similarity index 96% rename from plugins/processors/awsapplicationsignals/internal/prune/metric_pruner_test.go rename to plugins/processors/awsapplicationsignals/internal/metrichandlers/pruner_test.go index 3f715b4e87..e88c6cd33d 100644 --- a/plugins/processors/awsapplicationsignals/internal/prune/metric_pruner_test.go +++ b/plugins/processors/awsapplicationsignals/internal/metrichandlers/pruner_test.go @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: MIT -package prune +package metrichandlers import ( "testing" @@ -41,7 +41,7 @@ func TestMetricPrunerWithIndexableAttribute(t *testing.T) { }, } - p := &MetricPruner{} + p := &Pruner{} for _, tt := range tests { attributes := pcommon.NewMap() attributes.PutStr(common.MetricAttributeTelemetrySource, "UnitTest") @@ -72,7 +72,7 @@ func TestMetricPrunerWithNonIndexableAttribute(t *testing.T) { }, } - p := &MetricPruner{} + p := &Pruner{} for _, tt := range tests { attributes := pcommon.NewMap() attributes.PutStr(common.MetricAttributeTelemetrySource, "UnitTest") @@ -99,7 +99,7 @@ func TestMetricPrunerWithNoTelemetrySourceAttribute(t *testing.T) { }, } - p := &MetricPruner{} + p := &Pruner{} for _, tt := range tests { attributes := pcommon.NewMap() attributes.PutStr(common.AttributeEC2InstanceId, tt.val) diff --git a/plugins/processors/awsapplicationsignals/processor.go b/plugins/processors/awsapplicationsignals/processor.go index c4a17a52a9..adc85f6bcb 100644 --- a/plugins/processors/awsapplicationsignals/processor.go +++ b/plugins/processors/awsapplicationsignals/processor.go @@ -16,10 +16,9 @@ import ( "golang.org/x/text/language" appsignalsconfig "github.com/aws/amazon-cloudwatch-agent/plugins/processors/awsapplicationsignals/config" - "github.com/aws/amazon-cloudwatch-agent/plugins/processors/awsapplicationsignals/internal/aggregation" "github.com/aws/amazon-cloudwatch-agent/plugins/processors/awsapplicationsignals/internal/cardinalitycontrol" + "github.com/aws/amazon-cloudwatch-agent/plugins/processors/awsapplicationsignals/internal/metrichandlers" "github.com/aws/amazon-cloudwatch-agent/plugins/processors/awsapplicationsignals/internal/normalizer" - "github.com/aws/amazon-cloudwatch-agent/plugins/processors/awsapplicationsignals/internal/prune" "github.com/aws/amazon-cloudwatch-agent/plugins/processors/awsapplicationsignals/internal/resolver" "github.com/aws/amazon-cloudwatch-agent/plugins/processors/awsapplicationsignals/rules" ) @@ -52,7 +51,7 @@ type awsapplicationsignalsprocessor struct { metricMutators []attributesMutator traceMutators []attributesMutator limiter cardinalitycontrol.Limiter - aggregationMutator aggregation.AggregationMutator + aggregationMutator metrichandlers.AggregationMutator stoppers []stopper } @@ -78,12 +77,12 @@ func (ap *awsapplicationsignalsprocessor) StartMetrics(ctx context.Context, _ co ap.replaceActions = rules.NewReplacer(ap.config.Rules, !limiterConfig.Disabled) - pruner := prune.NewPruner() + pruner := metrichandlers.NewPruner() keeper := rules.NewKeeper(ap.config.Rules, !limiterConfig.Disabled) dropper := rules.NewDropper(ap.config.Rules) ap.allowlistMutators = []allowListMutator{pruner, keeper, dropper} - ap.aggregationMutator = aggregation.NewAggregationMutator() + ap.aggregationMutator = metrichandlers.NewAggregationMutator() return nil }