feat(processors.noop): Noop processor (#14297)

This commit is contained in:
Joshua Powers 2023-11-15 10:35:21 -07:00 committed by GitHub
parent a590a1b5b3
commit 0a63e2e1aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 189 additions and 0 deletions

View File

@ -0,0 +1,5 @@
//go:build !custom || processors || processors.noop
package all
import _ "github.com/influxdata/telegraf/plugins/processors/noop" // register plugin

View File

@ -0,0 +1,60 @@
# Noop Processor Plugin
The noop processor plugin does nothing to metrics. Instead it can be used to
apply the global configuration options after other processing. Global config
options like tagpass, fieldpass, and others are applied before a processor,
aggregator, or output. As such a user might want to apply these after doing
processing, but before an output or another processor.
## Global configuration options <!-- @/docs/includes/plugin_config.md -->
In addition to the plugin-specific configuration settings, plugins support
additional global and plugin configuration settings. These settings are used to
modify metrics, tags, and field or create aliases and configure ordering, etc.
See the [CONFIGURATION.md][CONFIGURATION.md] for more details.
[CONFIGURATION.md]: ../../../docs/CONFIGURATION.md#plugins
## Configuration
```toml @sample.conf
# Do nothing processor
[[processors.noop]]
## Metric Filtering
## The following options provide mechanisms to include or exclude entire
## metrics. For specific details and examples see the metric filtering docs:
## https://github.com/influxdata/telegraf/blob/master/docs/CONFIGURATION.md#metric-filtering
## Metric Selectors - These will drop entire metrics
## Filter on metric name or tag key + value
# namepass = []
# namedrop = []
# tagpass = {}
# tagdrop = {}
## Filter on Common Expression Language (CEL) expression
# metricpass = ""
## Metric Modifiers - These will drop tags and fields from metrics
## Filter on tag key or field key
# taginclude = []
# tagexclude = []
# fieldpass = []
# fielddrop = []
```
## Examples
Consider a use-case where you have processed a metric based on a tag, but no
longer need that tag for additional processing:
```toml
[[processors.ifname]]
order = 1
...
[[processors.noop]]
order = 2
tagexclude = ["useless_tag"]
```

View File

@ -0,0 +1,28 @@
//go:generate ../../../tools/readme_config_includer/generator
package noop
import (
_ "embed"
"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/plugins/processors"
)
//go:embed sample.conf
var sampleConfig string
type Noop struct{}
func (*Noop) SampleConfig() string {
return sampleConfig
}
func (p *Noop) Apply(in ...telegraf.Metric) []telegraf.Metric {
return in
}
func init() {
processors.Add("noop", func() telegraf.Processor {
return &Noop{}
})
}

View File

@ -0,0 +1,72 @@
package noop
import (
"testing"
"time"
"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/testutil"
"github.com/stretchr/testify/require"
)
func TestNoopNoMetric(t *testing.T) {
processor := Noop{}
m := []telegraf.Metric{}
actual := processor.Apply(m...)
require.Empty(t, actual)
testutil.RequireMetricsEqual(t, m, actual)
}
func TestNoopSingleMetric(t *testing.T) {
processor := Noop{}
m := []telegraf.Metric{
testutil.MustMetric(
"test",
map[string]string{
"tag": "tag_value",
},
map[string]interface{}{
"value": 42,
},
time.Now(),
telegraf.Gauge,
),
}
actual := processor.Apply(m...)
require.Len(t, actual, 1)
testutil.RequireMetricsEqual(t, m, actual)
}
func TestNoopMultipleMetrics(t *testing.T) {
processor := Noop{}
m := []telegraf.Metric{
testutil.MustMetric(
"test",
map[string]string{
"tag": "tag_value",
},
map[string]interface{}{
"value": 42,
},
time.Now(),
telegraf.Gauge,
),
testutil.MustMetric(
"test",
map[string]string{
"tag": "tag_value",
},
map[string]interface{}{
"value": 42,
},
time.Now(),
telegraf.Gauge,
),
}
actual := processor.Apply(m...)
require.Len(t, actual, 2)
testutil.RequireMetricsEqual(t, m, actual)
}

View File

@ -0,0 +1,24 @@
# Do nothing processor
[[processors.noop]]
## Metric Filtering
## The following options provide mechanisms to include or exclude entire
## metrics. For specific details and examples see the metric filtering docs:
## https://github.com/influxdata/telegraf/blob/master/docs/CONFIGURATION.md#metric-filtering
## Metric Selectors - These will drop entire metrics
## Filter on metric name or tag key + value
# namepass = []
# namedrop = []
# tagpass = {}
# tagdrop = {}
## Filter on Common Expression Language (CEL) expression
# metricpass = ""
## Metric Modifiers - These will drop tags and fields from metrics
## Filter on tag key or field key
# taginclude = []
# tagexclude = []
# fieldpass = []
# fielddrop = []