From deb6efee8e0cc3916db39f54369ccb03f59b6cf3 Mon Sep 17 00:00:00 2001 From: Akash Suresh Date: Thu, 18 Mar 2021 20:20:51 -0400 Subject: [PATCH] exporter/signalfx: Update exclude_metrics option (#2737) --- exporter/signalfxexporter/README.md | 5 ++++- exporter/signalfxexporter/factory.go | 4 +--- exporter/signalfxexporter/factory_test.go | 20 ++++++++++++++++++++ 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/exporter/signalfxexporter/README.md b/exporter/signalfxexporter/README.md index 645933fdb0117..0d91f3882c411 100644 --- a/exporter/signalfxexporter/README.md +++ b/exporter/signalfxexporter/README.md @@ -44,7 +44,10 @@ The following configuration options can also be configured: - `exclude_metrics`: List of metric filters that will determine metrics to be excluded from sending to Signalfx backend. If `translation_rules` options are enabled, the exclusion will be applied on translated metrics. - See [here](./testdata/config.yaml) for examples. + See [here](./testdata/config.yaml) for examples. Apart from the values explicitly + provided via this option, by default, [these](./translation/default_metrics.go) are + also appended to this list. Setting this option to `[]` will override all the default + excludes. - `include_metrics`: List of filters to override exclusion of any metrics. This option can be used to included metrics that are otherwise dropped by default. See [here](./translation/default_metrics.go) for a list of metrics diff --git a/exporter/signalfxexporter/factory.go b/exporter/signalfxexporter/factory.go index 08dfa1638dc06..8e43516cbccf6 100644 --- a/exporter/signalfxexporter/factory.go +++ b/exporter/signalfxexporter/factory.go @@ -187,9 +187,7 @@ func setDefaultExcludes(cfg *Config) error { if err != nil { return err } - if cfg.ExcludeMetrics == nil { - cfg.ExcludeMetrics = defaultExcludeMetrics - } else { + if cfg.ExcludeMetrics == nil || len(cfg.ExcludeMetrics) > 0 { cfg.ExcludeMetrics = append(cfg.ExcludeMetrics, defaultExcludeMetrics...) } return nil diff --git a/exporter/signalfxexporter/factory_test.go b/exporter/signalfxexporter/factory_test.go index d0e6cce9f9bb3..08219d0b5acf6 100644 --- a/exporter/signalfxexporter/factory_test.go +++ b/exporter/signalfxexporter/factory_test.go @@ -331,6 +331,26 @@ func TestCreateMetricsExporterWithExcludeMetrics(t *testing.T) { assert.Equal(t, 11, len(config.ExcludeMetrics)) } +func TestCreateMetricsExporterWithEmptyExcludeMetrics(t *testing.T) { + config := &Config{ + ExporterSettings: configmodels.ExporterSettings{ + TypeVal: configmodels.Type(typeStr), + NameVal: typeStr, + }, + AccessToken: "testToken", + Realm: "us1", + ExcludeMetrics: []dpfilters.MetricFilter{}, + } + + te, err := createMetricsExporter(context.Background(), component.ExporterCreateParams{Logger: zap.NewNop()}, config) + require.NoError(t, err) + require.NotNil(t, te) + + // Validate that default excludes are overridden when exclude metrics + // is explicitly set to an empty slice. + assert.Equal(t, 0, len(config.ExcludeMetrics)) +} + func testMetricsData() pdata.ResourceMetrics { md := internaldata.MetricsData{ Metrics: []*metricspb.Metric{