Skip to content

Commit

Permalink
Rename files
Browse files Browse the repository at this point in the history
  • Loading branch information
bjrara committed Dec 31, 2024
1 parent bdd661e commit ae89669
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT

package aggregation
package metrichandlers

import (
"context"
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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())
}
})
Expand All @@ -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())

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT

package prune
package metrichandlers

import (
"errors"
Expand All @@ -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()) {
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT

package prune
package metrichandlers

import (
"testing"
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand All @@ -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)
Expand Down
9 changes: 4 additions & 5 deletions plugins/processors/awsapplicationsignals/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -52,7 +51,7 @@ type awsapplicationsignalsprocessor struct {
metricMutators []attributesMutator
traceMutators []attributesMutator
limiter cardinalitycontrol.Limiter
aggregationMutator aggregation.AggregationMutator
aggregationMutator metrichandlers.AggregationMutator
stoppers []stopper
}

Expand All @@ -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
}
Expand Down

0 comments on commit ae89669

Please sign in to comment.