Skip to content

Commit

Permalink
sfxexporter: Add initial list of non-default metrics (#2145)
Browse files Browse the repository at this point in the history
Always drop certain non-default metrics. A subsequent PR will be opened
to add ability to override this behavior.
  • Loading branch information
asuresh4 committed Jan 20, 2021
1 parent 9aa0432 commit 6bf5f19
Show file tree
Hide file tree
Showing 3 changed files with 182 additions and 0 deletions.
34 changes: 34 additions & 0 deletions exporter/signalfxexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,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"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/batchperresourceattr"
)
Expand Down Expand Up @@ -110,6 +111,11 @@ func createMetricsExporter(
return nil, err
}

err = setDefaultExcludes(expCfg)
if err != nil {
return nil, err
}

exp, err := newSignalFxExporter(expCfg, params.Logger)
if err != nil {
return nil, err
Expand Down Expand Up @@ -168,6 +174,34 @@ func loadDefaultTranslationRules() ([]translation.Rule, error) {
return config.TranslationRules, nil
}

// setDefaultExcludes appends default metrics to be excluded to the exclude_metrics option.
func setDefaultExcludes(cfg *Config) error {
defaultExcludeMetrics, err := loadDefaultExcludes()
if err != nil {
return err
}
if cfg.ExcludeMetrics == nil {
cfg.ExcludeMetrics = defaultExcludeMetrics
} else {
cfg.ExcludeMetrics = append(cfg.ExcludeMetrics, defaultExcludeMetrics...)
}
return nil
}

func loadDefaultExcludes() ([]dpfilters.MetricFilter, error) {
config := Config{}

v := otelconfig.NewViper()
v.SetConfigType("yaml")
v.ReadConfig(strings.NewReader(translation.DefaultExcludeMetricsYaml))
err := v.UnmarshalExact(&config)
if err != nil {
return nil, fmt.Errorf("failed to load default exclude metrics: %v", err)
}

return config.ExcludeMetrics, nil
}

func createLogsExporter(
_ context.Context,
params component.ExporterCreateParams,
Expand Down
42 changes: 42 additions & 0 deletions exporter/signalfxexporter/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"google.golang.org/protobuf/types/known/timestamppb"

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

func TestCreateDefaultConfig(t *testing.T) {
Expand Down Expand Up @@ -310,6 +311,47 @@ func TestDefaultTranslationRules(t *testing.T) {
require.True(t, ok, "container_memory_major_page_faults not found")
}

func TestCreateMetricsExporterWithDefaultExcludeMetrics(t *testing.T) {
config := &Config{
ExporterSettings: configmodels.ExporterSettings{
TypeVal: configmodels.Type(typeStr),
NameVal: typeStr,
},
AccessToken: "testToken",
Realm: "us1",
}

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

// Validate that default excludes are always loaded.
assert.Equal(t, 7, len(config.ExcludeMetrics))
}

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

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

// Validate that default excludes are always loaded.
assert.Equal(t, 8, len(config.ExcludeMetrics))
}

func testMetricsData() pdata.ResourceMetrics {
md := consumerdata.MetricsData{
Metrics: []*metricspb.Metric{
Expand Down
106 changes: 106 additions & 0 deletions exporter/signalfxexporter/translation/default_metrics.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// Copyright 2021, OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http:https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package translation

// DefaultExcludeMetricsYaml holds list of hard coded metrics that will added to the
// exclude list from the config. It includes non-default metrics collected by
// receivers. This list is determined by categorization of metrics in the SignalFx
// Agent. Metrics in the OpenTelemetry convention, that have equivalents in the
// SignalFx Agent that are categorized as non-default are also included in this list.
const DefaultExcludeMetricsYaml = `
exclude_metrics:
# Metrics in SignalFx Agent Format.
- metric_names:
# CPU metrics.
# Derived from https://docs.signalfx.com/en/latest/integrations/agent/monitors/cpu.html.
- cpu.interrupt
- cpu.nice
- cpu.softirq
- cpu.steal
- cpu.system
- cpu.user
- cpu.utilization_per_core
- cpu.wait
# Memory metrics.
# Derived from https://docs.signalfx.com/en/latest/integrations/agent/monitors/memory.html.
# Windows Only.
- memory.available
# Filesystems metrics.
# Derived from https://docs.signalfx.com/en/latest/integrations/agent/monitors/filesystems.html.
- df_complex.reserved
- df_inodes.free
- df_inodes.used
- percent_inodes.free
- percent_inodes.used
- percent_bytes.free
- percent_bytes.free
- percent_bytes.free
# Disk-IO metrics.
# Derived from https://docs.signalfx.com/en/latest/integrations/agent/monitors/disk-io.html.
- disk_merged.read
- disk_merged.write
- disk_octets.read
- disk_octets.write
- disk_ops.pending
- disk_time.read
- disk_time.write
# Windows Only.
- disk_octets.avg_read
- disk_octets.avg_write
- disk_time.avg_read
- disk_time.avg_write
# Network-io metrics.
# Derived from https://docs.signalfx.com/en/latest/integrations/agent/monitors/net-io.html.
- if_dropped.rx
- if_dropped.tx
- if_packets.rx
- if_packets.tx
# Metrics in OpenTelemetry Convention.
# CPU Metrics.
- metric_name: system.cpu.time
dimensions:
state: [interrupt, nice, softirq, steal, system, user, wait]
# Memory metrics.
- metric_name: system.memory.usage
dimensions:
state: [inactive]
# Filesystem metrics.
- metric_name: system.filesystem.usage
dimensions:
state: [reserved]
- metric_name: system.filesystem.inodes.usage
# Disk-IO metrics.
- metric_names:
- system.disk.merged
- system.disk.io
- system.disk.time
- system.disk.pending_operations
# Network-IO metrics.
- metric_names:
- system.network.packets
- system.network.dropped_packets
- system.network.tcp_connections
`

0 comments on commit 6bf5f19

Please sign in to comment.