From df19dfb89a243db3cf101d521a2f5e3b619e3b70 Mon Sep 17 00:00:00 2001 From: Jordan Storms Date: Mon, 25 Nov 2024 16:12:00 -0500 Subject: [PATCH] [SVLS-6016] Filter high cardinality tags from the metric agent (#31440) --- cmd/serverless-init/main.go | 4 ++-- cmd/serverless-init/tag/tag.go | 10 +++++++--- cmd/serverless-init/tag/tag_test.go | 6 ++++++ 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/cmd/serverless-init/main.go b/cmd/serverless-init/main.go index b59177af3e6a5..1b5242fa41e21 100644 --- a/cmd/serverless-init/main.go +++ b/cmd/serverless-init/main.go @@ -193,8 +193,8 @@ func setupMetricAgent(tags map[string]string, tagger tagger.Component) *metrics. SketchesBucketOffset: time.Second * 0, Tagger: tagger, } - // we don't want to add the container_id tag to metrics for cardinality reasons - tags = serverlessInitTag.WithoutContainerID(tags) + // we don't want to add certain tags to metrics for cardinality reasons + tags = serverlessInitTag.WithoutHighCardinalityTags(tags) metricAgent.Start(5*time.Second, &metrics.MetricConfig{}, &metrics.MetricDogStatsD{}) metricAgent.SetExtraTags(serverlessTag.MapToArray(tags)) return metricAgent diff --git a/cmd/serverless-init/tag/tag.go b/cmd/serverless-init/tag/tag.go index e35ca586ddd88..538e0b5dfb8b6 100644 --- a/cmd/serverless-init/tag/tag.go +++ b/cmd/serverless-init/tag/tag.go @@ -62,11 +62,15 @@ func GetBaseTagsMapWithMetadata(metadata map[string]string, versionMode string) return tagsMap } -// WithoutContainerID creates a new tag map without the `container_id` tag -func WithoutContainerID(tags map[string]string) map[string]string { +// WithoutHihCardinalityTags creates a new tag map without high cardinality tags we use on traces +func WithoutHighCardinalityTags(tags map[string]string) map[string]string { newTags := make(map[string]string, len(tags)) for k, v := range tags { - if k != "container_id" { + if k != "container_id" && + k != "gcr.container_id" && + k != "gcrfx.container_id" && + k != "replica_name" && + k != "aca.replica.name" { newTags[k] = v } } diff --git a/cmd/serverless-init/tag/tag_test.go b/cmd/serverless-init/tag/tag_test.go index 166738e21b60c..69735bbfabdc6 100644 --- a/cmd/serverless-init/tag/tag_test.go +++ b/cmd/serverless-init/tag/tag_test.go @@ -104,3 +104,9 @@ func TestDdTags(t *testing.T) { assert.Equal(t, "value5", mergedTags["key5"]) assert.Equal(t, "value6", mergedTags["key6"]) } + +func TestWithoutHighCardinalityTags(t *testing.T) { + tags := map[string]string{"key1": "value1", "key2": "value2", "container_id": "abc", "replica_name": "abc"} + filteredTags := WithoutHighCardinalityTags(tags) + assert.Equal(t, map[string]string{"key1": "value1", "key2": "value2"}, filteredTags) +}