Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

signalfxexporter: Update exclude_metrics option to use dpfilters.MetricFilter #1951

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions exporter/signalfxexporter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ The following configuration options can also be configured:
configuration option for [SignalFx
receiver](../../receiver/signalfxreceiver/README.md) to preserve datapoint
origin.
- `exclude_metrics`: metric names that will be excluded from sending
to Signalfx backend. If `send_compatible_metrics` or `translation_rules`
options are enabled, the exclusion will be applied on translated metrics.
- `exclude_metrics`: List of metric filters that will determine metrics to be
excluded from sending to Signalfx backend. If `send_compatible_metrics`
or `translation_rules` options are enabled, the exclusion will be applied
on translated metrics. See [here](./testdata/config.yaml) for examples.
- `headers` (no default): Headers to pass in the payload.
- `log_dimension_updates` (default = `false`): Whether or not to log dimension
updates.
Expand Down
10 changes: 6 additions & 4 deletions exporter/signalfxexporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (

"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/signalfxexporter/correlation"
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/signalfxexporter/translation"
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/signalfxexporter/translation/dpfilters"
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/splunk"
)

Expand Down Expand Up @@ -85,10 +86,11 @@ type Config struct {
// And keep `override=true` in resourcedetection config.
SyncHostMetadata bool `mapstructure:"sync_host_metadata"`

// ExcludeMetrics defines metrics that will be excluded from sending to Signalfx
// backend. If translations enabled with SendCompatibleMetrics or TranslationRules
// options, the exclusion will be applied on translated metrics.
ExcludeMetrics []string `mapstructure:"exclude_metrics"`
// ExcludeMetrics defines dpfilter.MetricFilters that will determine metrics to be
// excluded from sending to SignalFx backend. If translations enabled with
// SendCompatibleMetrics or TranslationRules options, the exclusion will be applied
// on translated metrics.
ExcludeMetrics []dpfilters.MetricFilter `mapstructure:"exclude_metrics"`

// Correlation configuration for syncing traces service and environment to metrics.
Correlation *correlation.Config `mapstructure:"correlation"`
Expand Down
21 changes: 21 additions & 0 deletions exporter/signalfxexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (

"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/signalfxexporter/correlation"
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/signalfxexporter/translation"
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/signalfxexporter/translation/dpfilters"
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/splunk"
)

Expand Down Expand Up @@ -94,6 +95,26 @@ func TestLoadConfig(t *testing.T) {
},
},
},
ExcludeMetrics: []dpfilters.MetricFilter{
{
MetricName: "metric1",
},
{
MetricNames: []string{"metric2", "metric3"},
},
{
MetricName: "metric4",
Dimensions: map[string]interface{}{
"dimension_key": "dimension_val",
},
},
{
MetricName: "metric5",
Dimensions: map[string]interface{}{
"dimension_key": []interface{}{"dimension_val1", "dimension_val2"},
},
},
},
DeltaTranslationTTL: 3600,
Correlation: &correlation.Config{
HTTPClientSettings: confighttp.HTTPClientSettings{
Expand Down
7 changes: 6 additions & 1 deletion exporter/signalfxexporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ func newSignalFxExporter(

headers := buildHeaders(config)

converter, err := translation.NewMetricsConverter(logger, options.metricTranslator, config.ExcludeMetrics)
if err != nil {
return nil, fmt.Errorf("failed to create metric converter: %v", err)
}

dpClient := &sfxDPClient{
sfxClientBase: sfxClientBase{
ingestURL: options.ingestURL,
Expand All @@ -103,7 +108,7 @@ func newSignalFxExporter(
},
logger: logger,
accessTokenPassthrough: config.AccessTokenPassthrough,
converter: translation.NewMetricsConverter(logger, options.metricTranslator),
converter: converter,
}

dimClient := dimensions.NewDimensionClient(
Expand Down
20 changes: 18 additions & 2 deletions exporter/signalfxexporter/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import (

"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/signalfxexporter/dimensions"
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/signalfxexporter/translation"
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/signalfxexporter/translation/dpfilters"
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/common/metrics"
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/splunk"
)
Expand All @@ -64,6 +65,15 @@ func TestNew(t *testing.T) {
},
wantErr: true,
},
{
name: "fails to create metrics converter",
config: &Config{
AccessToken: "test",
Realm: "realm",
ExcludeMetrics: []dpfilters.MetricFilter{{}},
},
wantErr: true,
},
{
name: "successfully create exporter",
config: &Config{
Expand Down Expand Up @@ -184,6 +194,9 @@ func TestConsumeMetrics(t *testing.T) {
serverURL, err := url.Parse(server.URL)
assert.NoError(t, err)

c, err := translation.NewMetricsConverter(zap.NewNop(), nil, nil)
require.NoError(t, err)
require.NotNil(t, c)
dpClient := &sfxDPClient{
sfxClientBase: sfxClientBase{
ingestURL: serverURL,
Expand All @@ -196,7 +209,7 @@ func TestConsumeMetrics(t *testing.T) {
}},
},
logger: zap.NewNop(),
converter: translation.NewMetricsConverter(zap.NewNop(), nil),
converter: c,
}

numDroppedTimeSeries, err := dpClient.pushMetricsData(context.Background(), tt.md)
Expand Down Expand Up @@ -961,6 +974,9 @@ func BenchmarkExporterConsumeData(b *testing.B) {
serverURL, err := url.Parse(server.URL)
assert.NoError(b, err)

c, err := translation.NewMetricsConverter(zap.NewNop(), nil, nil)
require.NoError(b, err)
require.NotNil(b, c)
dpClient := &sfxDPClient{
sfxClientBase: sfxClientBase{
ingestURL: serverURL,
Expand All @@ -972,7 +988,7 @@ func BenchmarkExporterConsumeData(b *testing.B) {
}},
},
logger: zap.NewNop(),
converter: translation.NewMetricsConverter(zap.NewNop(), nil),
converter: c,
}

for i := 0; i < b.N; i++ {
Expand Down
4 changes: 0 additions & 4 deletions exporter/signalfxexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,6 @@ func setTranslationRules(cfg *Config) error {
}
cfg.TranslationRules = defaultRules
}
if len(cfg.ExcludeMetrics) > 0 {
cfg.TranslationRules = append(cfg.TranslationRules,
translation.GetExcludeMetricsRule(cfg.ExcludeMetrics))
}
return nil
}

Expand Down
54 changes: 2 additions & 52 deletions exporter/signalfxexporter/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,57 +236,6 @@ func TestCreateMetricsExporterWithSpecifiedTranslaitonRules(t *testing.T) {
assert.Equal(t, "new_dimension", config.TranslationRules[0].Mapping["old_dimension"])
}

func TestCreateMetricsExporterWithExcludedMetrics(t *testing.T) {
config := &Config{
ExporterSettings: configmodels.ExporterSettings{
TypeVal: configmodels.Type(typeStr),
NameVal: typeStr,
},
AccessToken: "testToken",
Realm: "us1",
ExcludeMetrics: []string{"metric1"},
}

te, err := createMetricsExporter(context.Background(), component.ExporterCreateParams{Logger: zap.NewNop()}, config)
require.NoError(t, err)
require.NotNil(t, te)

assert.Equal(t, 1, len(config.TranslationRules))
assert.Equal(t, translation.ActionDropMetrics, config.TranslationRules[0].Action)
assert.Equal(t, 1, len(config.TranslationRules[0].MetricNames))
assert.True(t, config.TranslationRules[0].MetricNames["metric1"])
}

func TestCreateMetricsExporterWithDefinedRulesAndExcludedMetrics(t *testing.T) {
config := &Config{
ExporterSettings: configmodels.ExporterSettings{
TypeVal: configmodels.Type(typeStr),
NameVal: typeStr,
},
AccessToken: "testToken",
Realm: "us1",
TranslationRules: []translation.Rule{
{
Action: translation.ActionRenameDimensionKeys,
Mapping: map[string]string{
"old_dimension": "new_dimension",
},
},
},
ExcludeMetrics: []string{"metric1"},
}

te, err := createMetricsExporter(context.Background(), component.ExporterCreateParams{Logger: zap.NewNop()}, config)
require.NoError(t, err)
require.NotNil(t, te)

assert.Equal(t, 2, len(config.TranslationRules))
assert.Equal(t, translation.ActionRenameDimensionKeys, config.TranslationRules[0].Action)
assert.Equal(t, translation.ActionDropMetrics, config.TranslationRules[1].Action)
assert.Equal(t, 1, len(config.TranslationRules[1].MetricNames))
assert.True(t, config.TranslationRules[1].MetricNames["metric1"])
}

func TestDefaultTranslationRules(t *testing.T) {
rules, err := loadDefaultTranslationRules()
require.NoError(t, err)
Expand All @@ -295,7 +244,8 @@ func TestDefaultTranslationRules(t *testing.T) {
require.NoError(t, err)
data := testMetricsData()

c := translation.NewMetricsConverter(zap.NewNop(), tr)
c, err := translation.NewMetricsConverter(zap.NewNop(), tr, nil)
require.NoError(t, err)
translated := c.MetricDataToSignalFxV2(data)
require.NotNil(t, translated)

Expand Down
11 changes: 11 additions & 0 deletions exporter/signalfxexporter/testdata/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@ exporters:
- action: rename_dimension_keys
mapping:
k8s.cluster.name: kubernetes_cluster
exclude_metrics:
- metric_name: metric1
- metric_names: [metric2, metric3]
- metric_name: metric4
dimensions:
dimension_key: dimension_val
- metric_name: metric5
dimensions:
dimension_key: [dimension_val1, dimension_val2]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This supports /regex/ and glob.* form too right? Should probably document/give examples those.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point. Added a few examples.




service:
pipelines:
Expand Down
25 changes: 23 additions & 2 deletions exporter/signalfxexporter/translation/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
tracetranslator "go.opentelemetry.io/collector/translator/trace"
"go.uber.org/zap"

"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/signalfxexporter/translation/dpfilters"
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/splunk"
)

Expand All @@ -51,13 +52,18 @@ var (
type MetricsConverter struct {
logger *zap.Logger
metricTranslator *MetricTranslator
filterSet *dpfilters.FilterSet
}

// NewMetricsConverter creates a MetricsConverter from the passed in logger and
// MetricTranslator. Pass in a nil MetricTranslator to not use translation
// rules.
func NewMetricsConverter(logger *zap.Logger, t *MetricTranslator) *MetricsConverter {
return &MetricsConverter{logger: logger, metricTranslator: t}
func NewMetricsConverter(logger *zap.Logger, t *MetricTranslator, excludes []dpfilters.MetricFilter) (*MetricsConverter, error) {
fs, err := dpfilters.NewFilterSet(excludes)
if err != nil {
return nil, err
}
return &MetricsConverter{logger: logger, metricTranslator: t, filterSet: fs}, nil
}

// MetricDataToSignalFxV2 converts the passed in MetricsData to SFx datapoints,
Expand Down Expand Up @@ -111,6 +117,21 @@ func (c *MetricsConverter) metricToSfxDataPoints(metric pdata.Metric, extraDimen
dps = c.metricTranslator.TranslateDataPoints(c.logger, dps)
}

// TODO:
// 1) Add hard coded list of metrics to be excluded to omit non-default metrics
// 2) Add an include_metrics options that will serve as an override to the exclude
// list. This will help to include metrics that are excluded by default.
resultSliceLen := 0
for i, dp := range dps {
if !c.filterSet.Matches(dp) {
if resultSliceLen < i {
dps[resultSliceLen] = dp
}
resultSliceLen++
}
}
dps = dps[:resultSliceLen]

return dps
}

Expand Down