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

feat: Implement deprecation infrastructure #9857

Closed
wants to merge 47 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
5dd278f
Make version available in config.
Oct 4, 2021
d6ab0ca
Define interface for declaring a plugin as deprecated.
Oct 4, 2021
accd613
Define telegraf version for the non-tagged case.
Oct 4, 2021
815822d
Implement deprecation handling.
Oct 4, 2021
48facbf
Handle deprecation.
Oct 4, 2021
8a96533
Deprecate httpjson as a showcase.
Oct 4, 2021
203d5cf
Deprecate 'address' option of http_response as showcase.
Oct 4, 2021
eac1c12
Color deprecation output to increase visibility.
Oct 4, 2021
cd4a3db
Report only those deprecated fields that contain data.
Oct 4, 2021
21ad7fe
Flag known deprecated packages.
Oct 4, 2021
dd605f6
Refactor deprecation handling a bit and implement deprecation listing.
Oct 4, 2021
555f325
Allow listing of deprecated plugins and options via telegraf cmd.
Oct 4, 2021
9044db0
Restore the old config.NewConfig().
Oct 4, 2021
5a15d4e
Fix linter issues.
Oct 4, 2021
233cd48
Make tidy.
Oct 5, 2021
ab84744
Add comment to walkPluginStruct().
Oct 5, 2021
0f277d2
Pimp walkPluginStruct() to also walk structs embedded in slices/array…
Oct 5, 2021
3cbd617
Print deprecation statistics which is also included in a log-file if …
Oct 13, 2021
1a13eca
Enable plugin filtering for deprecation list.
Oct 13, 2021
abc4486
Add new command-line flag to documentation.
Oct 14, 2021
d44c5e4
Fix doc alignment.
Oct 15, 2021
6234b1c
Fix linter error.
Oct 15, 2021
05a3bf1
Implement discussed deprecation strategy and allow to specify a custo…
Nov 9, 2021
22500d6
Move deprecation info to long-term persistant tables.
Nov 9, 2021
cdfe548
Print deprecation notice for deprecated and already removed plugins.
Nov 9, 2021
11fa16b
Use keyed fields.
Nov 9, 2021
2227789
Allow <br> HTML elements for Markdown as they are often the only why …
Nov 11, 2021
61100ef
Fix Markdown errors found by markdownlint.
Nov 11, 2021
8c57204
Add inputs.io to list of deprecated plugins.
Nov 11, 2021
9cb28b6
Remove color from deprecation output.
Nov 11, 2021
5913229
Fix Makefile.
Nov 11, 2021
c3a36f1
Use go-semver for versioning.
Nov 11, 2021
547a440
Simplify version handling in telegraf.
Nov 11, 2021
f9593f4
Make version internal.
Nov 11, 2021
fcbcda6
Fix linter error.
Nov 11, 2021
9a3ae7d
Improve error message.
Nov 11, 2021
70fec20
Formatting.
Nov 11, 2021
56c9a3a
Update deprecation information from Changelog.
Nov 11, 2021
3d3fc20
Revert "Remove color from deprecation output."
Nov 11, 2021
aaedcbf
Handle processor and aggregator deprecations as well.
Nov 16, 2021
f10f487
Rename 'Level' to 'LogLevel'.
Nov 16, 2021
4dcad88
Make all versions tri-dotted format.
Nov 17, 2021
d013d33
Print origin for version panic to ease debugging.
Nov 17, 2021
184d745
Switch to 'github.com/blang/semver' as we already have this as a (ind…
Nov 17, 2021
d50bf5b
Drop potential pre-release tags for telegraf when comparing the versi…
Nov 17, 2021
c5411e6
Revert "Switch to 'github.com/blang/semver' as we already have this a…
Nov 18, 2021
2e98015
Merge branch 'master' into deprecation
srebhan Nov 22, 2021
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
5 changes: 4 additions & 1 deletion .markdownlint.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"MD013": false
"MD013": false,
"MD033": {
"allowed_elements": ["br"]
}
}
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ HOSTGO := env -u GOOS -u GOARCH -u GOARM -- go
LDFLAGS := $(LDFLAGS) -X main.commit=$(commit) -X main.branch=$(branch) -X main.goos=$(GOOS) -X main.goarch=$(GOARCH)
ifneq ($(tag),)
LDFLAGS += -X main.version=$(version)
else
LDFLAGS += -X main.version=$(version)-$(commit)
powersj marked this conversation as resolved.
Show resolved Hide resolved
endif

