diff --git a/m3/config.go b/m3/config.go index ccfb51ce..0a94f124 100644 --- a/m3/config.go +++ b/m3/config.go @@ -50,9 +50,14 @@ type Configuration struct { // with the histogram bucket bound values. HistogramBucketTagPrecision uint `yaml:"histogramBucketTagPrecision"` - // CommonTagsInternal are tags that should be added to all internal metrics + // InternalTags are tags that should be added to all internal metrics // emitted by the reporter. - CommonTagsInternal map[string]string `yaml:"commonTagsInternal"` + InternalTags map[string]string `yaml:"internalTags"` + + // InternalTagsToAnonymize are tags that should be anonymized in all internal + // metrics emitted by the reporter. The values of these tags will be replaced + // with the string "global". + InternalTagsToAnonymize []string `yaml:"internalTagsToAnonymize"` } // NewReporter creates a new M3 reporter from this configuration. @@ -70,6 +75,7 @@ func (c Configuration) NewReporter() (Reporter, error) { MaxPacketSizeBytes: c.PacketSize, IncludeHost: c.IncludeHost, HistogramBucketTagPrecision: c.HistogramBucketTagPrecision, - InternalTags: c.CommonTagsInternal, + InternalTags: c.InternalTags, + InternalTagsToAnonymize: c.InternalTagsToAnonymize, }) } diff --git a/m3/config_test.go b/m3/config_test.go index 20afd121..e727a2a3 100644 --- a/m3/config_test.go +++ b/m3/config_test.go @@ -42,7 +42,7 @@ func TestConfigSimple(t *testing.T) { assert.True(t, ok) assert.True(t, tagEquals(reporter.commonTags, "service", "my-service")) assert.True(t, tagEquals(reporter.commonTags, "env", "test")) - assert.Equal(t, 0, len(c.CommonTagsInternal)) + assert.Equal(t, 0, len(c.InternalTags)) } func TestConfigMulti(t *testing.T) { diff --git a/m3/reporter.go b/m3/reporter.go index c930d5c2..972271aa 100644 --- a/m3/reporter.go +++ b/m3/reporter.go @@ -150,6 +150,7 @@ type Options struct { HistogramBucketName string HistogramBucketTagPrecision uint InternalTags map[string]string + InternalTagsToAnonymize []string } // NewReporter creates a new M3 reporter. @@ -294,6 +295,11 @@ func NewReporter(opts Options) (Reporter, error) { internalTags[k] = v } + for _, toAnonomize := range opts.InternalTagsToAnonymize { + // override if present, set if not. + internalTags[toAnonomize] = "global" + } + r.batchSizeHistogram = r.AllocateHistogram("tally.internal.batch-size", internalTags, buckets) r.numBatchesCounter = r.AllocateCounter("tally.internal.num-batches", internalTags) r.numMetricsCounter = r.AllocateCounter("tally.internal.num-metrics", internalTags) diff --git a/m3/reporter_test.go b/m3/reporter_test.go index 6e5bbb0a..1a66719e 100644 --- a/m3/reporter_test.go +++ b/m3/reporter_test.go @@ -580,6 +580,10 @@ func TestReporterCommmonTagsInternal(t *testing.T) { IncludeHost: true, MaxPacketSizeBytes: maxPacketSize, InternalTags: internalTags, + InternalTagsToAnonymize: []string{ + "host", + "instance", + }, }) require.NoError(t, err) defer r.Close() @@ -598,17 +602,19 @@ func TestReporterCommmonTagsInternal(t *testing.T) { numInternalMetricsActual++ for k, v := range internalTags { require.True(t, tagEquals(metric.Tags, k, v)) + require.True(t, tagEquals(metric.Tags, "host", "global")) + require.True(t, tagEquals(metric.Tags, "instance", "global")) } } 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")) } - // 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) }