Skip to content

Commit

Permalink
Move entity field removal logic
Browse files Browse the repository at this point in the history
  • Loading branch information
duhminick committed Jan 9, 2025
1 parent 5845e15 commit bf33217
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
5 changes: 5 additions & 0 deletions exporter/awsemfexporter/datapoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"math"
"strconv"
"strings"
"time"

"go.opentelemetry.io/collector/pdata/pcommon"
Expand All @@ -18,6 +19,7 @@ import (
)

const (
AWSEntityPrefix = "com.amazonaws.cloudwatch.entity.internal."
summaryCountSuffix = "_count"
summarySumSuffix = "_sum"
)
Expand Down Expand Up @@ -534,6 +536,9 @@ func createLabels(attributes pcommon.Map) map[string]string {
labels[k] = v.AsString()
return true
})
attributes.RemoveIf(func(k string, _ pcommon.Value) bool {
return strings.HasPrefix(k, AWSEntityPrefix)
})

return labels
}
Expand Down
10 changes: 0 additions & 10 deletions exporter/awsemfexporter/emf_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ import (
)

const (
AWSEntityPrefix = "com.amazonaws.cloudwatch.entity.internal."

// OutputDestination Options
outputDestinationCloudWatch = "cloudwatch"
outputDestinationStdout = "stdout"
Expand Down Expand Up @@ -93,7 +91,6 @@ func (emf *emfExporter) pushMetricsData(_ context.Context, md pmetric.Metrics) e
for i := 0; i < rms.Len(); i++ {
rm := rms.At(i)
am := rm.Resource().Attributes()
removeEntityFields(am)
if am.Len() > 0 {
am.Range(func(k string, v pcommon.Value) bool {
labels[k] = v.Str()
Expand Down Expand Up @@ -248,10 +245,3 @@ func wrapErrorIfBadRequest(err error) error {
}
return err
}

// removeEntityFields so that it is not tagged as a dimension, and reduces the size of the PMD payload.
func removeEntityFields(mutableResourceAttributes pcommon.Map) {
mutableResourceAttributes.RemoveIf(func(s string, _ pcommon.Value) bool {
return strings.HasPrefix(s, AWSEntityPrefix)
})
}

0 comments on commit bf33217

Please sign in to comment.