Skip to content

Commit

Permalink
feat: migrate processor plugins to new sample config format (#10913)
Browse files Browse the repository at this point in the history
  • Loading branch information
sspaink authored and MyaLongmire committed Jul 6, 2022
1 parent 15dd24f commit 2b1eb6f
Show file tree
Hide file tree
Showing 81 changed files with 481 additions and 1,099 deletions.
5 changes: 5 additions & 0 deletions plugins/processors/aws/ec2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ to metrics associated with EC2 instances.
## Configuration

```toml
# Attach AWS EC2 metadata to metrics
[[processors.aws_ec2]]
## Instance identity document tags to attach to metrics.
## For more information see:
## https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-identity-documents.html
##
## Available tags:
## * accountId
## * architecture
Expand Down
56 changes: 0 additions & 56 deletions plugins/processors/aws/ec2/ec2.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,54 +35,6 @@ type AwsEc2Processor struct {
instanceID string
}

const sampleConfig = `
## Instance identity document tags to attach to metrics.
## For more information see:
## https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-identity-documents.html
##
## Available tags:
## * accountId
## * architecture
## * availabilityZone
## * billingProducts
## * imageId
## * instanceId
## * instanceType
## * kernelId
## * pendingTime
## * privateIp
## * ramdiskId
## * region
## * version
imds_tags = []
## EC2 instance tags retrieved with DescribeTags action.
## In case tag is empty upon retrieval it's omitted when tagging metrics.
## Note that in order for this to work, role attached to EC2 instance or AWS
## credentials available from the environment must have a policy attached, that
## allows ec2:DescribeTags.
##
## For more information see:
## https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeTags.html
ec2_tags = []
## Timeout for http requests made by against aws ec2 metadata endpoint.
timeout = "10s"
## ordered controls whether or not the metrics need to stay in the same order
## this plugin received them in. If false, this plugin will change the order
## with requests hitting cached results moving through immediately and not
## waiting on slower lookups. This may cause issues for you if you are
## depending on the order of metrics staying the same. If so, set this to true.
## Keeping the metrics ordered may be slightly slower.
ordered = false
## max_parallel_calls is the maximum number of AWS API calls to be in flight
## at the same time.
## It's probably best to keep this number fairly low.
max_parallel_calls = 10
`

const (
DefaultMaxOrderedQueueSize = 10_000
DefaultMaxParallelCalls = 10
Expand All @@ -105,14 +57,6 @@ var allowedImdsTags = map[string]struct{}{
"version": {},
}

func (r *AwsEc2Processor) SampleConfig() string {
return sampleConfig
}

func (r *AwsEc2Processor) Description() string {
return "Attach AWS EC2 metadata to metrics"
}

func (r *AwsEc2Processor) Add(metric telegraf.Metric, _ telegraf.Accumulator) error {
r.parallel.Enqueue(metric)
return nil
Expand Down
8 changes: 8 additions & 0 deletions plugins/processors/aws/ec2/ec2_sample_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//go:generate go run ../../../../tools/generate_plugindata/main.go
//go:generate go run ../../../../tools/generate_plugindata/main.go --clean
// DON'T EDIT; This file is used as a template by tools/generate_plugindata
package ec2

func (r *AwsEc2Processor) SampleConfig() string {
return `{{ .SampleConfig }}`
}
10 changes: 0 additions & 10 deletions plugins/processors/aws/ec2/ec2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package ec2
import (
"testing"

"github.com/influxdata/telegraf/config"
"github.com/influxdata/telegraf/testutil"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -46,12 +45,3 @@ func TestBasicInitInvalidTagsReturnAnError(t *testing.T) {
err := p.Init()
require.Error(t, err)
}

func TestLoadingConfig(t *testing.T) {
confFile := []byte("[[processors.aws_ec2]]" + "\n" + sampleConfig)
c := config.NewConfig()
err := c.LoadConfigData(confFile)
require.NoError(t, err)

require.Len(t, c.Processors, 1)
}
19 changes: 0 additions & 19 deletions plugins/processors/clone/clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,13 @@ import (
"github.com/influxdata/telegraf/plugins/processors"
)

var sampleConfig = `
## All modifications on inputs and aggregators can be overridden:
# name_override = "new_name"
# name_prefix = "new_name_prefix"
# name_suffix = "new_name_suffix"
## Tags to be added (all values must be strings)
# [processors.clone.tags]
# additional_tag = "tag_value"
`

type Clone struct {
NameOverride string
NamePrefix string
NameSuffix string
Tags map[string]string
}

func (c *Clone) SampleConfig() string {
return sampleConfig
}

func (c *Clone) Description() string {
return "Clone metrics and apply modifications."
}

func (c *Clone) Apply(in ...telegraf.Metric) []telegraf.Metric {
cloned := []telegraf.Metric{}

Expand Down
8 changes: 8 additions & 0 deletions plugins/processors/clone/clone_sample_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//go:generate go run ../../../tools/generate_plugindata/main.go
//go:generate go run ../../../tools/generate_plugindata/main.go --clean
// DON'T EDIT; This file is used as a template by tools/generate_plugindata
package clone

func (c *Clone) SampleConfig() string {
return `{{ .SampleConfig }}`
}
37 changes: 0 additions & 37 deletions plugins/processors/converter/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,6 @@ import (
"github.com/influxdata/telegraf/plugins/processors"
)

var sampleConfig = `
## Tags to convert
##
## The table key determines the target type, and the array of key-values
## select the keys to convert. The array may contain globs.
## <target-type> = [<tag-key>...]
[processors.converter.tags]
measurement = []
string = []
integer = []
unsigned = []
boolean = []
float = []
## Fields to convert
##
## The table key determines the target type, and the array of key-values
## select the keys to convert. The array may contain globs.
## <target-type> = [<field-key>...]
[processors.converter.fields]
measurement = []
tag = []
string = []
integer = []
unsigned = []
boolean = []
float = []
`

type Conversion struct {
Measurement []string `toml:"measurement"`
Tag []string `toml:"tag"`
Expand Down Expand Up @@ -71,14 +42,6 @@ type ConversionFilter struct {
Float filter.Filter
}

func (p *Converter) SampleConfig() string {
return sampleConfig
}

func (p *Converter) Description() string {
return "Convert values to another metric value type"
}

func (p *Converter) Init() error {
return p.compile()
}
Expand Down
8 changes: 8 additions & 0 deletions plugins/processors/converter/converter_sample_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//go:generate go run ../../../tools/generate_plugindata/main.go
//go:generate go run ../../../tools/generate_plugindata/main.go --clean
// DON'T EDIT; This file is used as a template by tools/generate_plugindata
package converter

func (p *Converter) SampleConfig() string {
return `{{ .SampleConfig }}`
}
1 change: 1 addition & 0 deletions plugins/processors/date/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ A few example usecases include:
## Configuration

```toml
# Dates measurements, tags, and fields that pass through this filter.
[[processors.date]]
## New tag to create
tag_key = "month"
Expand Down
33 changes: 0 additions & 33 deletions plugins/processors/date/date.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,6 @@ import (
"github.com/influxdata/telegraf/plugins/processors"
)

const sampleConfig = `
## New tag to create
tag_key = "month"
## New field to create (cannot set both field_key and tag_key)
# field_key = "month"
## Date format string, must be a representation of the Go "reference time"
## which is "Mon Jan 2 15:04:05 -0700 MST 2006".
date_format = "Jan"
## If destination is a field, date format can also be one of
## "unix", "unix_ms", "unix_us", or "unix_ns", which will insert an integer field.
# date_format = "unix"
## Offset duration added to the date string when writing the new tag.
# date_offset = "0s"
## Timezone to use when creating the tag or field using a reference time
## string. This can be set to one of "UTC", "Local", or to a location name
## in the IANA Time Zone database.
## example: timezone = "America/Los_Angeles"
# timezone = "UTC"
`

const defaultTimezone = "UTC"

type Date struct {
Expand All @@ -46,14 +21,6 @@ type Date struct {
location *time.Location
}

func (d *Date) SampleConfig() string {
return sampleConfig
}

func (d *Date) Description() string {
return "Dates measurements, tags, and fields that pass through this filter."
}

func (d *Date) Init() error {
// Check either TagKey or FieldKey specified
if len(d.FieldKey) > 0 && len(d.TagKey) > 0 {
Expand Down
8 changes: 8 additions & 0 deletions plugins/processors/date/date_sample_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//go:generate go run ../../../tools/generate_plugindata/main.go
//go:generate go run ../../../tools/generate_plugindata/main.go --clean
// DON'T EDIT; This file is used as a template by tools/generate_plugindata
package date

func (d *Date) SampleConfig() string {
return `{{ .SampleConfig }}`
}
1 change: 1 addition & 0 deletions plugins/processors/dedup/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Filter metrics whose field values are exact repetitions of the previous values.
## Configuration

```toml
# Filter metrics with repeating field values
[[processors.dedup]]
## Maximum time to suppress output
dedup_interval = "600s"
Expand Down
13 changes: 0 additions & 13 deletions plugins/processors/dedup/dedup.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,12 @@ import (
"github.com/influxdata/telegraf/plugins/processors"
)

var sampleConfig = `
## Maximum time to suppress output
dedup_interval = "600s"
`

type Dedup struct {
DedupInterval config.Duration `toml:"dedup_interval"`
FlushTime time.Time
Cache map[uint64]telegraf.Metric
}

func (d *Dedup) SampleConfig() string {
return sampleConfig
}

func (d *Dedup) Description() string {
return "Filter metrics with repeating field values"
}

// Remove expired items from cache
func (d *Dedup) cleanup() {
// No need to cleanup cache too often. Lets save some CPU
Expand Down
8 changes: 8 additions & 0 deletions plugins/processors/dedup/dedup_sample_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//go:generate go run ../../../tools/generate_plugindata/main.go
//go:generate go run ../../../tools/generate_plugindata/main.go --clean
// DON'T EDIT; This file is used as a template by tools/generate_plugindata
package dedup

func (d *Dedup) SampleConfig() string {
return `{{ .SampleConfig }}`
}
11 changes: 9 additions & 2 deletions plugins/processors/defaults/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,15 @@ Telegraf minimum version: Telegraf 1.15.0
```toml
## Set default fields on your metric(s) when they are nil or empty
[[processors.defaults]]

## This table determines what fields will be inserted in your metric(s)
## Ensures a set of fields always exists on your metric(s) with their
## respective default value.
## For any given field pair (key = default), if it's not set, a field
## is set on the metric with the specified default.
##
## A field is considered not set if it is nil on the incoming metric;
## or it is not nil but its value is an empty string or is a string
## of one or more spaces.
## <target-field> = <value>
[processors.defaults.fields]
field_1 = "bar"
time_idle = 0
Expand Down
26 changes: 0 additions & 26 deletions plugins/processors/defaults/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,12 @@ import (
"github.com/influxdata/telegraf/plugins/processors"
)

const sampleConfig = `
## Ensures a set of fields always exists on your metric(s) with their
## respective default value.
## For any given field pair (key = default), if it's not set, a field
## is set on the metric with the specified default.
##
## A field is considered not set if it is nil on the incoming metric;
## or it is not nil but its value is an empty string or is a string
## of one or more spaces.
## <target-field> = <value>
# [processors.defaults.fields]
# field_1 = "bar"
# time_idle = 0
# is_error = true
`

// Defaults is a processor for ensuring certain fields always exist
// on your Metrics with at least a default value.
type Defaults struct {
DefaultFieldsSets map[string]interface{} `toml:"fields"`
}

// SampleConfig represents a sample toml config for this plugin.
func (def *Defaults) SampleConfig() string {
return sampleConfig
}

// Description is a brief description of this processor plugin's behaviour.
func (def *Defaults) Description() string {
return "Defaults sets default value(s) for specified fields that are not set on incoming metrics."
}

// Apply contains the main implementation of this processor.
// For each metric in 'inputMetrics', it goes over each default pair.
// If the field in the pair does not exist on the metric, the associated default is added.
Expand Down
8 changes: 8 additions & 0 deletions plugins/processors/defaults/defaults_sample_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//go:generate go run ../../../tools/generate_plugindata/main.go
//go:generate go run ../../../tools/generate_plugindata/main.go --clean
// DON'T EDIT; This file is used as a template by tools/generate_plugindata
package defaults

func (def *Defaults) SampleConfig() string {
return `{{ .SampleConfig }}`
}
1 change: 1 addition & 0 deletions plugins/processors/enum/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ source tag or field is overwritten.
## Configuration

```toml
# Map enum values according to given table.
[[processors.enum]]
[[processors.enum.mapping]]
## Name of the field to map. Globs accepted.
Expand Down
Loading

0 comments on commit 2b1eb6f

Please sign in to comment.