From 3aa020a7a36f8c06c8511ad65994b97cb13cb7aa Mon Sep 17 00:00:00 2001 From: Sven Rebhan <36194019+srebhan@users.noreply.github.com> Date: Wed, 25 May 2022 16:59:41 +0200 Subject: [PATCH] chore: Embed sample configurations into README for processors (#11189) --- Makefile | 4 ++-- plugins/processors/aws/ec2/README.md | 2 +- plugins/processors/aws/ec2/ec2.go | 10 ++++++++++ plugins/processors/aws/ec2/ec2_sample_config.go | 8 -------- plugins/processors/clone/README.md | 2 +- plugins/processors/clone/clone.go | 11 +++++++++++ plugins/processors/clone/clone_sample_config.go | 8 -------- plugins/processors/converter/README.md | 2 +- plugins/processors/converter/converter.go | 10 ++++++++++ .../processors/converter/converter_sample_config.go | 8 -------- plugins/processors/date/README.md | 2 +- plugins/processors/date/date.go | 10 ++++++++++ plugins/processors/date/date_sample_config.go | 8 -------- plugins/processors/dedup/README.md | 2 +- plugins/processors/dedup/dedup.go | 10 ++++++++++ plugins/processors/dedup/dedup_sample_config.go | 8 -------- plugins/processors/defaults/README.md | 2 +- plugins/processors/defaults/defaults.go | 10 ++++++++++ .../processors/defaults/defaults_sample_config.go | 8 -------- plugins/processors/enum/README.md | 2 +- plugins/processors/enum/enum.go | 10 ++++++++++ plugins/processors/enum/enum_sample_config.go | 8 -------- plugins/processors/execd/README.md | 2 +- plugins/processors/execd/execd.go | 10 ++++++++++ plugins/processors/execd/execd_sample_config.go | 8 -------- plugins/processors/filepath/README.md | 2 +- plugins/processors/filepath/filepath.go | 10 ++++++++++ .../processors/filepath/filepath_sample_config.go | 8 -------- plugins/processors/ifname/README.md | 2 +- plugins/processors/ifname/ifname.go | 10 ++++++++++ plugins/processors/ifname/ifname_sample_config.go | 8 -------- plugins/processors/noise/README.md | 2 +- plugins/processors/noise/noise.go | 13 ++++++++++++- plugins/processors/noise/noise_sample_config.go | 8 -------- plugins/processors/override/README.md | 2 +- plugins/processors/override/override.go | 11 +++++++++++ .../processors/override/override_sample_config.go | 8 -------- plugins/processors/parser/README.md | 2 +- plugins/processors/parser/parser.go | 11 +++++++++++ plugins/processors/parser/parser_sample_config.go | 8 -------- plugins/processors/pivot/README.md | 2 +- plugins/processors/pivot/pivot.go | 11 +++++++++++ plugins/processors/pivot/pivot_sample_config.go | 8 -------- plugins/processors/port_name/README.md | 2 +- plugins/processors/port_name/port_name.go | 10 ++++++++++ .../processors/port_name/port_name_sample_config.go | 8 -------- plugins/processors/printer/README.md | 2 +- plugins/processors/printer/printer.go | 10 ++++++++++ plugins/processors/printer/printer_sample_config.go | 8 -------- plugins/processors/regex/README.md | 2 +- plugins/processors/regex/regex.go | 10 ++++++++++ plugins/processors/regex/regex_sample_config.go | 8 -------- plugins/processors/rename/README.md | 2 +- plugins/processors/rename/rename.go | 11 +++++++++++ plugins/processors/rename/rename_sample_config.go | 8 -------- plugins/processors/reverse_dns/README.md | 2 +- plugins/processors/reverse_dns/reverse_dns.go | 10 ++++++++++ .../reverse_dns/reverse_dns_sample_config.go | 8 -------- plugins/processors/s2geo/README.md | 2 +- plugins/processors/s2geo/s2geo.go | 11 +++++++++++ plugins/processors/s2geo/s2geo_sample_config.go | 8 -------- plugins/processors/starlark/README.md | 2 +- plugins/processors/starlark/starlark.go | 10 ++++++++++ .../processors/starlark/starlark_sample_config.go | 8 -------- plugins/processors/strings/README.md | 2 +- plugins/processors/strings/strings.go | 10 ++++++++++ plugins/processors/strings/strings_sample_config.go | 8 -------- plugins/processors/tag_limit/README.md | 2 +- plugins/processors/tag_limit/tag_limit.go | 10 ++++++++++ .../processors/tag_limit/tag_limit_sample_config.go | 8 -------- plugins/processors/template/README.md | 2 +- plugins/processors/template/template.go | 10 ++++++++++ .../processors/template/template_sample_config.go | 8 -------- plugins/processors/topk/README.md | 2 +- plugins/processors/topk/topk.go | 10 ++++++++++ plugins/processors/topk/topk_sample_config.go | 8 -------- plugins/processors/unpivot/README.md | 2 +- plugins/processors/unpivot/unpivot.go | 11 +++++++++++ plugins/processors/unpivot/unpivot_sample_config.go | 8 -------- 79 files changed, 297 insertions(+), 237 deletions(-) delete mode 100644 plugins/processors/aws/ec2/ec2_sample_config.go delete mode 100644 plugins/processors/clone/clone_sample_config.go delete mode 100644 plugins/processors/converter/converter_sample_config.go delete mode 100644 plugins/processors/date/date_sample_config.go delete mode 100644 plugins/processors/dedup/dedup_sample_config.go delete mode 100644 plugins/processors/defaults/defaults_sample_config.go delete mode 100644 plugins/processors/enum/enum_sample_config.go delete mode 100644 plugins/processors/execd/execd_sample_config.go delete mode 100644 plugins/processors/filepath/filepath_sample_config.go delete mode 100644 plugins/processors/ifname/ifname_sample_config.go delete mode 100644 plugins/processors/noise/noise_sample_config.go delete mode 100644 plugins/processors/override/override_sample_config.go delete mode 100644 plugins/processors/parser/parser_sample_config.go delete mode 100644 plugins/processors/pivot/pivot_sample_config.go delete mode 100644 plugins/processors/port_name/port_name_sample_config.go delete mode 100644 plugins/processors/printer/printer_sample_config.go delete mode 100644 plugins/processors/regex/regex_sample_config.go delete mode 100644 plugins/processors/rename/rename_sample_config.go delete mode 100644 plugins/processors/reverse_dns/reverse_dns_sample_config.go delete mode 100644 plugins/processors/s2geo/s2geo_sample_config.go delete mode 100644 plugins/processors/starlark/starlark_sample_config.go delete mode 100644 plugins/processors/strings/strings_sample_config.go delete mode 100644 plugins/processors/tag_limit/tag_limit_sample_config.go delete mode 100644 plugins/processors/template/template_sample_config.go delete mode 100644 plugins/processors/topk/topk_sample_config.go delete mode 100644 plugins/processors/unpivot/unpivot_sample_config.go diff --git a/Makefile b/Makefile index fcaa2a76f6061..ace542df4997b 100644 --- a/Makefile +++ b/Makefile @@ -126,11 +126,11 @@ generate_plugins_%: build_generator go generate -run="plugindata/main.go$$" ./plugins/$*/... .PHONY: generate -generate: insert_config_to_readme_inputs insert_config_to_readme_outputs generate_plugins_processors generate_plugins_aggregators +generate: insert_config_to_readme_inputs insert_config_to_readme_outputs insert_config_to_readme_processors generate_plugins_aggregators .PHONY: generate-clean generate-clean: - go generate -run="plugindata/main.go --clean" ./plugins/processors/... ./plugins/aggregators/... + go generate -run="plugindata/main.go --clean" ./plugins/aggregators/... .PHONY: build build: diff --git a/plugins/processors/aws/ec2/README.md b/plugins/processors/aws/ec2/README.md index a064294c0cfbb..b35be3ed723bb 100644 --- a/plugins/processors/aws/ec2/README.md +++ b/plugins/processors/aws/ec2/README.md @@ -7,7 +7,7 @@ to metrics associated with EC2 instances. ## Configuration -```toml +```toml @sample.conf # Attach AWS EC2 metadata to metrics [[processors.aws_ec2]] ## Instance identity document tags to attach to metrics. diff --git a/plugins/processors/aws/ec2/ec2.go b/plugins/processors/aws/ec2/ec2.go index 059189e47f66e..eae5adac71b6f 100644 --- a/plugins/processors/aws/ec2/ec2.go +++ b/plugins/processors/aws/ec2/ec2.go @@ -1,7 +1,9 @@ +//go:generate ../../../../tools/readme_config_includer/generator package ec2 import ( "context" + _ "embed" "errors" "fmt" "strings" @@ -20,6 +22,10 @@ import ( "github.com/influxdata/telegraf/plugins/processors" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + type AwsEc2Processor struct { ImdsTags []string `toml:"imds_tags"` EC2Tags []string `toml:"ec2_tags"` @@ -57,6 +63,10 @@ var allowedImdsTags = map[string]struct{}{ "version": {}, } +func (*AwsEc2Processor) SampleConfig() string { + return sampleConfig +} + func (r *AwsEc2Processor) Add(metric telegraf.Metric, _ telegraf.Accumulator) error { r.parallel.Enqueue(metric) return nil diff --git a/plugins/processors/aws/ec2/ec2_sample_config.go b/plugins/processors/aws/ec2/ec2_sample_config.go deleted file mode 100644 index c7da40ae07bfb..0000000000000 --- a/plugins/processors/aws/ec2/ec2_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//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 }}` -} diff --git a/plugins/processors/clone/README.md b/plugins/processors/clone/README.md index 837f2d8fc1070..287cf666efb02 100644 --- a/plugins/processors/clone/README.md +++ b/plugins/processors/clone/README.md @@ -24,7 +24,7 @@ having several hosts (modifying ``host`` tag). ## Configuration -```toml +```toml @sample.conf # Apply metric modifications using override semantics. [[processors.clone]] ## All modifications on inputs and aggregators can be overridden: diff --git a/plugins/processors/clone/clone.go b/plugins/processors/clone/clone.go index 567115fea4ba5..c658b197624c4 100644 --- a/plugins/processors/clone/clone.go +++ b/plugins/processors/clone/clone.go @@ -1,10 +1,17 @@ +//go:generate ../../../tools/readme_config_includer/generator package clone import ( + _ "embed" + "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/plugins/processors" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + type Clone struct { NameOverride string NamePrefix string @@ -12,6 +19,10 @@ type Clone struct { Tags map[string]string } +func (*Clone) SampleConfig() string { + return sampleConfig +} + func (c *Clone) Apply(in ...telegraf.Metric) []telegraf.Metric { cloned := []telegraf.Metric{} diff --git a/plugins/processors/clone/clone_sample_config.go b/plugins/processors/clone/clone_sample_config.go deleted file mode 100644 index 5576b6147663d..0000000000000 --- a/plugins/processors/clone/clone_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//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 }}` -} diff --git a/plugins/processors/converter/README.md b/plugins/processors/converter/README.md index 96d4546ddf1d2..3b15a0a101cb6 100644 --- a/plugins/processors/converter/README.md +++ b/plugins/processors/converter/README.md @@ -13,7 +13,7 @@ will overwrite one another. ## Configuration -```toml +```toml @sample.conf # Convert values to another metric value type [[processors.converter]] ## Tags to convert diff --git a/plugins/processors/converter/converter.go b/plugins/processors/converter/converter.go index 4c18e22f45398..374c2d20238b3 100644 --- a/plugins/processors/converter/converter.go +++ b/plugins/processors/converter/converter.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package converter import ( + _ "embed" "errors" "fmt" "math" @@ -13,6 +15,10 @@ import ( "github.com/influxdata/telegraf/plugins/processors" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + type Conversion struct { Measurement []string `toml:"measurement"` Tag []string `toml:"tag"` @@ -42,6 +48,10 @@ type ConversionFilter struct { Float filter.Filter } +func (*Converter) SampleConfig() string { + return sampleConfig +} + func (p *Converter) Init() error { return p.compile() } diff --git a/plugins/processors/converter/converter_sample_config.go b/plugins/processors/converter/converter_sample_config.go deleted file mode 100644 index 2ee99dddc29df..0000000000000 --- a/plugins/processors/converter/converter_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//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 }}` -} diff --git a/plugins/processors/date/README.md b/plugins/processors/date/README.md index 42811302989c3..59064c3ad017d 100644 --- a/plugins/processors/date/README.md +++ b/plugins/processors/date/README.md @@ -12,7 +12,7 @@ A few example usecases include: ## Configuration -```toml +```toml @sample.conf # Dates measurements, tags, and fields that pass through this filter. [[processors.date]] ## New tag to create diff --git a/plugins/processors/date/date.go b/plugins/processors/date/date.go index 5994214537b80..7d94723683d5d 100644 --- a/plugins/processors/date/date.go +++ b/plugins/processors/date/date.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package date import ( + _ "embed" "errors" "time" @@ -9,6 +11,10 @@ import ( "github.com/influxdata/telegraf/plugins/processors" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + const defaultTimezone = "UTC" type Date struct { @@ -21,6 +27,10 @@ type Date struct { location *time.Location } +func (*Date) SampleConfig() string { + return sampleConfig +} + func (d *Date) Init() error { // Check either TagKey or FieldKey specified if len(d.FieldKey) > 0 && len(d.TagKey) > 0 { diff --git a/plugins/processors/date/date_sample_config.go b/plugins/processors/date/date_sample_config.go deleted file mode 100644 index 5e957b9c1fe1c..0000000000000 --- a/plugins/processors/date/date_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//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 }}` -} diff --git a/plugins/processors/dedup/README.md b/plugins/processors/dedup/README.md index dc4f0cc718537..75e61ec2c5ded 100644 --- a/plugins/processors/dedup/README.md +++ b/plugins/processors/dedup/README.md @@ -4,7 +4,7 @@ Filter metrics whose field values are exact repetitions of the previous values. ## Configuration -```toml +```toml @sample.conf # Filter metrics with repeating field values [[processors.dedup]] ## Maximum time to suppress output diff --git a/plugins/processors/dedup/dedup.go b/plugins/processors/dedup/dedup.go index 0c49053fac0f1..34d2172a285d3 100644 --- a/plugins/processors/dedup/dedup.go +++ b/plugins/processors/dedup/dedup.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package dedup import ( + _ "embed" "time" "github.com/influxdata/telegraf" @@ -8,6 +10,10 @@ import ( "github.com/influxdata/telegraf/plugins/processors" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + type Dedup struct { DedupInterval config.Duration `toml:"dedup_interval"` FlushTime time.Time @@ -36,6 +42,10 @@ func (d *Dedup) save(metric telegraf.Metric, id uint64) { d.Cache[id].Accept() } +func (*Dedup) SampleConfig() string { + return sampleConfig +} + // main processing method func (d *Dedup) Apply(metrics ...telegraf.Metric) []telegraf.Metric { idx := 0 diff --git a/plugins/processors/dedup/dedup_sample_config.go b/plugins/processors/dedup/dedup_sample_config.go deleted file mode 100644 index 84a3c7dd6d632..0000000000000 --- a/plugins/processors/dedup/dedup_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//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 }}` -} diff --git a/plugins/processors/defaults/README.md b/plugins/processors/defaults/README.md index ee04441931766..db2978ec366c1 100644 --- a/plugins/processors/defaults/README.md +++ b/plugins/processors/defaults/README.md @@ -12,7 +12,7 @@ Telegraf minimum version: Telegraf 1.15.0 ## Configuration -```toml +```toml @sample.conf ## Set default fields on your metric(s) when they are nil or empty [[processors.defaults]] ## Ensures a set of fields always exists on your metric(s) with their diff --git a/plugins/processors/defaults/defaults.go b/plugins/processors/defaults/defaults.go index 31c7e3baf6c5b..17f7364615df2 100644 --- a/plugins/processors/defaults/defaults.go +++ b/plugins/processors/defaults/defaults.go @@ -1,18 +1,28 @@ +//go:generate ../../../tools/readme_config_includer/generator package defaults import ( + _ "embed" "strings" "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/plugins/processors" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + // 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"` } +func (*Defaults) SampleConfig() string { + return sampleConfig +} + // 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. diff --git a/plugins/processors/defaults/defaults_sample_config.go b/plugins/processors/defaults/defaults_sample_config.go deleted file mode 100644 index b30943155c802..0000000000000 --- a/plugins/processors/defaults/defaults_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//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 }}` -} diff --git a/plugins/processors/enum/README.md b/plugins/processors/enum/README.md index 3a559a1ac1f92..94ed0e59400b2 100644 --- a/plugins/processors/enum/README.md +++ b/plugins/processors/enum/README.md @@ -11,7 +11,7 @@ source tag or field is overwritten. ## Configuration -```toml +```toml @sample.conf # Map enum values according to given table. [[processors.enum]] [[processors.enum.mapping]] diff --git a/plugins/processors/enum/enum.go b/plugins/processors/enum/enum.go index 0027b1f066d26..77797a82bf73a 100644 --- a/plugins/processors/enum/enum.go +++ b/plugins/processors/enum/enum.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package enum import ( + _ "embed" "fmt" "strconv" @@ -9,6 +11,10 @@ import ( "github.com/influxdata/telegraf/plugins/processors" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + type EnumMapper struct { Mappings []Mapping `toml:"mapping"` @@ -24,6 +30,10 @@ type Mapping struct { ValueMappings map[string]interface{} } +func (*EnumMapper) SampleConfig() string { + return sampleConfig +} + func (mapper *EnumMapper) Init() error { mapper.FieldFilters = make(map[string]filter.Filter) mapper.TagFilters = make(map[string]filter.Filter) diff --git a/plugins/processors/enum/enum_sample_config.go b/plugins/processors/enum/enum_sample_config.go deleted file mode 100644 index 314c2f53c4271..0000000000000 --- a/plugins/processors/enum/enum_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//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 enum - -func (mapper *EnumMapper) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/processors/execd/README.md b/plugins/processors/execd/README.md index 7a3e0cc1a874b..4c229341d2549 100644 --- a/plugins/processors/execd/README.md +++ b/plugins/processors/execd/README.md @@ -22,7 +22,7 @@ Telegraf minimum version: Telegraf 1.15.0 ## Configuration -```toml +```toml @sample.conf # Run executable as long-running processor plugin [[processors.execd]] ## One program to run as daemon. diff --git a/plugins/processors/execd/execd.go b/plugins/processors/execd/execd.go index 4deba08d6d703..65539e424c57e 100644 --- a/plugins/processors/execd/execd.go +++ b/plugins/processors/execd/execd.go @@ -1,7 +1,9 @@ +//go:generate ../../../tools/readme_config_includer/generator package execd import ( "bufio" + _ "embed" "errors" "fmt" "io" @@ -17,6 +19,10 @@ import ( "github.com/influxdata/telegraf/plugins/serializers" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + type Execd struct { Command []string `toml:"command"` Environment []string `toml:"environment"` @@ -43,6 +49,10 @@ func New() *Execd { } } +func (*Execd) SampleConfig() string { + return sampleConfig +} + func (e *Execd) Start(acc telegraf.Accumulator) error { var err error e.parser, err = parsers.NewParser(e.parserConfig) diff --git a/plugins/processors/execd/execd_sample_config.go b/plugins/processors/execd/execd_sample_config.go deleted file mode 100644 index bc59d8ef367c8..0000000000000 --- a/plugins/processors/execd/execd_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//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 execd - -func (e *Execd) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/processors/filepath/README.md b/plugins/processors/filepath/README.md index 731980a9aa477..12f1080a3e97e 100644 --- a/plugins/processors/filepath/README.md +++ b/plugins/processors/filepath/README.md @@ -28,7 +28,7 @@ Telegraf minimum version: Telegraf 1.15.0 ## Configuration -```toml +```toml @sample.conf # Performs file path manipulations on tags and fields [[processors.filepath]] ## Treat the tag value as a path and convert it to its last element, storing the result in a new tag diff --git a/plugins/processors/filepath/filepath.go b/plugins/processors/filepath/filepath.go index 507c53b8af110..0618b8adefcc9 100644 --- a/plugins/processors/filepath/filepath.go +++ b/plugins/processors/filepath/filepath.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package filepath import ( + _ "embed" "path/filepath" "strings" @@ -8,6 +10,10 @@ import ( "github.com/influxdata/telegraf/plugins/processors" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + type Options struct { BaseName []BaseOpts `toml:"basename"` DirName []BaseOpts `toml:"dirname"` @@ -95,6 +101,10 @@ func (o *Options) processMetric(metric telegraf.Metric) { } } +func (*Options) SampleConfig() string { + return sampleConfig +} + func (o *Options) Apply(in ...telegraf.Metric) []telegraf.Metric { for _, m := range in { o.processMetric(m) diff --git a/plugins/processors/filepath/filepath_sample_config.go b/plugins/processors/filepath/filepath_sample_config.go deleted file mode 100644 index cbcb7a327471e..0000000000000 --- a/plugins/processors/filepath/filepath_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//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 filepath - -func (o *Options) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/processors/ifname/README.md b/plugins/processors/ifname/README.md index 7c1d17805b53e..0f3a0fcd2deee 100644 --- a/plugins/processors/ifname/README.md +++ b/plugins/processors/ifname/README.md @@ -6,7 +6,7 @@ Telegraf minimum version: Telegraf 1.15.0 ## Configuration -```toml +```toml @sample.conf # Add a tag of the network interface name looked up over SNMP by interface number [[processors.ifname]] ## Name of tag holding the interface number diff --git a/plugins/processors/ifname/ifname.go b/plugins/processors/ifname/ifname.go index 9f8346f47f023..9c5c39dd0fa94 100644 --- a/plugins/processors/ifname/ifname.go +++ b/plugins/processors/ifname/ifname.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package ifname import ( + _ "embed" "errors" "fmt" "strconv" @@ -15,6 +17,10 @@ import ( "github.com/influxdata/telegraf/plugins/processors" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + type nameMap map[uint64]string type keyType = string type valType = nameMap @@ -54,6 +60,10 @@ type IfName struct { const minRetry = 5 * time.Minute +func (*IfName) SampleConfig() string { + return sampleConfig +} + func (d *IfName) Init() error { d.getMapRemote = d.getMapRemoteNoMock d.makeTable = d.makeTableNoMock diff --git a/plugins/processors/ifname/ifname_sample_config.go b/plugins/processors/ifname/ifname_sample_config.go deleted file mode 100644 index e6347439135d7..0000000000000 --- a/plugins/processors/ifname/ifname_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//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 ifname - -func (d *IfName) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/processors/noise/README.md b/plugins/processors/noise/README.md index ab39fc879691a..a460a4c3e259c 100644 --- a/plugins/processors/noise/README.md +++ b/plugins/processors/noise/README.md @@ -7,7 +7,7 @@ Depending on the function, various parameters need to be configured: Depending on the choice of the distribution function, the respective parameters must be set. Default settings are `noise_type = "laplacian"` with `mu = 0.0` and `scale = 1.0`: -```toml +```toml @sample.conf # Adds noise to numerical fields [[processors.noise]] ## Specified the type of the random distribution. diff --git a/plugins/processors/noise/noise.go b/plugins/processors/noise/noise.go index 5b5901ff10995..03e174c9b0614 100644 --- a/plugins/processors/noise/noise.go +++ b/plugins/processors/noise/noise.go @@ -1,16 +1,23 @@ +//go:generate ../../../tools/readme_config_includer/generator package noise import ( + _ "embed" "fmt" "math" "reflect" + "gonum.org/v1/gonum/stat/distuv" + "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/filter" "github.com/influxdata/telegraf/plugins/processors" - "gonum.org/v1/gonum/stat/distuv" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + const ( defaultScale = 1.0 defaultMin = -1.0 @@ -79,6 +86,10 @@ func (p *Noise) addNoise(value interface{}) interface{} { return value } +func (*Noise) SampleConfig() string { + return sampleConfig +} + // Creates a filter for Include and Exclude fields and sets the desired noise // distribution func (p *Noise) Init() error { diff --git a/plugins/processors/noise/noise_sample_config.go b/plugins/processors/noise/noise_sample_config.go deleted file mode 100644 index fc256aa4352a1..0000000000000 --- a/plugins/processors/noise/noise_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//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 noise - -func (p *Noise) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/processors/override/README.md b/plugins/processors/override/README.md index ff454b9f74a33..15e829406e4fd 100644 --- a/plugins/processors/override/README.md +++ b/plugins/processors/override/README.md @@ -23,7 +23,7 @@ are adhered to irrespective of input plugin configurations, e.g. by ## Configuration -```toml +```toml @sample.conf # Apply metric modifications using override semantics. [[processors.override]] ## All modifications on inputs and aggregators can be overridden: diff --git a/plugins/processors/override/override.go b/plugins/processors/override/override.go index 3fab35b94fdc4..0b24bf7e88224 100644 --- a/plugins/processors/override/override.go +++ b/plugins/processors/override/override.go @@ -1,10 +1,17 @@ +//go:generate ../../../tools/readme_config_includer/generator package override import ( + _ "embed" + "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/plugins/processors" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + type Override struct { NameOverride string NamePrefix string @@ -12,6 +19,10 @@ type Override struct { Tags map[string]string } +func (*Override) SampleConfig() string { + return sampleConfig +} + func (p *Override) Apply(in ...telegraf.Metric) []telegraf.Metric { for _, metric := range in { if len(p.NameOverride) > 0 { diff --git a/plugins/processors/override/override_sample_config.go b/plugins/processors/override/override_sample_config.go deleted file mode 100644 index 19547c2931d15..0000000000000 --- a/plugins/processors/override/override_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//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 override - -func (p *Override) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/processors/parser/README.md b/plugins/processors/parser/README.md index 1adf629c41048..0e4e1a783769f 100644 --- a/plugins/processors/parser/README.md +++ b/plugins/processors/parser/README.md @@ -5,7 +5,7 @@ creates new metrics based on the contents of the field. ## Configuration -```toml +```toml @sample.conf # Parse a value in a specified field/tag(s) and add the result in a new metric [[processors.parser]] ## The name of the fields whose value will be parsed. diff --git a/plugins/processors/parser/parser.go b/plugins/processors/parser/parser.go index 9cdb1b48a8a4c..bc8a9db02610a 100644 --- a/plugins/processors/parser/parser.go +++ b/plugins/processors/parser/parser.go @@ -1,12 +1,19 @@ +//go:generate ../../../tools/readme_config_includer/generator package parser import ( + _ "embed" + "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/models" "github.com/influxdata/telegraf/plugins/parsers" "github.com/influxdata/telegraf/plugins/processors" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + type Parser struct { parsers.Config DropOriginal bool `toml:"drop_original"` @@ -16,6 +23,10 @@ type Parser struct { parser telegraf.Parser } +func (*Parser) SampleConfig() string { + return sampleConfig +} + func (p *Parser) Apply(metrics ...telegraf.Metric) []telegraf.Metric { if p.parser == nil { var err error diff --git a/plugins/processors/parser/parser_sample_config.go b/plugins/processors/parser/parser_sample_config.go deleted file mode 100644 index fe0bd41f2a428..0000000000000 --- a/plugins/processors/parser/parser_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//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 parser - -func (p *Parser) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/processors/pivot/README.md b/plugins/processors/pivot/README.md index 0277b9e7a4c64..732e758e3735f 100644 --- a/plugins/processors/pivot/README.md +++ b/plugins/processors/pivot/README.md @@ -10,7 +10,7 @@ To perform the reverse operation use the [unpivot] processor. ## Configuration -```toml +```toml @sample.conf # Rotate a single valued metric into a multi field metric [[processors.pivot]] ## Tag to use for naming the new field. diff --git a/plugins/processors/pivot/pivot.go b/plugins/processors/pivot/pivot.go index 4ebdf1c0e9c3e..2832a3b5ff5d5 100644 --- a/plugins/processors/pivot/pivot.go +++ b/plugins/processors/pivot/pivot.go @@ -1,15 +1,26 @@ +//go:generate ../../../tools/readme_config_includer/generator package pivot import ( + _ "embed" + "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/plugins/processors" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + type Pivot struct { TagKey string `toml:"tag_key"` ValueKey string `toml:"value_key"` } +func (*Pivot) SampleConfig() string { + return sampleConfig +} + func (p *Pivot) Apply(metrics ...telegraf.Metric) []telegraf.Metric { for _, m := range metrics { key, ok := m.GetTag(p.TagKey) diff --git a/plugins/processors/pivot/pivot_sample_config.go b/plugins/processors/pivot/pivot_sample_config.go deleted file mode 100644 index 7e6981128f12b..0000000000000 --- a/plugins/processors/pivot/pivot_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//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 pivot - -func (p *Pivot) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/processors/port_name/README.md b/plugins/processors/port_name/README.md index 54c16b00171ff..81515cc969824 100644 --- a/plugins/processors/port_name/README.md +++ b/plugins/processors/port_name/README.md @@ -10,7 +10,7 @@ Telegraf minimum version: Telegraf 1.15.0 ## Configuration -```toml +```toml @sample.conf # Given a tag/field of a TCP or UDP port number, add a tag/field of the service name looked up in the system services file [[processors.port_name]] ## Name of tag holding the port number diff --git a/plugins/processors/port_name/port_name.go b/plugins/processors/port_name/port_name.go index 16c69f2bedee7..7079b62e06a8a 100644 --- a/plugins/processors/port_name/port_name.go +++ b/plugins/processors/port_name/port_name.go @@ -1,7 +1,9 @@ +//go:generate ../../../tools/readme_config_includer/generator package port_name import ( "bufio" + _ "embed" "io" "os" "strconv" @@ -11,6 +13,10 @@ import ( "github.com/influxdata/telegraf/plugins/processors" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + type sMap map[string]map[int]string // "https" == services["tcp"][443] var services sMap @@ -78,6 +84,10 @@ func readServices(r io.Reader) sMap { return services } +func (*PortName) SampleConfig() string { + return sampleConfig +} + func (pn *PortName) Apply(metrics ...telegraf.Metric) []telegraf.Metric { for _, m := range metrics { var portProto string diff --git a/plugins/processors/port_name/port_name_sample_config.go b/plugins/processors/port_name/port_name_sample_config.go deleted file mode 100644 index 73b2bd91f7eb2..0000000000000 --- a/plugins/processors/port_name/port_name_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//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 port_name - -func (pn *PortName) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/processors/printer/README.md b/plugins/processors/printer/README.md index 453690275da7e..292d6c8cc56f9 100644 --- a/plugins/processors/printer/README.md +++ b/plugins/processors/printer/README.md @@ -4,7 +4,7 @@ The printer processor plugin simple prints every metric passing through it. ## Configuration -```toml +```toml @sample.conf # Print all metrics that pass through this filter. [[processors.printer]] ``` diff --git a/plugins/processors/printer/printer.go b/plugins/processors/printer/printer.go index 9706f81bf39c7..60c88f3bbe0f2 100644 --- a/plugins/processors/printer/printer.go +++ b/plugins/processors/printer/printer.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package printer import ( + _ "embed" "fmt" "github.com/influxdata/telegraf" @@ -9,10 +11,18 @@ import ( "github.com/influxdata/telegraf/plugins/serializers/influx" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + type Printer struct { serializer serializers.Serializer } +func (*Printer) SampleConfig() string { + return sampleConfig +} + func (p *Printer) Apply(in ...telegraf.Metric) []telegraf.Metric { for _, metric := range in { octets, err := p.serializer.Serialize(metric) diff --git a/plugins/processors/printer/printer_sample_config.go b/plugins/processors/printer/printer_sample_config.go deleted file mode 100644 index ebd8806659c99..0000000000000 --- a/plugins/processors/printer/printer_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//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 printer - -func (p *Printer) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/processors/regex/README.md b/plugins/processors/regex/README.md index 8e31153c94ce4..b6c9d3ed19a44 100644 --- a/plugins/processors/regex/README.md +++ b/plugins/processors/regex/README.md @@ -11,7 +11,7 @@ For metrics transforms, `key` denotes the element that should be transformed. Fu ## Configuration -```toml +```toml @sample.conf # Transforms tag and field values as well as measurement, tag and field names with regex pattern [[processors.regex]] namepass = ["nginx_requests"] diff --git a/plugins/processors/regex/regex.go b/plugins/processors/regex/regex.go index cc811c1f61098..c26969b78670e 100644 --- a/plugins/processors/regex/regex.go +++ b/plugins/processors/regex/regex.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package regex import ( + _ "embed" "fmt" "regexp" @@ -9,6 +11,10 @@ import ( "github.com/influxdata/telegraf/plugins/processors" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + type Regex struct { Tags []converter `toml:"tags"` Fields []converter `toml:"fields"` @@ -27,6 +33,10 @@ type converter struct { Append bool `toml:"append"` } +func (*Regex) SampleConfig() string { + return sampleConfig +} + func (r *Regex) Init() error { r.regexCache = make(map[string]*regexp.Regexp) diff --git a/plugins/processors/regex/regex_sample_config.go b/plugins/processors/regex/regex_sample_config.go deleted file mode 100644 index b51a546f18ebf..0000000000000 --- a/plugins/processors/regex/regex_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//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 regex - -func (r *Regex) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/processors/rename/README.md b/plugins/processors/rename/README.md index 411db590eeb2e..bbd545c2634e4 100644 --- a/plugins/processors/rename/README.md +++ b/plugins/processors/rename/README.md @@ -4,7 +4,7 @@ The `rename` processor renames measurements, fields, and tags. ## Configuration -```toml +```toml @sample.conf # Rename measurements, tags, and fields that pass through this filter. [[processors.rename]] ## Specify one sub-table per rename operation. diff --git a/plugins/processors/rename/rename.go b/plugins/processors/rename/rename.go index 14e2163f3f2af..03080451309c7 100644 --- a/plugins/processors/rename/rename.go +++ b/plugins/processors/rename/rename.go @@ -1,10 +1,17 @@ +//go:generate ../../../tools/readme_config_includer/generator package rename import ( + _ "embed" + "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/plugins/processors" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + type Replace struct { Measurement string `toml:"measurement"` Tag string `toml:"tag"` @@ -16,6 +23,10 @@ type Rename struct { Replaces []Replace `toml:"replace"` } +func (*Rename) SampleConfig() string { + return sampleConfig +} + func (r *Rename) Apply(in ...telegraf.Metric) []telegraf.Metric { for _, point := range in { for _, replace := range r.Replaces { diff --git a/plugins/processors/rename/rename_sample_config.go b/plugins/processors/rename/rename_sample_config.go deleted file mode 100644 index ac4fad883760e..0000000000000 --- a/plugins/processors/rename/rename_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//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 rename - -func (r *Rename) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/processors/reverse_dns/README.md b/plugins/processors/reverse_dns/README.md index 4c3b70c4e3854..f13a692859f0c 100644 --- a/plugins/processors/reverse_dns/README.md +++ b/plugins/processors/reverse_dns/README.md @@ -7,7 +7,7 @@ Telegraf minimum version: Telegraf 1.15.0 ## Configuration -```toml +```toml @sample.conf # ReverseDNS does a reverse lookup on IP addresses to retrieve the DNS name [[processors.reverse_dns]] ## For optimal performance, you may want to limit which metrics are passed to this diff --git a/plugins/processors/reverse_dns/reverse_dns.go b/plugins/processors/reverse_dns/reverse_dns.go index 9b98789ce1f33..a46166950f51a 100644 --- a/plugins/processors/reverse_dns/reverse_dns.go +++ b/plugins/processors/reverse_dns/reverse_dns.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package reverse_dns import ( + _ "embed" "time" "github.com/influxdata/telegraf" @@ -9,6 +11,10 @@ import ( "github.com/influxdata/telegraf/plugins/processors" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + type lookupEntry struct { Tag string `toml:"tag"` Field string `toml:"field"` @@ -28,6 +34,10 @@ type ReverseDNS struct { Log telegraf.Logger `toml:"-"` } +func (*ReverseDNS) SampleConfig() string { + return sampleConfig +} + func (r *ReverseDNS) Start(acc telegraf.Accumulator) error { r.acc = acc r.reverseDNSCache = NewReverseDNSCache( diff --git a/plugins/processors/reverse_dns/reverse_dns_sample_config.go b/plugins/processors/reverse_dns/reverse_dns_sample_config.go deleted file mode 100644 index ebfcb6a7e20c2..0000000000000 --- a/plugins/processors/reverse_dns/reverse_dns_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//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 reverse_dns - -func (r *ReverseDNS) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/processors/s2geo/README.md b/plugins/processors/s2geo/README.md index c58c80cfe3df6..d3a7d51424317 100644 --- a/plugins/processors/s2geo/README.md +++ b/plugins/processors/s2geo/README.md @@ -6,7 +6,7 @@ The `lat` and `lon` fields values should contain WGS-84 coordinates in decimal d ## Configuration -```toml +```toml @sample.conf # Add the S2 Cell ID as a tag based on latitude and longitude fields [[processors.s2geo]] ## The name of the lat and lon fields containing WGS-84 latitude and diff --git a/plugins/processors/s2geo/s2geo.go b/plugins/processors/s2geo/s2geo.go index f67f4c08e95be..479237270d385 100644 --- a/plugins/processors/s2geo/s2geo.go +++ b/plugins/processors/s2geo/s2geo.go @@ -1,13 +1,20 @@ +//go:generate ../../../tools/readme_config_includer/generator package s2geo import ( + _ "embed" "fmt" "github.com/golang/geo/s2" + "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/plugins/processors" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + type Geo struct { LatField string `toml:"lat_field"` LonField string `toml:"lon_field"` @@ -15,6 +22,10 @@ type Geo struct { CellLevel int `toml:"cell_level"` } +func (*Geo) SampleConfig() string { + return sampleConfig +} + func (g *Geo) Init() error { if g.CellLevel < 0 || g.CellLevel > 30 { return fmt.Errorf("invalid cell level %d", g.CellLevel) diff --git a/plugins/processors/s2geo/s2geo_sample_config.go b/plugins/processors/s2geo/s2geo_sample_config.go deleted file mode 100644 index ba713c8e38ae0..0000000000000 --- a/plugins/processors/s2geo/s2geo_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//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 s2geo - -func (g *Geo) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/processors/starlark/README.md b/plugins/processors/starlark/README.md index eab55ea2e1874..8578a8fe29c25 100644 --- a/plugins/processors/starlark/README.md +++ b/plugins/processors/starlark/README.md @@ -16,7 +16,7 @@ Telegraf minimum version: Telegraf 1.15.0 ## Configuration -```toml +```toml @sample.conf # Process metrics using a Starlark script [[processors.starlark]] ## The Starlark source can be set as a string in this configuration file, or diff --git a/plugins/processors/starlark/starlark.go b/plugins/processors/starlark/starlark.go index 4dad7f7590376..bf15927d60c69 100644 --- a/plugins/processors/starlark/starlark.go +++ b/plugins/processors/starlark/starlark.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package starlark import ( + _ "embed" "fmt" "github.com/influxdata/telegraf" @@ -9,12 +11,20 @@ import ( "go.starlark.net/starlark" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + type Starlark struct { common.StarlarkCommon results []telegraf.Metric } +func (*Starlark) SampleConfig() string { + return sampleConfig +} + func (s *Starlark) Init() error { err := s.StarlarkCommon.Init() if err != nil { diff --git a/plugins/processors/starlark/starlark_sample_config.go b/plugins/processors/starlark/starlark_sample_config.go deleted file mode 100644 index 67d3483d7d0d3..0000000000000 --- a/plugins/processors/starlark/starlark_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//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 starlark - -func (s *Starlark) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/processors/strings/README.md b/plugins/processors/strings/README.md index b0b49c5f3d1f3..07536ddae9508 100644 --- a/plugins/processors/strings/README.md +++ b/plugins/processors/strings/README.md @@ -27,7 +27,7 @@ If you'd like to apply multiple processings to the same `tag_key` or `field_key` ## Configuration -```toml +```toml @sample.conf # Perform string processing on tags, fields, and measurements [[processors.strings]] ## Convert a field value to lowercase and store in a new field diff --git a/plugins/processors/strings/strings.go b/plugins/processors/strings/strings.go index 8cc3d5ba9c3d0..a331e2a52baed 100644 --- a/plugins/processors/strings/strings.go +++ b/plugins/processors/strings/strings.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package strings import ( + _ "embed" "encoding/base64" "strings" "unicode" @@ -10,6 +12,10 @@ import ( "github.com/influxdata/telegraf/plugins/processors" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + type Strings struct { Lowercase []converter `toml:"lowercase"` Uppercase []converter `toml:"uppercase"` @@ -267,6 +273,10 @@ func (s *Strings) initOnce() { s.init = true } +func (*Strings) SampleConfig() string { + return sampleConfig +} + func (s *Strings) Apply(in ...telegraf.Metric) []telegraf.Metric { s.initOnce() diff --git a/plugins/processors/strings/strings_sample_config.go b/plugins/processors/strings/strings_sample_config.go deleted file mode 100644 index 65bbc4b6d8df7..0000000000000 --- a/plugins/processors/strings/strings_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//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 strings - -func (s *Strings) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/processors/tag_limit/README.md b/plugins/processors/tag_limit/README.md index 35b319e5ec9e1..9552349b0e0ff 100644 --- a/plugins/processors/tag_limit/README.md +++ b/plugins/processors/tag_limit/README.md @@ -10,7 +10,7 @@ levels of cardinality are computationally and/or financially expensive. ## Configuration -```toml +```toml @sample.conf # Restricts the number of tags that can pass through this filter and chooses which tags to preserve when over the limit. [[processors.tag_limit]] ## Maximum number of tags to preserve diff --git a/plugins/processors/tag_limit/tag_limit.go b/plugins/processors/tag_limit/tag_limit.go index ba3b2a98f346d..3a85259144c99 100644 --- a/plugins/processors/tag_limit/tag_limit.go +++ b/plugins/processors/tag_limit/tag_limit.go @@ -1,12 +1,18 @@ +//go:generate ../../../tools/readme_config_includer/generator package tag_limit import ( + _ "embed" "fmt" "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/plugins/processors" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + type TagLimit struct { Limit int `toml:"limit"` Keep []string `toml:"keep"` @@ -31,6 +37,10 @@ func (d *TagLimit) initOnce() error { return nil } +func (*TagLimit) SampleConfig() string { + return sampleConfig +} + func (d *TagLimit) Apply(in ...telegraf.Metric) []telegraf.Metric { err := d.initOnce() if err != nil { diff --git a/plugins/processors/tag_limit/tag_limit_sample_config.go b/plugins/processors/tag_limit/tag_limit_sample_config.go deleted file mode 100644 index cb0d549e978eb..0000000000000 --- a/plugins/processors/tag_limit/tag_limit_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//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 tag_limit - -func (d *TagLimit) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/processors/template/README.md b/plugins/processors/template/README.md index 14d84cb0f39ca..f9c502d5b0e44 100644 --- a/plugins/processors/template/README.md +++ b/plugins/processors/template/README.md @@ -12,7 +12,7 @@ Read the full [Go Template Documentation][]. ## Configuration -```toml +```toml @sample.conf # Uses a Go template to create a new tag [[processors.template]] ## Tag to set with the output of the template. diff --git a/plugins/processors/template/template.go b/plugins/processors/template/template.go index 7391cd75ad470..a995e40718a02 100644 --- a/plugins/processors/template/template.go +++ b/plugins/processors/template/template.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package template import ( + _ "embed" "strings" "text/template" @@ -8,6 +10,10 @@ import ( "github.com/influxdata/telegraf/plugins/processors" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + type TemplateProcessor struct { Tag string `toml:"tag"` Template string `toml:"template"` @@ -15,6 +21,10 @@ type TemplateProcessor struct { tmpl *template.Template } +func (*TemplateProcessor) SampleConfig() string { + return sampleConfig +} + func (r *TemplateProcessor) Apply(in ...telegraf.Metric) []telegraf.Metric { // for each metric in "in" array for _, metric := range in { diff --git a/plugins/processors/template/template_sample_config.go b/plugins/processors/template/template_sample_config.go deleted file mode 100644 index 4b43dccb46371..0000000000000 --- a/plugins/processors/template/template_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//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 template - -func (r *TemplateProcessor) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/processors/topk/README.md b/plugins/processors/topk/README.md index f47fc87dd0111..fc2afb70a9910 100644 --- a/plugins/processors/topk/README.md +++ b/plugins/processors/topk/README.md @@ -17,7 +17,7 @@ Notes: ## Configuration -```toml +```toml @sample.conf # Print all metrics that pass through this filter. [[processors.topk]] ## How many seconds between aggregations diff --git a/plugins/processors/topk/topk.go b/plugins/processors/topk/topk.go index c7d239a0595dc..cb5a2ed0faa45 100644 --- a/plugins/processors/topk/topk.go +++ b/plugins/processors/topk/topk.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package topk import ( + _ "embed" "fmt" "math" "sort" @@ -13,6 +15,10 @@ import ( "github.com/influxdata/telegraf/plugins/processors" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + type TopK struct { Period config.Duration `toml:"period"` K int `toml:"k"` @@ -71,6 +77,10 @@ func sortMetrics(metrics []MetricAggregation, field string, reverse bool) { } } +func (*TopK) SampleConfig() string { + return sampleConfig +} + func (t *TopK) Reset() { t.cache = make(map[string][]telegraf.Metric) t.lastAggregation = time.Now() diff --git a/plugins/processors/topk/topk_sample_config.go b/plugins/processors/topk/topk_sample_config.go deleted file mode 100644 index 9aa2cede0fc85..0000000000000 --- a/plugins/processors/topk/topk_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//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 topk - -func (t *TopK) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/processors/unpivot/README.md b/plugins/processors/unpivot/README.md index c81da78dad4d2..92a4e7fc4fc13 100644 --- a/plugins/processors/unpivot/README.md +++ b/plugins/processors/unpivot/README.md @@ -6,7 +6,7 @@ To perform the reverse operation use the [pivot] processor. ## Configuration -```toml +```toml @sample.conf # Rotate multi field metric into several single field metrics [[processors.unpivot]] ## Tag to use for the name. diff --git a/plugins/processors/unpivot/unpivot.go b/plugins/processors/unpivot/unpivot.go index f58bbd2b02520..4e738ba1f146d 100644 --- a/plugins/processors/unpivot/unpivot.go +++ b/plugins/processors/unpivot/unpivot.go @@ -1,10 +1,17 @@ +//go:generate ../../../tools/readme_config_includer/generator package unpivot import ( + _ "embed" + "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/plugins/processors" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + type Unpivot struct { TagKey string `toml:"tag_key"` ValueKey string `toml:"value_key"` @@ -25,6 +32,10 @@ func copyWithoutFields(metric telegraf.Metric) telegraf.Metric { return m } +func (*Unpivot) SampleConfig() string { + return sampleConfig +} + func (p *Unpivot) Apply(metrics ...telegraf.Metric) []telegraf.Metric { fieldCount := 0 for _, m := range metrics { diff --git a/plugins/processors/unpivot/unpivot_sample_config.go b/plugins/processors/unpivot/unpivot_sample_config.go deleted file mode 100644 index f57d77ab56b01..0000000000000 --- a/plugins/processors/unpivot/unpivot_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//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 unpivot - -func (p *Unpivot) SampleConfig() string { - return `{{ .SampleConfig }}` -}