Skip to content

Commit

Permalink
[SVLS-6016] Filter high cardinality tags from the metric agent (#31440)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcstorms1 authored Nov 25, 2024
1 parent 88703d8 commit df19dfb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
4 changes: 2 additions & 2 deletions cmd/serverless-init/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 7 additions & 3 deletions cmd/serverless-init/tag/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
6 changes: 6 additions & 0 deletions cmd/serverless-init/tag/tag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit df19dfb

Please sign in to comment.