Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Embed sample configurations into README for processors #11189

Merged
merged 3 commits into from
May 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion plugins/processors/aws/ec2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 10 additions & 0 deletions plugins/processors/aws/ec2/ec2.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
//go:generate ../../../../tools/readme_config_includer/generator
package ec2

import (
"context"
_ "embed"
"errors"
"fmt"
"strings"
Expand All @@ -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"`
Expand Down Expand Up @@ -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
Expand Down
8 changes: 0 additions & 8 deletions plugins/processors/aws/ec2/ec2_sample_config.go

This file was deleted.

2 changes: 1 addition & 1 deletion plugins/processors/clone/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
11 changes: 11 additions & 0 deletions plugins/processors/clone/clone.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
//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
NameSuffix string
Tags map[string]string
}

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

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

Expand Down
8 changes: 0 additions & 8 deletions plugins/processors/clone/clone_sample_config.go

This file was deleted.

2 changes: 1 addition & 1 deletion plugins/processors/converter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions plugins/processors/converter/converter.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//go:generate ../../../tools/readme_config_includer/generator
package converter

import (
_ "embed"
"errors"
"fmt"
"math"
Expand All @@ -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"`
Expand Down Expand Up @@ -42,6 +48,10 @@ type ConversionFilter struct {
Float filter.Filter
}

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

func (p *Converter) Init() error {
return p.compile()
}
Expand Down
8 changes: 0 additions & 8 deletions plugins/processors/converter/converter_sample_config.go

This file was deleted.

2 changes: 1 addition & 1 deletion plugins/processors/date/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions plugins/processors/date/date.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//go:generate ../../../tools/readme_config_includer/generator
package date

import (
_ "embed"
"errors"
"time"

Expand All @@ -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 {
Expand All @@ -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 {
Expand Down
8 changes: 0 additions & 8 deletions plugins/processors/date/date_sample_config.go

This file was deleted.

2 changes: 1 addition & 1 deletion plugins/processors/dedup/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions plugins/processors/dedup/dedup.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
//go:generate ../../../tools/readme_config_includer/generator
package dedup

import (
_ "embed"
"time"

"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/config"
"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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 0 additions & 8 deletions plugins/processors/dedup/dedup_sample_config.go

This file was deleted.

2 changes: 1 addition & 1 deletion plugins/processors/defaults/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions plugins/processors/defaults/defaults.go
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
8 changes: 0 additions & 8 deletions plugins/processors/defaults/defaults_sample_config.go

This file was deleted.

2 changes: 1 addition & 1 deletion plugins/processors/enum/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Expand Down
10 changes: 10 additions & 0 deletions plugins/processors/enum/enum.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//go:generate ../../../tools/readme_config_includer/generator
package enum

import (
_ "embed"
"fmt"
"strconv"

Expand All @@ -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"`

Expand All @@ -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)
Expand Down
8 changes: 0 additions & 8 deletions plugins/processors/enum/enum_sample_config.go

This file was deleted.

2 changes: 1 addition & 1 deletion plugins/processors/execd/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 10 additions & 0 deletions plugins/processors/execd/execd.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
//go:generate ../../../tools/readme_config_includer/generator
package execd

import (
"bufio"
_ "embed"
"errors"
"fmt"
"io"
Expand All @@ -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"`
Expand All @@ -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)
Expand Down
Loading