Skip to content

Commit

Permalink
Apply global and plugin level metric modifications before filtering (i…
Browse files Browse the repository at this point in the history
  • Loading branch information
danielnelson authored and Max Eshleman committed Feb 13, 2019
1 parent 08fb7e0 commit 01ca102
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 7 deletions.
12 changes: 6 additions & 6 deletions internal/models/running_input.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,6 @@ func (r *RunningInput) MakeMetric(metric telegraf.Metric) telegraf.Metric {
return nil
}

r.Config.Filter.Modify(metric)
if len(metric.FieldList()) == 0 {
r.metricFiltered(metric)
return nil
}

m := makemetric(
metric,
r.Config.NameOverride,
Expand All @@ -76,6 +70,12 @@ func (r *RunningInput) MakeMetric(metric telegraf.Metric) telegraf.Metric {
r.Config.Tags,
r.defaultTags)

r.Config.Filter.Modify(metric)
if len(metric.FieldList()) == 0 {
r.metricFiltered(metric)
return nil
}

r.MetricsGathered.Incr(1)
GlobalMetricsGathered.Incr(1)
return m
Expand Down
34 changes: 33 additions & 1 deletion internal/models/running_input_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,43 @@ import (
"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/metric"
"github.com/influxdata/telegraf/testutil"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestMakeMetricFilterAfterApplyingGlobalTags(t *testing.T) {
now := time.Now()
ri := NewRunningInput(&testInput{}, &InputConfig{
Filter: Filter{
TagInclude: []string{"b"},
},
})
require.NoError(t, ri.Config.Filter.Compile())
ri.SetDefaultTags(map[string]string{"a": "x", "b": "y"})

m, err := metric.New("cpu",
map[string]string{},
map[string]interface{}{
"value": 42,
},
now)
require.NoError(t, err)

actual := ri.MakeMetric(m)

expected, err := metric.New("cpu",
map[string]string{
"b": "y",
},
map[string]interface{}{
"value": 42,
},
now)
require.NoError(t, err)

testutil.RequireMetricEqual(t, expected, actual)
}

func TestMakeMetricNoFields(t *testing.T) {
now := time.Now()
ri := NewRunningInput(&testInput{}, &InputConfig{
Expand Down

0 comments on commit 01ca102

Please sign in to comment.