Apply global and plugin level metric modifications before filtering (#5152)
This commit is contained in:
parent
7caa5d20af
commit
544262a23a
|
@ -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,
|
||||
|
@ -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
|
||||
|
|
|
@ -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{
|
||||
|
|
Loading…
Reference in New Issue