Skip to content

Commit

Permalink
redact host and instance tags for internal metrics (#237)
Browse files Browse the repository at this point in the history
* redact host and instance tags for internal metrics

* fix unit test
  • Loading branch information
shaan420 committed Oct 27, 2023
1 parent 3518876 commit a844582
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 5 additions & 1 deletion m3/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ const (
DefaultHistogramBucketIDName = "bucketid"
// DefaultHistogramBucketName is the default histogram bucket name tag name
DefaultHistogramBucketName = "bucket"
// DefaultTagRedactValue is the default tag value to use when redacting
DefaultTagRedactValue = "global"
// DefaultHistogramBucketTagPrecision is the default
// precision to use when formatting the metric tag
// with the histogram bucket bound values.
Expand Down Expand Up @@ -287,7 +289,9 @@ func NewReporter(opts Options) (Reporter, error) {
}

internalTags := map[string]string{
"version": tally.Version,
"version": tally.Version,
"host": DefaultTagRedactValue,
"instance": DefaultTagRedactValue,
}

for k, v := range opts.InternalTags {
Expand Down
7 changes: 5 additions & 2 deletions m3/reporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -597,15 +597,18 @@ func TestReporterCommmonTagsInternal(t *testing.T) {
for k, v := range internalTags {
require.True(t, tagEquals(metric.Tags, k, v))
}

// The following tags should be redacted.
require.True(t, tagEquals(metric.Tags, "host", DefaultTagRedactValue))
require.True(t, tagEquals(metric.Tags, "instance", DefaultTagRedactValue))
} else {
require.Equal(t, "testCounter1", metric.Name)
require.False(t, tagIncluded(metric.Tags, "internal1"))
require.False(t, tagIncluded(metric.Tags, "internal2"))
}

// The following tags should not be present as part of the individual metrics
// as they are common tags.
require.False(t, tagIncluded(metric.Tags, "host"))
require.False(t, tagIncluded(metric.Tags, "instance"))
require.False(t, tagIncluded(metric.Tags, "service"))
}
require.Equal(t, internalMetrics, numInternalMetricsActual)
Expand Down

0 comments on commit a844582

Please sign in to comment.