Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove high-cardinality attribute from AWS Container Insight metrics #37697

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
change_type: breaking

component: awscontainerinsightreceiver

note: Remove high cardinality attribute `Timestamp` from metrics generated by `awscontainerinsightreceiver`

issues: [35861]

change_logs: [user, api]
10 changes: 6 additions & 4 deletions internal/aws/containerinsight/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"log"
"strconv"
"strings"
"time"

"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/pmetric"
Expand Down Expand Up @@ -154,7 +153,9 @@ func GetUnitForMetric(metric string) string {
return metricToUnitMap[metric]
}

// ConvertToOTLPMetrics converts a field containing metric values and a tag containing the relevant labels to OTLP metrics
// ConvertToOTLPMetrics converts a field containing metric values and tags containing the relevant labels to OTLP metrics.
// For legacy reasons, the timestamp is stored in the tags map with the key "Timestamp", but, unlike other tags,
// it is not added as a resource attribute to avoid high-cardinality metrics.
func ConvertToOTLPMetrics(fields map[string]any, tags map[string]string, logger *zap.Logger) pmetric.Metrics {
md := pmetric.NewMetrics()
rms := md.ResourceMetrics()
Expand All @@ -166,8 +167,9 @@ func ConvertToOTLPMetrics(fields map[string]any, tags map[string]string, logger
if tagKey == Timestamp {
timeNs, _ := strconv.ParseUint(tagValue, 10, 64)
timestamp = pcommon.Timestamp(timeNs)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

timestamp is added to the data point itself, so it still needs to be calculated

// convert from nanosecond to millisecond (as emf log use millisecond timestamp)
tagValue = strconv.FormatUint(timeNs/uint64(time.Millisecond), 10)

// Do not add Timestamp as a resource attribute to avoid high-cardinality.
continue
}
resource.Attributes().PutStr(tagKey, tagValue)
}
Expand Down
14 changes: 10 additions & 4 deletions internal/aws/containerinsight/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,16 +140,22 @@ func checkMetricsAreExpected(t *testing.T, md pmetric.Metrics, fields map[string
// check the attributes are expected
rm := rms.At(0)
attributes := rm.Resource().Attributes()
assert.Equal(t, len(tags), attributes.Len())
assert.Equal(t, len(tags)-1, attributes.Len()) // tags has Timestamp but attributes should not have it
var timeUnixNano uint64
for key, val := range tags {
log.Printf("key=%v value=%v", key, val)
attr, ok := attributes.Get(key)
assert.True(t, ok)
if key == Timestamp {
timeUnixNano, _ = strconv.ParseUint(val, 10, 64)
val = strconv.FormatUint(timeUnixNano/uint64(time.Millisecond), 10)
// Capture the timestamp for later check.
var err error
timeUnixNano, err = strconv.ParseUint(val, 10, 64)
assert.NoError(t, err)

// Timestamp is passed on tags but should NOT be in attributes.
assert.False(t, ok)
continue
}
assert.True(t, ok)
assert.Equal(t, val, attr.Str())
}

Expand Down
14 changes: 0 additions & 14 deletions receiver/awscontainerinsightreceiver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,6 @@ kubectl apply -f config.yaml
| ClusterName |
| NodeName |
| Type |
| Timestamp |
| Version |
| Sources |

Expand All @@ -362,7 +361,6 @@ kubectl apply -f config.yaml
| NodeName |
| Namespace |
| Type |
| Timestamp |
| Version |
| Sources |
| kubernete |
Expand All @@ -384,7 +382,6 @@ kubectl apply -f config.yaml
| Namespace |
| Service |
| Type |
| Timestamp |
| Version |
| Sources |
| kubernete |
Expand Down Expand Up @@ -437,7 +434,6 @@ kubectl apply -f config.yaml
| ClusterName |
| InstanceType |
| NodeName |
| Timestamp |
| Type |
| Version |
| Sources |
Expand Down Expand Up @@ -468,7 +464,6 @@ kubectl apply -f config.yaml
| InstanceId |
| InstanceType |
| NodeName |
| Timestamp |
| EBSVolumeId |
| device |
| Type |
Expand Down Expand Up @@ -496,7 +491,6 @@ kubectl apply -f config.yaml
| InstanceId |
| InstanceType |
| NodeName |
| Timestamp |
| EBSVolumeId |
| device |
| fstype |
Expand Down Expand Up @@ -528,7 +522,6 @@ kubectl apply -f config.yaml
| InstanceId |
| InstanceType |
| NodeName |
| Timestamp |
| Type |
| Version |
| interface |
Expand Down Expand Up @@ -588,7 +581,6 @@ kubectl apply -f config.yaml
| Namespace |
| NodeName |
| PodId |
| Timestamp |
| Type |
| Version |
| Sources |
Expand Down Expand Up @@ -621,7 +613,6 @@ kubectl apply -f config.yaml
| Namespace |
| NodeName |
| PodId |
| Timestamp |
| Type |
| Version |
| interface |
Expand Down Expand Up @@ -672,7 +663,6 @@ kubectl apply -f config.yaml
| Namespace |
| NodeName |
| PodId |
| Timestamp |
| Type |
| Version |
| Sources |
Expand Down Expand Up @@ -779,7 +769,6 @@ To deploy to an ECS cluster check this [doc](https://aws-otel.github.io/docs/set
| ClusterName |
| InstanceType |
| AutoScalingGroupName |
| Timestamp |
| Type |
| Version |
| Sources |
Expand Down Expand Up @@ -810,7 +799,6 @@ To deploy to an ECS cluster check this [doc](https://aws-otel.github.io/docs/set
| ClusterName |
| InstanceType |
| AutoScalingGroupName |
| Timestamp |
| Type |
| Version |
| Sources |
Expand All @@ -837,7 +825,6 @@ To deploy to an ECS cluster check this [doc](https://aws-otel.github.io/docs/set
| ClusterName |
| InstanceType |
| AutoScalingGroupName |
| Timestamp |
| Type |
| Version |
| Sources |
Expand Down Expand Up @@ -866,7 +853,6 @@ To deploy to an ECS cluster check this [doc](https://aws-otel.github.io/docs/set
| ClusterName |
| InstanceType |
| AutoScalingGroupName |
| Timestamp |
| Type |
| Version |
| Sources |
Expand Down