# Go built-in race detector works only for 64 bits architectures.
Expand Down Expand Up @@ -160,6 +162,10 @@ lint:
exit 1
endif

ifeq (, $(shell which markdownlint-cli))
$(info markdownlint-cli can't be found, please run: make lint-install)
exit 1
endif
markdownlint-cli

.PHONY: lint-branch
Expand Down
51 changes: 41 additions & 10 deletions cmd/telegraf/telegraf.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ var fVersion = flag.Bool("version", false, "display the version and exit")
var fSampleConfig = flag.Bool("sample-config", false,
"print out full sample configuration")
var fPidfile = flag.String("pidfile", "", "file to write our pid to")
var fDeprecationList = flag.Bool("deprecation-list", false,
"print all deprecated plugins or plugin options.")
var fSectionFilters = flag.String("section-filter", "",
"filter the sections to print, separator is ':'. Valid values are 'agent', 'global_tags', 'outputs', 'processors', 'aggregators' and 'inputs'")
var fInputFilters = flag.String("input-filter", "",
Expand Down Expand Up @@ -270,6 +272,19 @@ func runAgent(ctx context.Context,
log.Printf("I! Loaded outputs: %s", strings.Join(c.OutputNames(), " "))
log.Printf("I! Tags enabled: %s", c.ListTags())

if count, found := c.Deprecations["inputs"]; found && (count[0] > 0 || count[1] > 0) {
log.Printf("W! Deprecated inputs: %d and %d options", count[0], count[1])
}
if count, found := c.Deprecations["aggregators"]; found && (count[0] > 0 || count[1] > 0) {
log.Printf("W! Deprecated aggregators: %d and %d options", count[0], count[1])
}
if count, found := c.Deprecations["processors"]; found && (count[0] > 0 || count[1] > 0) {
log.Printf("W! Deprecated processors: %d and %d options", count[0], count[1])
}
if count, found := c.Deprecations["outputs"]; found && (count[0] > 0 || count[1] > 0) {
log.Printf("W! Deprecated outputs: %d and %d options", count[0], count[1])
}

if *fPidfile != "" {
f, err := os.OpenFile(*fPidfile, os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
Expand Down Expand Up @@ -348,6 +363,11 @@ func main() {

logger.SetupLogging(logger.LogConfig{})

// Configure version
if err := internal.SetVersion(version); err != nil {
log.Println("Telegraf version already configured to: " + internal.Version())
}

// Load external plugins, if requested.
if *fPlugins != "" {
log.Printf("I! Loading external plugins from: %s", *fPlugins)
Expand Down Expand Up @@ -392,6 +412,27 @@ func main() {

// switch for flags which just do something and exit immediately
switch {
case *fDeprecationList:
c := config.NewConfig()
infos := c.CollectDeprecationInfos(
inputFilters,
outputFilters,
aggregatorFilters,
processorFilters,
)
//nolint:revive // We will notice if Println fails
fmt.Println("Deprecated Input Plugins: ")
c.PrintDeprecationList(infos["inputs"])
//nolint:revive // We will notice if Println fails
fmt.Println("Deprecated Output Plugins: ")
c.PrintDeprecationList(infos["outputs"])
//nolint:revive // We will notice if Println fails
fmt.Println("Deprecated Processor Plugins: ")
c.PrintDeprecationList(infos["processors"])
//nolint:revive // We will notice if Println fails
fmt.Println("Deprecated Aggregator Plugins: ")
c.PrintDeprecationList(infos["aggregators"])
return
case *fOutputList:
fmt.Println("Available Output Plugins: ")
names := make([]string, 0, len(outputs.Outputs))
Expand Down Expand Up @@ -435,16 +476,6 @@ func main() {
return
}

shortVersion := version
if shortVersion == "" {
shortVersion = "unknown"
}

// Configure version
if err := internal.SetVersion(shortVersion); err != nil {
log.Println("Telegraf version already configured to: " + internal.Version())
}

run(
inputFilters,
outputFilters,
Expand Down
54 changes: 54 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import (
"strings"
"time"

"github.com/coreos/go-semver/semver"

"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/internal"
"github.com/influxdata/telegraf/internal/choice"
Expand Down Expand Up @@ -77,6 +79,9 @@ type Config struct {
// Processors have a slice wrapper type because they need to be sorted
Processors models.RunningProcessors
AggProcessors models.RunningProcessors

Deprecations map[string][]int64
version *semver.Version
}

// NewConfig creates a new struct to hold the Telegraf config.
Expand All @@ -102,7 +107,15 @@ func NewConfig() *Config {
AggProcessors: make([]*models.RunningProcessor, 0),
InputFilters: make([]string, 0),
OutputFilters: make([]string, 0),
Deprecations: make(map[string][]int64),
}

// Handle unknown version
version := internal.Version()
if version == "" || version == "unknown" {
version = "0.0.0-unknown"
}
powersj marked this conversation as resolved.
Show resolved Hide resolved
c.version = semver.New(version)

tomlCfg := &toml.Config{
NormFieldName: toml.DefaultConfig.NormFieldName,
Expand Down Expand Up @@ -1008,6 +1021,11 @@ func parseConfig(contents []byte) (*ast.Table, error) {
func (c *Config) addAggregator(name string, table *ast.Table) error {
creator, ok := aggregators.Aggregators[name]
if !ok {
// Handle removed, deprecated plugins
if di, deprecated := aggregators.Deprecations[name]; deprecated {
printHistoricPluginDeprecationNotice("aggregators", name, di)
return fmt.Errorf("plugin deprecated")
}
return fmt.Errorf("Undefined but requested aggregator: %s", name)
}
aggregator := creator()
Expand All @@ -1021,13 +1039,22 @@ func (c *Config) addAggregator(name string, table *ast.Table) error {
return err
}

if err := c.printUserDeprecation("aggregators", name, aggregator); err != nil {
return err
}

c.Aggregators = append(c.Aggregators, models.NewRunningAggregator(aggregator, conf))
return nil
}

func (c *Config) addProcessor(name string, table *ast.Table) error {
creator, ok := processors.Processors[name]
if !ok {
// Handle removed, deprecated plugins
if di, deprecated := processors.Deprecations[name]; deprecated {
printHistoricPluginDeprecationNotice("processors", name, di)
return fmt.Errorf("plugin deprecated")
}
return fmt.Errorf("Undefined but requested processor: %s", name)
}

Expand Down Expand Up @@ -1069,6 +1096,10 @@ func (c *Config) newRunningProcessor(
}
}

if err := c.printUserDeprecation("processors", processorConfig.Name, processor); err != nil {
return nil, err
}

rf := models.NewRunningProcessor(processor, processorConfig)
return rf, nil
}
Expand All @@ -1079,6 +1110,11 @@ func (c *Config) addOutput(name string, table *ast.Table) error {
}
creator, ok := outputs.Outputs[name]
if !ok {
// Handle removed, deprecated plugins
if di, deprecated := outputs.Deprecations[name]; deprecated {
printHistoricPluginDeprecationNotice("outputs", name, di)
return fmt.Errorf("plugin deprecated")
}
return fmt.Errorf("Undefined but requested output: %s", name)
}
output := creator()
Expand All @@ -1103,6 +1139,10 @@ func (c *Config) addOutput(name string, table *ast.Table) error {
return err
}

if err := c.printUserDeprecation("outputs", name, output); err != nil {
return err
}

ro := models.NewRunningOutput(output, outputConfig, c.Agent.MetricBatchSize, c.Agent.MetricBufferLimit)
c.Outputs = append(c.Outputs, ro)
return nil
Expand All @@ -1112,13 +1152,23 @@ func (c *Config) addInput(name string, table *ast.Table) error {
if len(c.InputFilters) > 0 && !sliceContains(name, c.InputFilters) {
return nil
}

// Legacy support renaming io input to diskio
if name == "io" {
if err := c.printUserDeprecation("inputs", name, nil); err != nil {
return err
}
name = "diskio"
}

creator, ok := inputs.Inputs[name]
if !ok {
// Handle removed, deprecated plugins
if di, deprecated := inputs.Deprecations[name]; deprecated {
printHistoricPluginDeprecationNotice("inputs", name, di)
return fmt.Errorf("plugin deprecated")
}

return fmt.Errorf("Undefined but requested input: %s", name)
}
input := creator()
Expand Down Expand Up @@ -1152,6 +1202,10 @@ func (c *Config) addInput(name string, table *ast.Table) error {
return err
}

if err := c.printUserDeprecation("inputs", name, input); err != nil {
return err
}

rp := models.NewRunningInput(input, pluginConfig)
rp.SetDefaultTags(c.Tags)
c.Inputs = append(c.Inputs, rp)
Expand Down
Loading