From 0d8717cc83f0547e67770cc3a321347ac9be9cdf Mon Sep 17 00:00:00 2001 From: Sven Rebhan Date: Mon, 4 Oct 2021 17:08:55 +0200 Subject: [PATCH 01/45] Make version available in config. --- cmd/telegraf/telegraf.go | 2 +- config/config.go | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/cmd/telegraf/telegraf.go b/cmd/telegraf/telegraf.go index 688c1e5bdd6c5..d7d5e444f36b1 100644 --- a/cmd/telegraf/telegraf.go +++ b/cmd/telegraf/telegraf.go @@ -194,7 +194,7 @@ func runAgent(ctx context.Context, log.Printf("I! Starting Telegraf %s", version) // If no other options are specified, load the config file and run. - c := config.NewConfig() + c := config.NewConfig(version) c.OutputFilters = outputFilters c.InputFilters = inputFilters var err error diff --git a/config/config.go b/config/config.go index 97f9c35b3ab55..231d12d7a4b7c 100644 --- a/config/config.go +++ b/config/config.go @@ -77,12 +77,17 @@ type Config struct { // Processors have a slice wrapper type because they need to be sorted Processors models.RunningProcessors AggProcessors models.RunningProcessors + + versionMajor int + versionMinor int } // NewConfig creates a new struct to hold the Telegraf config. // For historical reasons, It holds the actual instances of the running plugins // once the configuration is parsed. -func NewConfig() *Config { +func NewConfig(version string) *Config { + maj, min := parseVersion(version) + c := &Config{ UnusedFields: map[string]bool{}, @@ -102,6 +107,9 @@ func NewConfig() *Config { AggProcessors: make([]*models.RunningProcessor, 0), InputFilters: make([]string, 0), OutputFilters: make([]string, 0), + + versionMajor: maj, + versionMinor: min, } tomlCfg := &toml.Config{ @@ -200,6 +208,9 @@ type AgentConfig struct { Hostname string OmitHostname bool + + versionMajor int + versionMinor int } // InputNames returns a list of strings of the configured inputs. From 8c52ceed27afb4b0415c0b7b2ddd8babe290cf1b Mon Sep 17 00:00:00 2001 From: Sven Rebhan Date: Mon, 4 Oct 2021 17:09:53 +0200 Subject: [PATCH 02/45] Define interface for declaring a plugin as deprecated. --- plugin.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/plugin.go b/plugin.go index f9dcaeac0344c..322f721fd66a3 100644 --- a/plugin.go +++ b/plugin.go @@ -23,6 +23,13 @@ type PluginDescriber interface { Description() string } +// PluginDeprecator marks a plugin as deprecated and provides hints to the user. +type PluginDeprecator interface { + // DeprecationNotice returns the version since when the plugin is deprecated and + // (optionally) provides a deprecation notice allowing to suggest replacements etc. + DeprecationNotice() (since string, notice string) +} + // Logger defines an plugin-related interface for logging. type Logger interface { // Errorf logs an error message, patterned after log.Printf. From abae0812fb5273f6502bb41dae8ecce5da90a983 Mon Sep 17 00:00:00 2001 From: Sven Rebhan Date: Mon, 4 Oct 2021 17:15:09 +0200 Subject: [PATCH 03/45] Define telegraf version for the non-tagged case. --- Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Makefile b/Makefile index 290008d8c34b0..2b5864602564a 100644 --- a/Makefile +++ b/Makefile @@ -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) endif # Go built-in race detector works only for 64 bits architectures. From aa4790ebfd4487563f079a00bda75bd699c5a32a Mon Sep 17 00:00:00 2001 From: Sven Rebhan Date: Mon, 4 Oct 2021 17:15:31 +0200 Subject: [PATCH 04/45] Implement deprecation handling. --- config/deprecation.go | 153 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 153 insertions(+) create mode 100644 config/deprecation.go diff --git a/config/deprecation.go b/config/deprecation.go new file mode 100644 index 0000000000000..24e719b1ab858 --- /dev/null +++ b/config/deprecation.go @@ -0,0 +1,153 @@ +package config + +import ( + "fmt" + "log" + "reflect" + "strconv" + "strings" + + "github.com/influxdata/telegraf" +) + +type Escalation int + +const ( + None Escalation = iota + Warn + Error +) + +const ( + pluginWarnNotice = "Deprecated plugin will be removed soon, please switch to a supported plugin!" + optionWarnNotice = "Deprecated options will be removed with the next major version, please adapt your config!" +) + +func (c *Config) handleDeprecation(name string, plugin interface{}) error { + // First check if the whole plugin is deprecated + if deprecatedPlugin, ok := plugin.(telegraf.PluginDeprecator); ok { + since, notice := deprecatedPlugin.DeprecationNotice() + switch c.getDeprecationEscalation(since) { + case Warn: + printPluginDeprecationNotice("W! [agent] DeprecationWarning", name, since, notice) + // We will not check for any deprecated options as the whole plugin is deprecated anyway. + return nil + case Error: + printPluginDeprecationNotice("E! [agent] DeprecationError", name, since, notice) + // We are past the grace period + return fmt.Errorf("plugin deprecated") + } + } + + // Check for deprecated options + deprecatedOptions := make([]string, 0) + walkPluginStruct(reflect.ValueOf(plugin), func(field reflect.StructField, value reflect.Value) { + tags := strings.SplitN(field.Tag.Get("deprecated"), ";", 2) + if len(tags) < 1 || tags[0] == "" { + return + } + since := tags[0] + notice := "" + if len(tags) > 1 { + notice = tags[1] + } + + // Get the toml field name + option := field.Tag.Get("toml") + if option == "" { + option = field.Name + } + + switch c.getDeprecationEscalation(since) { + case Warn: + printOptionDeprecationNotice("W! [agent] DeprecationWarning", name, option, since, notice) + case Error: + printOptionDeprecationNotice("E! [agent] DeprecationError", name, option, since, notice) + deprecatedOptions = append(deprecatedOptions, option) + } + }) + + if len(deprecatedOptions) > 0 { + return fmt.Errorf("plugin options %q deprecated", strings.Join(deprecatedOptions, ",")) + } + + return nil +} + +func (c *Config) getDeprecationEscalation(since string) Escalation { + sinceMajor, sinceMinor := parseVersion(since) + if c.versionMajor > sinceMajor { + return Error + } + if c.versionMajor == sinceMajor && c.versionMinor >= sinceMinor { + return Warn + } + + return None +} + +func printPluginDeprecationNotice(prefix, name, since, notice string) { + if notice != "" { + log.Printf("%s: Plugin %q deprecated since version %s: %s", prefix, name, since, notice) + } else { + log.Printf("%s: Plugin %q deprecated since version %s", prefix, name, since) + } + log.Printf("Please note: %s", pluginWarnNotice) +} + +func printOptionDeprecationNotice(prefix, name, option, since, notice string) { + if notice != "" { + log.Printf("%s: Option %q of plugin %q deprecated since version %s: %s", prefix, option, name, since, notice) + } else { + log.Printf("%s: Option %q of plugin %q deprecated since version %s", prefix, option, name, since) + } + log.Printf("Please note: %s", optionWarnNotice) +} + +func walkPluginStruct(value reflect.Value, fn func(f reflect.StructField, fv reflect.Value)) { + v := reflect.Indirect(value) + t := v.Type() + + for i := 0; i < t.NumField(); i++ { + field := t.Field(i) + fieldValue := v.Field(i) + + if field.PkgPath != "" { + continue + } + switch field.Type.Kind() { + case reflect.Struct: + walkPluginStruct(fieldValue, fn) + + case reflect.Array, reflect.Slice: + for j := 0; j < fieldValue.Len(); j++ { + fn(field, fieldValue.Index(j)) + } + case reflect.Map: + iter := fieldValue.MapRange() + for iter.Next() { + fn(field, iter.Value()) + } + default: + fn(field, fieldValue) + } + } +} + +func parseVersion(version string) (major, minor int) { + parts := strings.SplitN(version, ".", 3) + if len(parts) < 2 { + panic(fmt.Errorf("insufficient version fields in %q", version)) + } + + major, err := strconv.Atoi(parts[0]) + if err != nil { + panic(fmt.Errorf("invalid version major in %q", version)) + } + + minor, err = strconv.Atoi(parts[1]) + if err != nil { + panic(fmt.Errorf("invalid version major in %q", version)) + } + return major, minor +} From f776ddf5c9024e8fd52de1e2ba2229dd2ec75cbe Mon Sep 17 00:00:00 2001 From: Sven Rebhan Date: Mon, 4 Oct 2021 17:22:33 +0200 Subject: [PATCH 05/45] Handle deprecation. --- config/config.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/config/config.go b/config/config.go index 231d12d7a4b7c..5674c7e608016 100644 --- a/config/config.go +++ b/config/config.go @@ -1033,6 +1033,10 @@ func (c *Config) addAggregator(name string, table *ast.Table) error { return err } + if err := c.handleDeprecation("aggregators."+name, aggregator); err != nil { + return err + } + c.Aggregators = append(c.Aggregators, models.NewRunningAggregator(aggregator, conf)) return nil } @@ -1081,6 +1085,10 @@ func (c *Config) newRunningProcessor( } } + if err := c.handleDeprecation("processors."+processorConfig.Name, processor); err != nil { + return nil, err + } + rf := models.NewRunningProcessor(processor, processorConfig) return rf, nil } @@ -1115,6 +1123,10 @@ func (c *Config) addOutput(name string, table *ast.Table) error { return err } + if err := c.handleDeprecation("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 @@ -1164,6 +1176,10 @@ func (c *Config) addInput(name string, table *ast.Table) error { return err } + if err := c.handleDeprecation("inputs."+name, input); err != nil { + return err + } + rp := models.NewRunningInput(input, pluginConfig) rp.SetDefaultTags(c.Tags) c.Inputs = append(c.Inputs, rp) From 7c6e65462788a3116dfc0bf602f429d1d679bc7f Mon Sep 17 00:00:00 2001 From: Sven Rebhan Date: Mon, 4 Oct 2021 17:23:11 +0200 Subject: [PATCH 06/45] Deprecate httpjson as a showcase. --- plugins/inputs/httpjson/httpjson.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/plugins/inputs/httpjson/httpjson.go b/plugins/inputs/httpjson/httpjson.go index 10a4cb0c17643..12a70a3b3e0c3 100644 --- a/plugins/inputs/httpjson/httpjson.go +++ b/plugins/inputs/httpjson/httpjson.go @@ -283,6 +283,10 @@ func (h *HTTPJSON) sendRequest(serverURL string) (string, float64, error) { return string(body), responseTime, err } +func (h *HTTPJSON) DeprecationNotice() (since, notice string) { + return "1.6", "use 'inputs.http' instead" +} + func init() { inputs.Add("httpjson", func() telegraf.Input { return &HTTPJSON{ From 09cbfa3049c952171ad7b64686a9d7fd20884d8b Mon Sep 17 00:00:00 2001 From: Sven Rebhan Date: Mon, 4 Oct 2021 17:23:58 +0200 Subject: [PATCH 07/45] Deprecate 'address' option of http_response as showcase. --- plugins/inputs/http_response/http_response.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/inputs/http_response/http_response.go b/plugins/inputs/http_response/http_response.go index 799f664d1e7b0..ef5a1f4e85069 100644 --- a/plugins/inputs/http_response/http_response.go +++ b/plugins/inputs/http_response/http_response.go @@ -28,7 +28,7 @@ const ( // HTTPResponse struct type HTTPResponse struct { - Address string // deprecated in 1.12 + Address string `toml:"address" deprecated:"1.12;use 'urls' instead"` URLs []string `toml:"urls"` HTTPProxy string `toml:"http_proxy"` Body string From 8d23064eb214dc66e8506b0a2c892e02bdd412a2 Mon Sep 17 00:00:00 2001 From: Sven Rebhan Date: Mon, 4 Oct 2021 17:39:24 +0200 Subject: [PATCH 08/45] Color deprecation output to increase visibility. --- config/deprecation.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/config/deprecation.go b/config/deprecation.go index 24e719b1ab858..4de70f99b959a 100644 --- a/config/deprecation.go +++ b/config/deprecation.go @@ -7,6 +7,8 @@ import ( "strconv" "strings" + "github.com/fatih/color" + "github.com/influxdata/telegraf" ) @@ -29,11 +31,13 @@ func (c *Config) handleDeprecation(name string, plugin interface{}) error { since, notice := deprecatedPlugin.DeprecationNotice() switch c.getDeprecationEscalation(since) { case Warn: - printPluginDeprecationNotice("W! [agent] DeprecationWarning", name, since, notice) + prefix := "W! " + color.YellowString("DeprecationWarning") + printPluginDeprecationNotice(prefix, name, since, notice) // We will not check for any deprecated options as the whole plugin is deprecated anyway. return nil case Error: - printPluginDeprecationNotice("E! [agent] DeprecationError", name, since, notice) + prefix := "E! " + color.RedString("DeprecationError") + printPluginDeprecationNotice(prefix, name, since, notice) // We are past the grace period return fmt.Errorf("plugin deprecated") } @@ -60,9 +64,11 @@ func (c *Config) handleDeprecation(name string, plugin interface{}) error { switch c.getDeprecationEscalation(since) { case Warn: - printOptionDeprecationNotice("W! [agent] DeprecationWarning", name, option, since, notice) + prefix := "W! " + color.YellowString("DeprecationWarning") + printOptionDeprecationNotice(prefix, name, option, since, notice) case Error: - printOptionDeprecationNotice("E! [agent] DeprecationError", name, option, since, notice) + prefix := "E! " + color.RedString("DeprecationError") + printOptionDeprecationNotice(prefix, name, option, since, notice) deprecatedOptions = append(deprecatedOptions, option) } }) From ceb67fd25952da197a5e7e8799e8ae4948594a7b Mon Sep 17 00:00:00 2001 From: Sven Rebhan Date: Mon, 4 Oct 2021 18:05:25 +0200 Subject: [PATCH 09/45] Report only those deprecated fields that contain data. --- config/deprecation.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/config/deprecation.go b/config/deprecation.go index 4de70f99b959a..36f5c4542ef9b 100644 --- a/config/deprecation.go +++ b/config/deprecation.go @@ -46,6 +46,11 @@ func (c *Config) handleDeprecation(name string, plugin interface{}) error { // Check for deprecated options deprecatedOptions := make([]string, 0) walkPluginStruct(reflect.ValueOf(plugin), func(field reflect.StructField, value reflect.Value) { + // Try to report only those fields that are set + if value.IsZero() { + return + } + tags := strings.SplitN(field.Tag.Get("deprecated"), ";", 2) if len(tags) < 1 || tags[0] == "" { return @@ -134,9 +139,8 @@ func walkPluginStruct(value reflect.Value, fn func(f reflect.StructField, fv ref for iter.Next() { fn(field, iter.Value()) } - default: - fn(field, fieldValue) } + fn(field, fieldValue) } } From 19c9cd8680285af3daaf296ba361c719e7de0df3 Mon Sep 17 00:00:00 2001 From: Sven Rebhan Date: Mon, 4 Oct 2021 18:05:47 +0200 Subject: [PATCH 10/45] Flag known deprecated packages. --- plugins/inputs/cassandra/cassandra.go | 4 ++++ plugins/inputs/http_listener_v2/http_listener_v2.go | 4 ++++ plugins/inputs/httpjson/httpjson.go | 2 +- plugins/inputs/jolokia/jolokia.go | 4 ++++ plugins/inputs/kafka_consumer_legacy/kafka_consumer_legacy.go | 4 ++++ plugins/inputs/logparser/logparser.go | 4 ++++ plugins/inputs/snmp_legacy/snmp_legacy.go | 4 ++++ plugins/inputs/tcp_listener/tcp_listener.go | 4 ++++ plugins/inputs/udp_listener/udp_listener.go | 4 ++++ plugins/outputs/riemann_legacy/riemann.go | 4 ++++ 10 files changed, 37 insertions(+), 1 deletion(-) diff --git a/plugins/inputs/cassandra/cassandra.go b/plugins/inputs/cassandra/cassandra.go index d1c23caadc68a..96b6d9bf46ed7 100644 --- a/plugins/inputs/cassandra/cassandra.go +++ b/plugins/inputs/cassandra/cassandra.go @@ -313,6 +313,10 @@ func (c *Cassandra) Gather(acc telegraf.Accumulator) error { return nil } +func (_ *Cassandra) DeprecationNotice() (since, notice string) { + return "1.7", "use 'inputs.jolokia2' with the 'cassandra.conf' example configuration instead" +} + func init() { inputs.Add("cassandra", func() telegraf.Input { return &Cassandra{jClient: &JolokiaClientImpl{client: &http.Client{}}} diff --git a/plugins/inputs/http_listener_v2/http_listener_v2.go b/plugins/inputs/http_listener_v2/http_listener_v2.go index d2a2e5f35214e..f62d59e929cff 100644 --- a/plugins/inputs/http_listener_v2/http_listener_v2.go +++ b/plugins/inputs/http_listener_v2/http_listener_v2.go @@ -385,6 +385,10 @@ func (h *HTTPListenerV2) authenticateIfSet(handler http.HandlerFunc, res http.Re } } +func (_ *HTTPListenerV2) DeprecationNotice() (since, notice string) { + return "1.9", "has been renamed to 'influxdb_listener', use 'inputs.influxdb_listener' or 'inputs.influxdb_listener_v2' instead" +} + func init() { inputs.Add("http_listener_v2", func() telegraf.Input { return &HTTPListenerV2{ diff --git a/plugins/inputs/httpjson/httpjson.go b/plugins/inputs/httpjson/httpjson.go index 12a70a3b3e0c3..77d3636138616 100644 --- a/plugins/inputs/httpjson/httpjson.go +++ b/plugins/inputs/httpjson/httpjson.go @@ -283,7 +283,7 @@ func (h *HTTPJSON) sendRequest(serverURL string) (string, float64, error) { return string(body), responseTime, err } -func (h *HTTPJSON) DeprecationNotice() (since, notice string) { +func (_ *HTTPJSON) DeprecationNotice() (since, notice string) { return "1.6", "use 'inputs.http' instead" } diff --git a/plugins/inputs/jolokia/jolokia.go b/plugins/inputs/jolokia/jolokia.go index af5e3de283800..cb39ca25764ed 100644 --- a/plugins/inputs/jolokia/jolokia.go +++ b/plugins/inputs/jolokia/jolokia.go @@ -318,6 +318,10 @@ func (j *Jolokia) Gather(acc telegraf.Accumulator) error { return nil } +func (_ *Jolokia) DeprecationNotice() (since, notice string) { + return "1.5", "use 'inputs.jolokia2' instead" +} + func init() { inputs.Add("jolokia", func() telegraf.Input { return &Jolokia{ diff --git a/plugins/inputs/kafka_consumer_legacy/kafka_consumer_legacy.go b/plugins/inputs/kafka_consumer_legacy/kafka_consumer_legacy.go index ab19e0875820a..3803808d9cd1c 100644 --- a/plugins/inputs/kafka_consumer_legacy/kafka_consumer_legacy.go +++ b/plugins/inputs/kafka_consumer_legacy/kafka_consumer_legacy.go @@ -184,6 +184,10 @@ func (k *Kafka) Gather(_ telegraf.Accumulator) error { return nil } +func (_ *Kafka) DeprecationNotice() (since, notice string) { + return "1.20", "use 'inputs.kafka_consumer' instead, NOTE: 'kafka_consumer' only supports Kafka v0.8+" +} + func init() { inputs.Add("kafka_consumer_legacy", func() telegraf.Input { return &Kafka{} diff --git a/plugins/inputs/logparser/logparser.go b/plugins/inputs/logparser/logparser.go index 83f5abd210bdd..017ee6868a968 100644 --- a/plugins/inputs/logparser/logparser.go +++ b/plugins/inputs/logparser/logparser.go @@ -360,6 +360,10 @@ func (l *LogParserPlugin) Stop() { offsetsMutex.Unlock() } +func (_ *LogParserPlugin) DeprecationNotice() (since, notice string) { + return "1.15", "use 'inputs.tail' with 'grok' data format instead" +} + func init() { inputs.Add("logparser", func() telegraf.Input { return NewLogParser() diff --git a/plugins/inputs/snmp_legacy/snmp_legacy.go b/plugins/inputs/snmp_legacy/snmp_legacy.go index ce454cbfbad36..ddbb4d276c1dd 100644 --- a/plugins/inputs/snmp_legacy/snmp_legacy.go +++ b/plugins/inputs/snmp_legacy/snmp_legacy.go @@ -815,6 +815,10 @@ func (h *Host) HandleResponse( return lastOid, nil } +func (_ *Snmp) DeprecationNotice() (since, notice string) { + return "1.20", "use 'inputs.snmp' instead" +} + func init() { inputs.Add("snmp_legacy", func() telegraf.Input { return &Snmp{} diff --git a/plugins/inputs/tcp_listener/tcp_listener.go b/plugins/inputs/tcp_listener/tcp_listener.go index 8eeaa9cff8091..f591149a7c556 100644 --- a/plugins/inputs/tcp_listener/tcp_listener.go +++ b/plugins/inputs/tcp_listener/tcp_listener.go @@ -297,6 +297,10 @@ func (t *TCPListener) remember(id string, conn *net.TCPConn) { t.conns[id] = conn } +func (_ *TCPListener) DeprecationNotice() (since, notice string) { + return "1.3", "use 'inputs.socket_listener' instead" +} + func init() { inputs.Add("tcp_listener", func() telegraf.Input { return &TCPListener{ diff --git a/plugins/inputs/udp_listener/udp_listener.go b/plugins/inputs/udp_listener/udp_listener.go index 39fef79ce1b98..8184b114062d2 100644 --- a/plugins/inputs/udp_listener/udp_listener.go +++ b/plugins/inputs/udp_listener/udp_listener.go @@ -221,6 +221,10 @@ func (u *UDPListener) udpParser() { } } +func (_ *UDPListener) DeprecationNotice() (since, notice string) { + return "1.3", "use 'inputs.socket_listener' instead" +} + func init() { inputs.Add("udp_listener", func() telegraf.Input { return &UDPListener{ diff --git a/plugins/outputs/riemann_legacy/riemann.go b/plugins/outputs/riemann_legacy/riemann.go index 0bd0f6b876c68..e071928a931c9 100644 --- a/plugins/outputs/riemann_legacy/riemann.go +++ b/plugins/outputs/riemann_legacy/riemann.go @@ -147,6 +147,10 @@ func serviceName(s string, n string, t map[string]string, f string) string { return strings.Join(serviceStrings, s) } +func (_ *Riemann) DeprecationNotice() (since, notice string) { + return "1.20", "use 'outputs.riemann' instead (see https://github.com/influxdata/telegraf/issues/1878)" +} + func init() { outputs.Add("riemann_legacy", func() telegraf.Output { return &Riemann{} From c0678acd89c401bba91eccb072c0111df08b3590 Mon Sep 17 00:00:00 2001 From: Sven Rebhan Date: Mon, 4 Oct 2021 19:42:02 +0200 Subject: [PATCH 11/45] Refactor deprecation handling a bit and implement deprecation listing. --- config/config.go | 8 +- config/deprecation.go | 184 +++++++++++++++++++++++++++++++++++------- 2 files changed, 157 insertions(+), 35 deletions(-) diff --git a/config/config.go b/config/config.go index 5674c7e608016..5f8f7c59f34f2 100644 --- a/config/config.go +++ b/config/config.go @@ -1033,7 +1033,7 @@ func (c *Config) addAggregator(name string, table *ast.Table) error { return err } - if err := c.handleDeprecation("aggregators."+name, aggregator); err != nil { + if err := c.printUserDeprecation("aggregators."+name, aggregator); err != nil { return err } @@ -1085,7 +1085,7 @@ func (c *Config) newRunningProcessor( } } - if err := c.handleDeprecation("processors."+processorConfig.Name, processor); err != nil { + if err := c.printUserDeprecation("processors."+processorConfig.Name, processor); err != nil { return nil, err } @@ -1123,7 +1123,7 @@ func (c *Config) addOutput(name string, table *ast.Table) error { return err } - if err := c.handleDeprecation("outputs."+name, output); err != nil { + if err := c.printUserDeprecation("outputs."+name, output); err != nil { return err } @@ -1176,7 +1176,7 @@ func (c *Config) addInput(name string, table *ast.Table) error { return err } - if err := c.handleDeprecation("inputs."+name, input); err != nil { + if err := c.printUserDeprecation("inputs."+name, input); err != nil { return err } diff --git a/config/deprecation.go b/config/deprecation.go index 36f5c4542ef9b..18341b0222891 100644 --- a/config/deprecation.go +++ b/config/deprecation.go @@ -4,50 +4,80 @@ import ( "fmt" "log" "reflect" + "sort" "strconv" "strings" "github.com/fatih/color" "github.com/influxdata/telegraf" + "github.com/influxdata/telegraf/plugins/aggregators" + "github.com/influxdata/telegraf/plugins/inputs" + "github.com/influxdata/telegraf/plugins/outputs" + "github.com/influxdata/telegraf/plugins/processors" ) +const ( + pluginWarnNotice = "Deprecated plugin will be removed soon, please switch to a supported plugin!" + optionWarnNotice = "Deprecated options will be removed with the next major version, please adapt your config!" +) + +// Escalation level for the plugin or option type Escalation int +func (e Escalation) String() string { + switch e { + case Warn: + return "WARN" + case Error: + return "ERROR" + } + return "NONE" +} + const ( + // None means no deprecation None Escalation = iota + // Warn means deprecated but still within the grace period Warn + // Error means deprecated and beyond grace period Error ) -const ( - pluginWarnNotice = "Deprecated plugin will be removed soon, please switch to a supported plugin!" - optionWarnNotice = "Deprecated options will be removed with the next major version, please adapt your config!" -) +// DeprecationInfo contains all important information to describe a deprecated entity +type DeprecationInfo struct { + // Name of the plugin or plugin option + Name string + // Level of deprecation + Level Escalation + // Since which version the plugin or plugin option is deprecated + Since string + // Notice to the user about alternatives or further information + Notice string +} + +// PluginDeprecationInfo holds all information about a deprecated plugin or it's options +type PluginDeprecationInfo struct { + DeprecationInfo + + // Options deprecated for this plugin + Options []DeprecationInfo +} + +func (c *Config) collectDeprecationInfo(name string, plugin interface{}, all bool) PluginDeprecationInfo { + info := PluginDeprecationInfo{} + info.Name = name -func (c *Config) handleDeprecation(name string, plugin interface{}) error { // First check if the whole plugin is deprecated if deprecatedPlugin, ok := plugin.(telegraf.PluginDeprecator); ok { - since, notice := deprecatedPlugin.DeprecationNotice() - switch c.getDeprecationEscalation(since) { - case Warn: - prefix := "W! " + color.YellowString("DeprecationWarning") - printPluginDeprecationNotice(prefix, name, since, notice) - // We will not check for any deprecated options as the whole plugin is deprecated anyway. - return nil - case Error: - prefix := "E! " + color.RedString("DeprecationError") - printPluginDeprecationNotice(prefix, name, since, notice) - // We are past the grace period - return fmt.Errorf("plugin deprecated") - } + info.Since, info.Notice = deprecatedPlugin.DeprecationNotice() + info.Level = c.getDeprecationEscalation(info.Since) } // Check for deprecated options - deprecatedOptions := make([]string, 0) walkPluginStruct(reflect.ValueOf(plugin), func(field reflect.StructField, value reflect.Value) { // Try to report only those fields that are set - if value.IsZero() { + if !all && value.IsZero() { return } @@ -55,28 +85,55 @@ func (c *Config) handleDeprecation(name string, plugin interface{}) error { if len(tags) < 1 || tags[0] == "" { return } - since := tags[0] - notice := "" - if len(tags) > 1 { - notice = tags[1] + optionInfo := DeprecationInfo{ + Name: field.Name, + Since: tags[0], + Level: c.getDeprecationEscalation(tags[0]), } + if len(tags) > 1 { + optionInfo.Notice = tags[1] + } // Get the toml field name option := field.Tag.Get("toml") - if option == "" { - option = field.Name + if option != "" { + optionInfo.Name = option } + info.Options = append(info.Options, optionInfo) + }) + + return info +} + +func (c *Config) printUserDeprecation(name string, plugin interface{}) error { + info := c.collectDeprecationInfo(name, plugin, false) + + switch info.Level { + case Warn: + prefix := "W! " + color.YellowString("DeprecationWarning") + printPluginDeprecationNotice(prefix, info.Name, info.Since, info.Notice) + // We will not check for any deprecated options as the whole plugin is deprecated anyway. + return nil + case Error: + prefix := "E! " + color.RedString("DeprecationError") + printPluginDeprecationNotice(prefix, info.Name, info.Since, info.Notice) + // We are past the grace period + return fmt.Errorf("plugin deprecated") + } - switch c.getDeprecationEscalation(since) { + // Print deprecated options + deprecatedOptions := make([]string, 0) + for _, option := range info.Options { + switch option.Level { case Warn: prefix := "W! " + color.YellowString("DeprecationWarning") - printOptionDeprecationNotice(prefix, name, option, since, notice) + printOptionDeprecationNotice(prefix, info.Name, option.Name, option.Since, option.Notice) case Error: prefix := "E! " + color.RedString("DeprecationError") - printOptionDeprecationNotice(prefix, name, option, since, notice) - deprecatedOptions = append(deprecatedOptions, option) + printOptionDeprecationNotice(prefix, info.Name, option.Name, option.Since, option.Notice) + deprecatedOptions = append(deprecatedOptions, option.Name) } - }) + } if len(deprecatedOptions) > 0 { return fmt.Errorf("plugin options %q deprecated", strings.Join(deprecatedOptions, ",")) @@ -85,6 +142,71 @@ func (c *Config) handleDeprecation(name string, plugin interface{}) error { return nil } +func (c *Config) CollectDeprecationInfos() map[string][]PluginDeprecationInfo { + infos := make(map[string][]PluginDeprecationInfo) + + infos["inputs"] = make([]PluginDeprecationInfo, 0) + for name, creator := range inputs.Inputs { + plugin := creator() + info := c.collectDeprecationInfo(name, plugin, true) + + if info.Level != None || len(info.Options) > 0 { + infos["inputs"] = append(infos["inputs"], info) + } + } + + infos["outputs"] = make([]PluginDeprecationInfo, 0) + for name, creator := range outputs.Outputs { + plugin := creator() + info := c.collectDeprecationInfo(name, plugin, true) + + if info.Level != None || len(info.Options) > 0 { + infos["outputs"] = append(infos["outputs"], info) + } + } + + infos["processors"] = make([]PluginDeprecationInfo, 0) + for name, creator := range processors.Processors { + plugin := creator() + info := c.collectDeprecationInfo(name, plugin, true) + + if info.Level != None || len(info.Options) > 0 { + infos["processors"] = append(infos["processors"], info) + } + } + + infos["aggregators"] = make([]PluginDeprecationInfo, 0) + for name, creator := range aggregators.Aggregators { + plugin := creator() + info := c.collectDeprecationInfo(name, plugin, true) + + if info.Level != None || len(info.Options) > 0 { + infos["aggregators"] = append(infos["aggregators"], info) + } + } + + return infos +} + +func (c *Config) PrintDeprecationList(infos []PluginDeprecationInfo) { + sort.Slice(infos, func(i, j int) bool { return infos[i].Name < infos[j].Name }) + + for _, info := range infos { + switch info.Level { + case Warn, Error: + fmt.Printf(" %-40s %-5s since %5s %s\n", info.Name, info.Level, info.Since, info.Notice) + } + + if len(info.Options) < 1 { + continue + } + sort.Slice(info.Options, func(i, j int) bool { return info.Options[i].Name < info.Options[j].Name }) + for _, option := range info.Options { + fmt.Printf(" %-40s %-5s since %5s %s\n", info.Name+"/"+option.Name, option.Level, option.Since, option.Notice) + } + } +} + func (c *Config) getDeprecationEscalation(since string) Escalation { sinceMajor, sinceMinor := parseVersion(since) if c.versionMajor > sinceMajor { From 03da7550992f7d6493a6e0122f6ff609963de4b3 Mon Sep 17 00:00:00 2001 From: Sven Rebhan Date: Mon, 4 Oct 2021 19:42:37 +0200 Subject: [PATCH 12/45] Allow listing of deprecated plugins and options via telegraf cmd. --- cmd/telegraf/telegraf.go | 14 ++++++++++++++ internal/usage.go | 5 +++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/cmd/telegraf/telegraf.go b/cmd/telegraf/telegraf.go index d7d5e444f36b1..b1b11b5839ebd 100644 --- a/cmd/telegraf/telegraf.go +++ b/cmd/telegraf/telegraf.go @@ -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", "", @@ -392,6 +394,18 @@ func main() { // switch for flags which just do something and exit immediately switch { + case *fDeprecationList: + c := config.NewConfig(version) + infos := c.CollectDeprecationInfos() + fmt.Println("Deprecated Input Plugins: ") + c.PrintDeprecationList(infos["inputs"]) + fmt.Println("Deprecated Output Plugins: ") + c.PrintDeprecationList(infos["outputs"]) + fmt.Println("Deprecated Processor Plugins: ") + c.PrintDeprecationList(infos["processors"]) + fmt.Println("Deprecated Aggregator Plugins: ") + c.PrintDeprecationList(infos["aggregators"]) + return case *fOutputList: fmt.Println("Available Output Plugins: ") names := make([]string, 0, len(outputs.Outputs)) diff --git a/internal/usage.go b/internal/usage.go index 916b5cb86e908..78e9a846b198b 100644 --- a/internal/usage.go +++ b/internal/usage.go @@ -17,13 +17,14 @@ The commands & flags are: --aggregator-filter filter the aggregators to enable, separator is : --config configuration file to load --config-directory directory containing additional *.conf files - --watch-config Telegraf will restart on local config changes. Monitor changes - using either fs notifications or polling. Valid values: 'inotify' or 'poll'. + --watch-config Telegraf will restart on local config changes. Monitor changes + using either fs notifications or polling. Valid values: 'inotify' or 'poll'. Monitoring is off by default. --plugin-directory directory containing *.so files, this directory will be searched recursively. Any Plugin found will be loaded and namespaced. --debug turn on debug logging + --deprecation-list print all deprecated plugins or plugin options. --input-filter filter the inputs to enable, separator is : --input-list print available input plugins. --output-filter filter the outputs to enable, separator is : From 9c4c1cd57abb2bfb7b1e08460c6a1669ae8a9c19 Mon Sep 17 00:00:00 2001 From: Sven Rebhan Date: Mon, 4 Oct 2021 19:54:51 +0200 Subject: [PATCH 13/45] Restore the old config.NewConfig(). --- cmd/telegraf/telegraf.go | 6 ++++-- config/config.go | 11 +++-------- config/deprecation.go | 8 ++++---- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/cmd/telegraf/telegraf.go b/cmd/telegraf/telegraf.go index b1b11b5839ebd..f8f361b0d3509 100644 --- a/cmd/telegraf/telegraf.go +++ b/cmd/telegraf/telegraf.go @@ -196,7 +196,8 @@ func runAgent(ctx context.Context, log.Printf("I! Starting Telegraf %s", version) // If no other options are specified, load the config file and run. - c := config.NewConfig(version) + c := config.NewConfig() + c.VersionMajor, c.VersionMinor = config.ParseVersion(version) c.OutputFilters = outputFilters c.InputFilters = inputFilters var err error @@ -395,7 +396,8 @@ func main() { // switch for flags which just do something and exit immediately switch { case *fDeprecationList: - c := config.NewConfig(version) + c := config.NewConfig() + c.VersionMajor, c.VersionMinor = config.ParseVersion(version) infos := c.CollectDeprecationInfos() fmt.Println("Deprecated Input Plugins: ") c.PrintDeprecationList(infos["inputs"]) diff --git a/config/config.go b/config/config.go index 5f8f7c59f34f2..13f25ba1649f9 100644 --- a/config/config.go +++ b/config/config.go @@ -78,16 +78,14 @@ type Config struct { Processors models.RunningProcessors AggProcessors models.RunningProcessors - versionMajor int - versionMinor int + VersionMajor int + VersionMinor int } // NewConfig creates a new struct to hold the Telegraf config. // For historical reasons, It holds the actual instances of the running plugins // once the configuration is parsed. -func NewConfig(version string) *Config { - maj, min := parseVersion(version) - +func NewConfig() *Config { c := &Config{ UnusedFields: map[string]bool{}, @@ -107,9 +105,6 @@ func NewConfig(version string) *Config { AggProcessors: make([]*models.RunningProcessor, 0), InputFilters: make([]string, 0), OutputFilters: make([]string, 0), - - versionMajor: maj, - versionMinor: min, } tomlCfg := &toml.Config{ diff --git a/config/deprecation.go b/config/deprecation.go index 18341b0222891..90d80feb1db8d 100644 --- a/config/deprecation.go +++ b/config/deprecation.go @@ -208,11 +208,11 @@ func (c *Config) PrintDeprecationList(infos []PluginDeprecationInfo) { } func (c *Config) getDeprecationEscalation(since string) Escalation { - sinceMajor, sinceMinor := parseVersion(since) - if c.versionMajor > sinceMajor { + sinceMajor, sinceMinor := ParseVersion(since) + if c.VersionMajor > sinceMajor { return Error } - if c.versionMajor == sinceMajor && c.versionMinor >= sinceMinor { + if c.VersionMajor == sinceMajor && c.VersionMinor >= sinceMinor { return Warn } @@ -266,7 +266,7 @@ func walkPluginStruct(value reflect.Value, fn func(f reflect.StructField, fv ref } } -func parseVersion(version string) (major, minor int) { +func ParseVersion(version string) (major, minor int) { parts := strings.SplitN(version, ".", 3) if len(parts) < 2 { panic(fmt.Errorf("insufficient version fields in %q", version)) From f6d5db3aff4ac5b7581fad7267217a14603091e0 Mon Sep 17 00:00:00 2001 From: Sven Rebhan Date: Mon, 4 Oct 2021 20:07:00 +0200 Subject: [PATCH 14/45] Fix linter issues. --- cmd/telegraf/telegraf.go | 4 ++++ config/config.go | 3 --- config/deprecation.go | 6 +++--- plugins/inputs/cassandra/cassandra.go | 2 +- plugins/inputs/http_listener_v2/http_listener_v2.go | 2 +- plugins/inputs/httpjson/httpjson.go | 2 +- plugins/inputs/jolokia/jolokia.go | 2 +- .../inputs/kafka_consumer_legacy/kafka_consumer_legacy.go | 2 +- plugins/inputs/logparser/logparser.go | 2 +- plugins/inputs/snmp_legacy/snmp_legacy.go | 2 +- plugins/inputs/tcp_listener/tcp_listener.go | 2 +- plugins/inputs/udp_listener/udp_listener.go | 2 +- plugins/outputs/riemann_legacy/riemann.go | 2 +- 13 files changed, 17 insertions(+), 16 deletions(-) diff --git a/cmd/telegraf/telegraf.go b/cmd/telegraf/telegraf.go index f8f361b0d3509..c4cb5dd3d613b 100644 --- a/cmd/telegraf/telegraf.go +++ b/cmd/telegraf/telegraf.go @@ -399,12 +399,16 @@ func main() { c := config.NewConfig() c.VersionMajor, c.VersionMinor = config.ParseVersion(version) infos := c.CollectDeprecationInfos() + //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 diff --git a/config/config.go b/config/config.go index 13f25ba1649f9..3723ad61dc993 100644 --- a/config/config.go +++ b/config/config.go @@ -203,9 +203,6 @@ type AgentConfig struct { Hostname string OmitHostname bool - - versionMajor int - versionMinor int } // InputNames returns a list of strings of the configured inputs. diff --git a/config/deprecation.go b/config/deprecation.go index 90d80feb1db8d..01c9314dfc15f 100644 --- a/config/deprecation.go +++ b/config/deprecation.go @@ -2,7 +2,7 @@ package config import ( "fmt" - "log" + "log" //nolint:revive // log is ok here as the logging facility is not set-up yet "reflect" "sort" "strconv" @@ -194,7 +194,7 @@ func (c *Config) PrintDeprecationList(infos []PluginDeprecationInfo) { for _, info := range infos { switch info.Level { case Warn, Error: - fmt.Printf(" %-40s %-5s since %5s %s\n", info.Name, info.Level, info.Since, info.Notice) + _, _ = fmt.Printf(" %-40s %-5s since %5s %s\n", info.Name, info.Level, info.Since, info.Notice) } if len(info.Options) < 1 { @@ -202,7 +202,7 @@ func (c *Config) PrintDeprecationList(infos []PluginDeprecationInfo) { } sort.Slice(info.Options, func(i, j int) bool { return info.Options[i].Name < info.Options[j].Name }) for _, option := range info.Options { - fmt.Printf(" %-40s %-5s since %5s %s\n", info.Name+"/"+option.Name, option.Level, option.Since, option.Notice) + _, _ = fmt.Printf(" %-40s %-5s since %5s %s\n", info.Name+"/"+option.Name, option.Level, option.Since, option.Notice) } } } diff --git a/plugins/inputs/cassandra/cassandra.go b/plugins/inputs/cassandra/cassandra.go index 96b6d9bf46ed7..456ec93fa2f86 100644 --- a/plugins/inputs/cassandra/cassandra.go +++ b/plugins/inputs/cassandra/cassandra.go @@ -313,7 +313,7 @@ func (c *Cassandra) Gather(acc telegraf.Accumulator) error { return nil } -func (_ *Cassandra) DeprecationNotice() (since, notice string) { +func (*Cassandra) DeprecationNotice() (since, notice string) { return "1.7", "use 'inputs.jolokia2' with the 'cassandra.conf' example configuration instead" } diff --git a/plugins/inputs/http_listener_v2/http_listener_v2.go b/plugins/inputs/http_listener_v2/http_listener_v2.go index f62d59e929cff..92a7670098a59 100644 --- a/plugins/inputs/http_listener_v2/http_listener_v2.go +++ b/plugins/inputs/http_listener_v2/http_listener_v2.go @@ -385,7 +385,7 @@ func (h *HTTPListenerV2) authenticateIfSet(handler http.HandlerFunc, res http.Re } } -func (_ *HTTPListenerV2) DeprecationNotice() (since, notice string) { +func (*HTTPListenerV2) DeprecationNotice() (since, notice string) { return "1.9", "has been renamed to 'influxdb_listener', use 'inputs.influxdb_listener' or 'inputs.influxdb_listener_v2' instead" } diff --git a/plugins/inputs/httpjson/httpjson.go b/plugins/inputs/httpjson/httpjson.go index 77d3636138616..4ca87fa46c1d8 100644 --- a/plugins/inputs/httpjson/httpjson.go +++ b/plugins/inputs/httpjson/httpjson.go @@ -283,7 +283,7 @@ func (h *HTTPJSON) sendRequest(serverURL string) (string, float64, error) { return string(body), responseTime, err } -func (_ *HTTPJSON) DeprecationNotice() (since, notice string) { +func (*HTTPJSON) DeprecationNotice() (since, notice string) { return "1.6", "use 'inputs.http' instead" } diff --git a/plugins/inputs/jolokia/jolokia.go b/plugins/inputs/jolokia/jolokia.go index cb39ca25764ed..97f4afcadf503 100644 --- a/plugins/inputs/jolokia/jolokia.go +++ b/plugins/inputs/jolokia/jolokia.go @@ -318,7 +318,7 @@ func (j *Jolokia) Gather(acc telegraf.Accumulator) error { return nil } -func (_ *Jolokia) DeprecationNotice() (since, notice string) { +func (*Jolokia) DeprecationNotice() (since, notice string) { return "1.5", "use 'inputs.jolokia2' instead" } diff --git a/plugins/inputs/kafka_consumer_legacy/kafka_consumer_legacy.go b/plugins/inputs/kafka_consumer_legacy/kafka_consumer_legacy.go index 3803808d9cd1c..041bf2783d25f 100644 --- a/plugins/inputs/kafka_consumer_legacy/kafka_consumer_legacy.go +++ b/plugins/inputs/kafka_consumer_legacy/kafka_consumer_legacy.go @@ -184,7 +184,7 @@ func (k *Kafka) Gather(_ telegraf.Accumulator) error { return nil } -func (_ *Kafka) DeprecationNotice() (since, notice string) { +func (*Kafka) DeprecationNotice() (since, notice string) { return "1.20", "use 'inputs.kafka_consumer' instead, NOTE: 'kafka_consumer' only supports Kafka v0.8+" } diff --git a/plugins/inputs/logparser/logparser.go b/plugins/inputs/logparser/logparser.go index 017ee6868a968..486acb957cdab 100644 --- a/plugins/inputs/logparser/logparser.go +++ b/plugins/inputs/logparser/logparser.go @@ -360,7 +360,7 @@ func (l *LogParserPlugin) Stop() { offsetsMutex.Unlock() } -func (_ *LogParserPlugin) DeprecationNotice() (since, notice string) { +func (*LogParserPlugin) DeprecationNotice() (since, notice string) { return "1.15", "use 'inputs.tail' with 'grok' data format instead" } diff --git a/plugins/inputs/snmp_legacy/snmp_legacy.go b/plugins/inputs/snmp_legacy/snmp_legacy.go index ddbb4d276c1dd..2ee19768a65b9 100644 --- a/plugins/inputs/snmp_legacy/snmp_legacy.go +++ b/plugins/inputs/snmp_legacy/snmp_legacy.go @@ -815,7 +815,7 @@ func (h *Host) HandleResponse( return lastOid, nil } -func (_ *Snmp) DeprecationNotice() (since, notice string) { +func (*Snmp) DeprecationNotice() (since, notice string) { return "1.20", "use 'inputs.snmp' instead" } diff --git a/plugins/inputs/tcp_listener/tcp_listener.go b/plugins/inputs/tcp_listener/tcp_listener.go index f591149a7c556..499f57a7be913 100644 --- a/plugins/inputs/tcp_listener/tcp_listener.go +++ b/plugins/inputs/tcp_listener/tcp_listener.go @@ -297,7 +297,7 @@ func (t *TCPListener) remember(id string, conn *net.TCPConn) { t.conns[id] = conn } -func (_ *TCPListener) DeprecationNotice() (since, notice string) { +func (*TCPListener) DeprecationNotice() (since, notice string) { return "1.3", "use 'inputs.socket_listener' instead" } diff --git a/plugins/inputs/udp_listener/udp_listener.go b/plugins/inputs/udp_listener/udp_listener.go index 8184b114062d2..d9eda53955399 100644 --- a/plugins/inputs/udp_listener/udp_listener.go +++ b/plugins/inputs/udp_listener/udp_listener.go @@ -221,7 +221,7 @@ func (u *UDPListener) udpParser() { } } -func (_ *UDPListener) DeprecationNotice() (since, notice string) { +func (*UDPListener) DeprecationNotice() (since, notice string) { return "1.3", "use 'inputs.socket_listener' instead" } diff --git a/plugins/outputs/riemann_legacy/riemann.go b/plugins/outputs/riemann_legacy/riemann.go index e071928a931c9..ff03feac63410 100644 --- a/plugins/outputs/riemann_legacy/riemann.go +++ b/plugins/outputs/riemann_legacy/riemann.go @@ -147,7 +147,7 @@ func serviceName(s string, n string, t map[string]string, f string) string { return strings.Join(serviceStrings, s) } -func (_ *Riemann) DeprecationNotice() (since, notice string) { +func (*Riemann) DeprecationNotice() (since, notice string) { return "1.20", "use 'outputs.riemann' instead (see https://github.com/influxdata/telegraf/issues/1878)" } From 0792b914f0efd56ad3e826fe4013cc8b2f1cbad2 Mon Sep 17 00:00:00 2001 From: Sven Rebhan Date: Tue, 5 Oct 2021 11:07:15 +0200 Subject: [PATCH 15/45] Make tidy. --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 75496c6646c71..b12d45dbb1ab2 100644 --- a/go.mod +++ b/go.mod @@ -98,7 +98,7 @@ require ( github.com/eapache/queue v1.1.0 // indirect github.com/echlebek/timeproxy v1.0.0 // indirect github.com/eclipse/paho.mqtt.golang v1.3.0 - github.com/fatih/color v1.10.0 // indirect + github.com/fatih/color v1.10.0 github.com/form3tech-oss/jwt-go v3.2.5+incompatible // indirect github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32 github.com/go-logfmt/logfmt v0.5.0 From 4e6e293c89477190bbac3a71b44d18e3eddbc2c8 Mon Sep 17 00:00:00 2001 From: Sven Rebhan Date: Tue, 5 Oct 2021 11:09:24 +0200 Subject: [PATCH 16/45] Add comment to walkPluginStruct(). --- config/deprecation.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/config/deprecation.go b/config/deprecation.go index 01c9314dfc15f..a28366b954fea 100644 --- a/config/deprecation.go +++ b/config/deprecation.go @@ -237,6 +237,9 @@ func printOptionDeprecationNotice(prefix, name, option, since, notice string) { log.Printf("Please note: %s", optionWarnNotice) } + +// walkPluginStruct iterates over the fields of a structure in depth-first search (to cover nested structures) +// and calls the given function for every visited field. func walkPluginStruct(value reflect.Value, fn func(f reflect.StructField, fv reflect.Value)) { v := reflect.Indirect(value) t := v.Type() From b83dc36d4ec62f99308f4097b5766d1f6dc7980f Mon Sep 17 00:00:00 2001 From: Sven Rebhan Date: Tue, 5 Oct 2021 11:17:56 +0200 Subject: [PATCH 17/45] Pimp walkPluginStruct() to also walk structs embedded in slices/arrays and maps. --- config/deprecation.go | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/config/deprecation.go b/config/deprecation.go index a28366b954fea..76df02559b4d5 100644 --- a/config/deprecation.go +++ b/config/deprecation.go @@ -237,13 +237,20 @@ func printOptionDeprecationNotice(prefix, name, option, since, notice string) { log.Printf("Please note: %s", optionWarnNotice) } - // walkPluginStruct iterates over the fields of a structure in depth-first search (to cover nested structures) // and calls the given function for every visited field. func walkPluginStruct(value reflect.Value, fn func(f reflect.StructField, fv reflect.Value)) { v := reflect.Indirect(value) t := v.Type() + // Only works on structs + if t.Kind() != reflect.Struct { + return + } + + // Walk over the struct fields and call the given function. If we encounter more complex embedded + // elements (stucts, slices/arrays, maps) we need to descend into those elements as they might + // contain structures nested in the current structure. for i := 0; i < t.NumField(); i++ { field := t.Field(i) fieldValue := v.Field(i) @@ -254,15 +261,20 @@ func walkPluginStruct(value reflect.Value, fn func(f reflect.StructField, fv ref switch field.Type.Kind() { case reflect.Struct: walkPluginStruct(fieldValue, fn) - case reflect.Array, reflect.Slice: for j := 0; j < fieldValue.Len(); j++ { - fn(field, fieldValue.Index(j)) + element := fieldValue.Index(j) + // The array might contain structs + walkPluginStruct(element, fn) + fn(field, element) } case reflect.Map: iter := fieldValue.MapRange() for iter.Next() { - fn(field, iter.Value()) + element := iter.Value() + // The map might contain structs + walkPluginStruct(element, fn) + fn(field, element) } } fn(field, fieldValue) From 75ee66d7f6fa317e1757370bccac60c32119dfd2 Mon Sep 17 00:00:00 2001 From: Sven Rebhan Date: Wed, 13 Oct 2021 15:12:50 +0200 Subject: [PATCH 18/45] Print deprecation statistics which is also included in a log-file if configured. --- cmd/telegraf/telegraf.go | 13 +++++++++++++ config/config.go | 10 ++++++---- config/deprecation.go | 39 +++++++++++++++++++++++++++++++-------- 3 files changed, 50 insertions(+), 12 deletions(-) diff --git a/cmd/telegraf/telegraf.go b/cmd/telegraf/telegraf.go index c4cb5dd3d613b..02cbc8b641da7 100644 --- a/cmd/telegraf/telegraf.go +++ b/cmd/telegraf/telegraf.go @@ -273,6 +273,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 { diff --git a/config/config.go b/config/config.go index 3723ad61dc993..da512e89699c4 100644 --- a/config/config.go +++ b/config/config.go @@ -80,6 +80,7 @@ type Config struct { VersionMajor int VersionMinor int + Deprecations map[string][]int64 } // NewConfig creates a new struct to hold the Telegraf config. @@ -105,6 +106,7 @@ func NewConfig() *Config { AggProcessors: make([]*models.RunningProcessor, 0), InputFilters: make([]string, 0), OutputFilters: make([]string, 0), + Deprecations: make(map[string][]int64, 0), } tomlCfg := &toml.Config{ @@ -1025,7 +1027,7 @@ func (c *Config) addAggregator(name string, table *ast.Table) error { return err } - if err := c.printUserDeprecation("aggregators."+name, aggregator); err != nil { + if err := c.printUserDeprecation("aggregators", name, aggregator); err != nil { return err } @@ -1077,7 +1079,7 @@ func (c *Config) newRunningProcessor( } } - if err := c.printUserDeprecation("processors."+processorConfig.Name, processor); err != nil { + if err := c.printUserDeprecation("processors", processorConfig.Name, processor); err != nil { return nil, err } @@ -1115,7 +1117,7 @@ func (c *Config) addOutput(name string, table *ast.Table) error { return err } - if err := c.printUserDeprecation("outputs."+name, output); err != nil { + if err := c.printUserDeprecation("outputs", name, output); err != nil { return err } @@ -1168,7 +1170,7 @@ func (c *Config) addInput(name string, table *ast.Table) error { return err } - if err := c.printUserDeprecation("inputs."+name, input); err != nil { + if err := c.printUserDeprecation("inputs", name, input); err != nil { return err } diff --git a/config/deprecation.go b/config/deprecation.go index 76df02559b4d5..ffdbc97932c92 100644 --- a/config/deprecation.go +++ b/config/deprecation.go @@ -64,14 +64,33 @@ type PluginDeprecationInfo struct { Options []DeprecationInfo } -func (c *Config) collectDeprecationInfo(name string, plugin interface{}, all bool) PluginDeprecationInfo { +func (c *Config) incrementPluginDeprecations(category string) { + newcounts := []int64{1, 0} + if counts, found := c.Deprecations[category]; found { + newcounts = []int64{counts[0] + 1, counts[1]} + } + c.Deprecations[category] = newcounts +} + +func (c *Config) incrementPluginOptionDeprecations(category string) { + newcounts := []int64{0, 1} + if counts, found := c.Deprecations[category]; found { + newcounts = []int64{counts[0], counts[1] + 1} + } + c.Deprecations[category] = newcounts +} + +func (c *Config) collectDeprecationInfo(category, name string, plugin interface{}, all bool) PluginDeprecationInfo { info := PluginDeprecationInfo{} - info.Name = name + info.Name = category + "." + name // First check if the whole plugin is deprecated if deprecatedPlugin, ok := plugin.(telegraf.PluginDeprecator); ok { info.Since, info.Notice = deprecatedPlugin.DeprecationNotice() info.Level = c.getDeprecationEscalation(info.Since) + if info.Level != None { + c.incrementPluginDeprecations(category) + } } // Check for deprecated options @@ -91,6 +110,10 @@ func (c *Config) collectDeprecationInfo(name string, plugin interface{}, all boo Level: c.getDeprecationEscalation(tags[0]), } + if optionInfo.Level != None { + c.incrementPluginOptionDeprecations(category) + } + if len(tags) > 1 { optionInfo.Notice = tags[1] } @@ -105,8 +128,8 @@ func (c *Config) collectDeprecationInfo(name string, plugin interface{}, all boo return info } -func (c *Config) printUserDeprecation(name string, plugin interface{}) error { - info := c.collectDeprecationInfo(name, plugin, false) +func (c *Config) printUserDeprecation(category, name string, plugin interface{}) error { + info := c.collectDeprecationInfo(category, name, plugin, false) switch info.Level { case Warn: @@ -148,7 +171,7 @@ func (c *Config) CollectDeprecationInfos() map[string][]PluginDeprecationInfo { infos["inputs"] = make([]PluginDeprecationInfo, 0) for name, creator := range inputs.Inputs { plugin := creator() - info := c.collectDeprecationInfo(name, plugin, true) + info := c.collectDeprecationInfo("inputs", name, plugin, true) if info.Level != None || len(info.Options) > 0 { infos["inputs"] = append(infos["inputs"], info) @@ -158,7 +181,7 @@ func (c *Config) CollectDeprecationInfos() map[string][]PluginDeprecationInfo { infos["outputs"] = make([]PluginDeprecationInfo, 0) for name, creator := range outputs.Outputs { plugin := creator() - info := c.collectDeprecationInfo(name, plugin, true) + info := c.collectDeprecationInfo("outputs", name, plugin, true) if info.Level != None || len(info.Options) > 0 { infos["outputs"] = append(infos["outputs"], info) @@ -168,7 +191,7 @@ func (c *Config) CollectDeprecationInfos() map[string][]PluginDeprecationInfo { infos["processors"] = make([]PluginDeprecationInfo, 0) for name, creator := range processors.Processors { plugin := creator() - info := c.collectDeprecationInfo(name, plugin, true) + info := c.collectDeprecationInfo("processors", name, plugin, true) if info.Level != None || len(info.Options) > 0 { infos["processors"] = append(infos["processors"], info) @@ -178,7 +201,7 @@ func (c *Config) CollectDeprecationInfos() map[string][]PluginDeprecationInfo { infos["aggregators"] = make([]PluginDeprecationInfo, 0) for name, creator := range aggregators.Aggregators { plugin := creator() - info := c.collectDeprecationInfo(name, plugin, true) + info := c.collectDeprecationInfo("aggregators", name, plugin, true) if info.Level != None || len(info.Options) > 0 { infos["aggregators"] = append(infos["aggregators"], info) From 246a650fb47cc40a85ce348b51695cfc5613cc75 Mon Sep 17 00:00:00 2001 From: Sven Rebhan Date: Wed, 13 Oct 2021 15:19:37 +0200 Subject: [PATCH 19/45] Enable plugin filtering for deprecation list. --- cmd/telegraf/telegraf.go | 7 ++++++- config/deprecation.go | 18 +++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/cmd/telegraf/telegraf.go b/cmd/telegraf/telegraf.go index 02cbc8b641da7..4dd2b5a1c19f0 100644 --- a/cmd/telegraf/telegraf.go +++ b/cmd/telegraf/telegraf.go @@ -411,7 +411,12 @@ func main() { case *fDeprecationList: c := config.NewConfig() c.VersionMajor, c.VersionMinor = config.ParseVersion(version) - infos := c.CollectDeprecationInfos() + infos := c.CollectDeprecationInfos( + inputFilters, + outputFilters, + aggregatorFilters, + processorFilters, + ) //nolint:revive // We will notice if Println fails fmt.Println("Deprecated Input Plugins: ") c.PrintDeprecationList(infos["inputs"]) diff --git a/config/deprecation.go b/config/deprecation.go index ffdbc97932c92..ebdf330a7b471 100644 --- a/config/deprecation.go +++ b/config/deprecation.go @@ -165,11 +165,15 @@ func (c *Config) printUserDeprecation(category, name string, plugin interface{}) return nil } -func (c *Config) CollectDeprecationInfos() map[string][]PluginDeprecationInfo { +func (c *Config) CollectDeprecationInfos(inFilter, outFilter, aggFilter, procFilter []string) map[string][]PluginDeprecationInfo { infos := make(map[string][]PluginDeprecationInfo) infos["inputs"] = make([]PluginDeprecationInfo, 0) for name, creator := range inputs.Inputs { + if len(inFilter) > 0 && !sliceContains(name, inFilter) { + continue + } + plugin := creator() info := c.collectDeprecationInfo("inputs", name, plugin, true) @@ -180,6 +184,10 @@ func (c *Config) CollectDeprecationInfos() map[string][]PluginDeprecationInfo { infos["outputs"] = make([]PluginDeprecationInfo, 0) for name, creator := range outputs.Outputs { + if len(outFilter) > 0 && !sliceContains(name, outFilter) { + continue + } + plugin := creator() info := c.collectDeprecationInfo("outputs", name, plugin, true) @@ -190,6 +198,10 @@ func (c *Config) CollectDeprecationInfos() map[string][]PluginDeprecationInfo { infos["processors"] = make([]PluginDeprecationInfo, 0) for name, creator := range processors.Processors { + if len(procFilter) > 0 && !sliceContains(name, procFilter) { + continue + } + plugin := creator() info := c.collectDeprecationInfo("processors", name, plugin, true) @@ -200,6 +212,10 @@ func (c *Config) CollectDeprecationInfos() map[string][]PluginDeprecationInfo { infos["aggregators"] = make([]PluginDeprecationInfo, 0) for name, creator := range aggregators.Aggregators { + if len(aggFilter) > 0 && !sliceContains(name, aggFilter) { + continue + } + plugin := creator() info := c.collectDeprecationInfo("aggregators", name, plugin, true) From 1d09c2e34793d7bea883ea4b81bb4ef413538cee Mon Sep 17 00:00:00 2001 From: Sven Rebhan Date: Thu, 14 Oct 2021 10:02:51 +0200 Subject: [PATCH 20/45] Add new command-line flag to documentation. --- docs/COMMANDS_AND_FLAGS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/COMMANDS_AND_FLAGS.md b/docs/COMMANDS_AND_FLAGS.md index babccb54ba152..b575b1a6f527c 100644 --- a/docs/COMMANDS_AND_FLAGS.md +++ b/docs/COMMANDS_AND_FLAGS.md @@ -24,6 +24,7 @@ telegraf [flags] |`--watch-config` |Telegraf will restart on local config changes. Monitor changes using either fs notifications or polling. Valid values: `inotify` or `poll`. Monitoring is off by default.| |`--plugin-directory` |directory containing *.so files, this directory will be searched recursively. Any Plugin found will be loaded and namespaced.| |`--debug` |turn on debug logging| +|`--deprecation-list` |print all deprecated plugins or plugin options| |`--input-filter ` |filter the inputs to enable, separator is `:`| |`--input-list` |print available input plugins.| |`--output-filter ` |filter the outputs to enable, separator is `:`| From 86e559bb4563348001b2e4b88b8ffd4a455f8d98 Mon Sep 17 00:00:00 2001 From: Sven Rebhan Date: Fri, 15 Oct 2021 13:03:20 +0200 Subject: [PATCH 21/45] Fix doc alignment. --- docs/COMMANDS_AND_FLAGS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/COMMANDS_AND_FLAGS.md b/docs/COMMANDS_AND_FLAGS.md index b575b1a6f527c..9a57a0b832bd7 100644 --- a/docs/COMMANDS_AND_FLAGS.md +++ b/docs/COMMANDS_AND_FLAGS.md @@ -24,7 +24,7 @@ telegraf [flags] |`--watch-config` |Telegraf will restart on local config changes. Monitor changes using either fs notifications or polling. Valid values: `inotify` or `poll`. Monitoring is off by default.| |`--plugin-directory` |directory containing *.so files, this directory will be searched recursively. Any Plugin found will be loaded and namespaced.| |`--debug` |turn on debug logging| -|`--deprecation-list` |print all deprecated plugins or plugin options| +|`--deprecation-list` |print all deprecated plugins or plugin options| |`--input-filter ` |filter the inputs to enable, separator is `:`| |`--input-list` |print available input plugins.| |`--output-filter ` |filter the outputs to enable, separator is `:`| From 43079aee67d8928fca13e157c58ba4b493ff2f6d Mon Sep 17 00:00:00 2001 From: Sven Rebhan Date: Fri, 15 Oct 2021 13:04:29 +0200 Subject: [PATCH 22/45] Fix linter error. --- config/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/config.go b/config/config.go index da512e89699c4..affba30b2ae38 100644 --- a/config/config.go +++ b/config/config.go @@ -106,7 +106,7 @@ func NewConfig() *Config { AggProcessors: make([]*models.RunningProcessor, 0), InputFilters: make([]string, 0), OutputFilters: make([]string, 0), - Deprecations: make(map[string][]int64, 0), + Deprecations: make(map[string][]int64), } tomlCfg := &toml.Config{ From 529557d2883f7c9120bd1374422b3f9a3ab8eae6 Mon Sep 17 00:00:00 2001 From: Sven Rebhan Date: Tue, 9 Nov 2021 18:47:22 +0100 Subject: [PATCH 23/45] Implement discussed deprecation strategy and allow to specify a custom removal version. --- config/deprecation.go | 138 ++++++++++++++++------------ plugin.go | 2 +- plugins/inputs/httpjson/httpjson.go | 4 +- 3 files changed, 81 insertions(+), 63 deletions(-) diff --git a/config/deprecation.go b/config/deprecation.go index ebdf330a7b471..4d16a34ba182e 100644 --- a/config/deprecation.go +++ b/config/deprecation.go @@ -17,11 +17,6 @@ import ( "github.com/influxdata/telegraf/plugins/processors" ) -const ( - pluginWarnNotice = "Deprecated plugin will be removed soon, please switch to a supported plugin!" - optionWarnNotice = "Deprecated options will be removed with the next major version, please adapt your config!" -) - // Escalation level for the plugin or option type Escalation int @@ -44,24 +39,73 @@ const ( Error ) -// DeprecationInfo contains all important information to describe a deprecated entity -type DeprecationInfo struct { +// deprecationInfo contains all important information to describe a deprecated entity +type deprecationInfo struct { // Name of the plugin or plugin option Name string // Level of deprecation Level Escalation // Since which version the plugin or plugin option is deprecated Since string + // RemovalIn is an optional field denoting in which version the plugin or plugin option is actually removed + RemovalIn string // Notice to the user about alternatives or further information Notice string } -// PluginDeprecationInfo holds all information about a deprecated plugin or it's options -type PluginDeprecationInfo struct { - DeprecationInfo +func (di *deprecationInfo) determineEscalation(major, minor int) { + var removalMajor, removalMinor int + + sinceMajor, sinceMinor := ParseVersion(di.Since) + if di.RemovalIn != "" { + removalMajor, removalMinor = ParseVersion(di.RemovalIn) + } else { + removalMajor, removalMinor = sinceMajor+1, 0 + di.RemovalIn = fmt.Sprintf("%d.%d", removalMajor, removalMinor) + } + + di.Level = None + if major > removalMajor || (major == removalMajor && minor >= removalMinor) { + di.Level = Error + } else if major > sinceMajor || (major == sinceMajor && minor >= sinceMinor) { + di.Level = Warn + } +} + +func (di *deprecationInfo) printPluginDeprecationNotice(prefix string) { + if di.Notice != "" { + log.Printf( + "%s: Plugin %q deprecated since version %s and will be removed in %s: %s", + prefix, di.Name, di.Since, di.RemovalIn, di.Notice, + ) + } else { + log.Printf( + "%s: Plugin %q deprecated since version %s and will be removed in %s", + prefix, di.Name, di.Since, di.RemovalIn, + ) + } +} + +func (di *deprecationInfo) printOptionDeprecationNotice(prefix, plugin string) { + if di.Notice != "" { + log.Printf( + "%s: Option %q of plugin %q deprecated since version %s and will be removed in %s: %s", + prefix, di.Name, plugin, di.Since, di.RemovalIn, di.Notice, + ) + } else { + log.Printf( + "%s: Option %q of plugin %q deprecated since version %s and will be removed in %s", + prefix, di.Name, plugin, di.Since, di.RemovalIn, + ) + } +} + +// pluginDeprecationInfo holds all information about a deprecated plugin or it's options +type pluginDeprecationInfo struct { + deprecationInfo // Options deprecated for this plugin - Options []DeprecationInfo + Options []deprecationInfo } func (c *Config) incrementPluginDeprecations(category string) { @@ -80,14 +124,14 @@ func (c *Config) incrementPluginOptionDeprecations(category string) { c.Deprecations[category] = newcounts } -func (c *Config) collectDeprecationInfo(category, name string, plugin interface{}, all bool) PluginDeprecationInfo { - info := PluginDeprecationInfo{} +func (c *Config) collectDeprecationInfo(category, name string, plugin interface{}, all bool) pluginDeprecationInfo { + info := pluginDeprecationInfo{} info.Name = category + "." + name // First check if the whole plugin is deprecated if deprecatedPlugin, ok := plugin.(telegraf.PluginDeprecator); ok { - info.Since, info.Notice = deprecatedPlugin.DeprecationNotice() - info.Level = c.getDeprecationEscalation(info.Since) + info.Since, info.RemovalIn, info.Notice = deprecatedPlugin.DeprecationNotice() + info.determineEscalation(c.VersionMajor, c.VersionMinor) if info.Level != None { c.incrementPluginDeprecations(category) } @@ -100,14 +144,13 @@ func (c *Config) collectDeprecationInfo(category, name string, plugin interface{ return } - tags := strings.SplitN(field.Tag.Get("deprecated"), ";", 2) + tags := strings.SplitN(field.Tag.Get("deprecated"), ";", 3) if len(tags) < 1 || tags[0] == "" { return } - optionInfo := DeprecationInfo{ + optionInfo := deprecationInfo{ Name: field.Name, Since: tags[0], - Level: c.getDeprecationEscalation(tags[0]), } if optionInfo.Level != None { @@ -115,8 +158,13 @@ func (c *Config) collectDeprecationInfo(category, name string, plugin interface{ } if len(tags) > 1 { - optionInfo.Notice = tags[1] + optionInfo.Notice = tags[len(tags)-1] + } + if len(tags) > 2 { + optionInfo.RemovalIn = tags[1] } + optionInfo.determineEscalation(c.VersionMajor, c.VersionMinor) + // Get the toml field name option := field.Tag.Get("toml") if option != "" { @@ -134,12 +182,12 @@ func (c *Config) printUserDeprecation(category, name string, plugin interface{}) switch info.Level { case Warn: prefix := "W! " + color.YellowString("DeprecationWarning") - printPluginDeprecationNotice(prefix, info.Name, info.Since, info.Notice) + info.printPluginDeprecationNotice(prefix) // We will not check for any deprecated options as the whole plugin is deprecated anyway. return nil case Error: prefix := "E! " + color.RedString("DeprecationError") - printPluginDeprecationNotice(prefix, info.Name, info.Since, info.Notice) + info.printPluginDeprecationNotice(prefix) // We are past the grace period return fmt.Errorf("plugin deprecated") } @@ -150,10 +198,10 @@ func (c *Config) printUserDeprecation(category, name string, plugin interface{}) switch option.Level { case Warn: prefix := "W! " + color.YellowString("DeprecationWarning") - printOptionDeprecationNotice(prefix, info.Name, option.Name, option.Since, option.Notice) + option.printOptionDeprecationNotice(prefix, info.Name) case Error: prefix := "E! " + color.RedString("DeprecationError") - printOptionDeprecationNotice(prefix, info.Name, option.Name, option.Since, option.Notice) + option.printOptionDeprecationNotice(prefix, info.Name) deprecatedOptions = append(deprecatedOptions, option.Name) } } @@ -165,10 +213,10 @@ func (c *Config) printUserDeprecation(category, name string, plugin interface{}) return nil } -func (c *Config) CollectDeprecationInfos(inFilter, outFilter, aggFilter, procFilter []string) map[string][]PluginDeprecationInfo { - infos := make(map[string][]PluginDeprecationInfo) +func (c *Config) CollectDeprecationInfos(inFilter, outFilter, aggFilter, procFilter []string) map[string][]pluginDeprecationInfo { + infos := make(map[string][]pluginDeprecationInfo) - infos["inputs"] = make([]PluginDeprecationInfo, 0) + infos["inputs"] = make([]pluginDeprecationInfo, 0) for name, creator := range inputs.Inputs { if len(inFilter) > 0 && !sliceContains(name, inFilter) { continue @@ -182,7 +230,7 @@ func (c *Config) CollectDeprecationInfos(inFilter, outFilter, aggFilter, procFil } } - infos["outputs"] = make([]PluginDeprecationInfo, 0) + infos["outputs"] = make([]pluginDeprecationInfo, 0) for name, creator := range outputs.Outputs { if len(outFilter) > 0 && !sliceContains(name, outFilter) { continue @@ -196,7 +244,7 @@ func (c *Config) CollectDeprecationInfos(inFilter, outFilter, aggFilter, procFil } } - infos["processors"] = make([]PluginDeprecationInfo, 0) + infos["processors"] = make([]pluginDeprecationInfo, 0) for name, creator := range processors.Processors { if len(procFilter) > 0 && !sliceContains(name, procFilter) { continue @@ -210,7 +258,7 @@ func (c *Config) CollectDeprecationInfos(inFilter, outFilter, aggFilter, procFil } } - infos["aggregators"] = make([]PluginDeprecationInfo, 0) + infos["aggregators"] = make([]pluginDeprecationInfo, 0) for name, creator := range aggregators.Aggregators { if len(aggFilter) > 0 && !sliceContains(name, aggFilter) { continue @@ -227,7 +275,7 @@ func (c *Config) CollectDeprecationInfos(inFilter, outFilter, aggFilter, procFil return infos } -func (c *Config) PrintDeprecationList(infos []PluginDeprecationInfo) { +func (c *Config) PrintDeprecationList(infos []pluginDeprecationInfo) { sort.Slice(infos, func(i, j int) bool { return infos[i].Name < infos[j].Name }) for _, info := range infos { @@ -246,36 +294,6 @@ func (c *Config) PrintDeprecationList(infos []PluginDeprecationInfo) { } } -func (c *Config) getDeprecationEscalation(since string) Escalation { - sinceMajor, sinceMinor := ParseVersion(since) - if c.VersionMajor > sinceMajor { - return Error - } - if c.VersionMajor == sinceMajor && c.VersionMinor >= sinceMinor { - return Warn - } - - return None -} - -func printPluginDeprecationNotice(prefix, name, since, notice string) { - if notice != "" { - log.Printf("%s: Plugin %q deprecated since version %s: %s", prefix, name, since, notice) - } else { - log.Printf("%s: Plugin %q deprecated since version %s", prefix, name, since) - } - log.Printf("Please note: %s", pluginWarnNotice) -} - -func printOptionDeprecationNotice(prefix, name, option, since, notice string) { - if notice != "" { - log.Printf("%s: Option %q of plugin %q deprecated since version %s: %s", prefix, option, name, since, notice) - } else { - log.Printf("%s: Option %q of plugin %q deprecated since version %s", prefix, option, name, since) - } - log.Printf("Please note: %s", optionWarnNotice) -} - // walkPluginStruct iterates over the fields of a structure in depth-first search (to cover nested structures) // and calls the given function for every visited field. func walkPluginStruct(value reflect.Value, fn func(f reflect.StructField, fv reflect.Value)) { diff --git a/plugin.go b/plugin.go index 322f721fd66a3..9bd593cb785f7 100644 --- a/plugin.go +++ b/plugin.go @@ -27,7 +27,7 @@ type PluginDescriber interface { type PluginDeprecator interface { // DeprecationNotice returns the version since when the plugin is deprecated and // (optionally) provides a deprecation notice allowing to suggest replacements etc. - DeprecationNotice() (since string, notice string) + DeprecationNotice() (since string, removalIn, notice string) } // Logger defines an plugin-related interface for logging. diff --git a/plugins/inputs/httpjson/httpjson.go b/plugins/inputs/httpjson/httpjson.go index 4ca87fa46c1d8..1528a32f09b07 100644 --- a/plugins/inputs/httpjson/httpjson.go +++ b/plugins/inputs/httpjson/httpjson.go @@ -283,8 +283,8 @@ func (h *HTTPJSON) sendRequest(serverURL string) (string, float64, error) { return string(body), responseTime, err } -func (*HTTPJSON) DeprecationNotice() (since, notice string) { - return "1.6", "use 'inputs.http' instead" +func (*HTTPJSON) DeprecationNotice() (since, removalIn, notice string) { + return "1.6", "", "use 'inputs.http' instead" } func init() { From 71575986ad7b4b802564456b6b8a0dbf57ae1e18 Mon Sep 17 00:00:00 2001 From: Sven Rebhan Date: Tue, 9 Nov 2021 19:29:09 +0100 Subject: [PATCH 24/45] Move deprecation info to long-term persistant tables. --- config/deprecation.go | 99 +++++++++++-------- plugin.go | 17 ++-- plugins/inputs/cassandra/cassandra.go | 4 - plugins/inputs/deprecations.go | 15 +++ .../http_listener_v2/http_listener_v2.go | 4 - plugins/inputs/httpjson/httpjson.go | 4 - plugins/inputs/jolokia/jolokia.go | 4 - .../kafka_consumer_legacy.go | 4 - plugins/inputs/logparser/logparser.go | 4 - plugins/inputs/snmp_legacy/snmp_legacy.go | 4 - plugins/inputs/tcp_listener/tcp_listener.go | 4 - plugins/inputs/udp_listener/udp_listener.go | 4 - plugins/outputs/deprecations.go | 7 ++ plugins/outputs/riemann_legacy/riemann.go | 4 - 14 files changed, 89 insertions(+), 89 deletions(-) create mode 100644 plugins/inputs/deprecations.go create mode 100644 plugins/outputs/deprecations.go diff --git a/config/deprecation.go b/config/deprecation.go index 4d16a34ba182e..94104fa3dc407 100644 --- a/config/deprecation.go +++ b/config/deprecation.go @@ -45,23 +45,23 @@ type deprecationInfo struct { Name string // Level of deprecation Level Escalation - // Since which version the plugin or plugin option is deprecated - Since string - // RemovalIn is an optional field denoting in which version the plugin or plugin option is actually removed - RemovalIn string - // Notice to the user about alternatives or further information - Notice string + info telegraf.DeprecationInfo } func (di *deprecationInfo) determineEscalation(major, minor int) { var removalMajor, removalMinor int - sinceMajor, sinceMinor := ParseVersion(di.Since) - if di.RemovalIn != "" { - removalMajor, removalMinor = ParseVersion(di.RemovalIn) + di.Level = None + if di.info.Since == "" { + return + } + + sinceMajor, sinceMinor := ParseVersion(di.info.Since) + if di.info.RemovalIn != "" { + removalMajor, removalMinor = ParseVersion(di.info.RemovalIn) } else { removalMajor, removalMinor = sinceMajor+1, 0 - di.RemovalIn = fmt.Sprintf("%d.%d", removalMajor, removalMinor) + di.info.RemovalIn = fmt.Sprintf("%d.%d", removalMajor, removalMinor) } di.Level = None @@ -73,29 +73,29 @@ func (di *deprecationInfo) determineEscalation(major, minor int) { } func (di *deprecationInfo) printPluginDeprecationNotice(prefix string) { - if di.Notice != "" { + if di.info.Notice != "" { log.Printf( "%s: Plugin %q deprecated since version %s and will be removed in %s: %s", - prefix, di.Name, di.Since, di.RemovalIn, di.Notice, + prefix, di.Name, di.info.Since, di.info.RemovalIn, di.info.Notice, ) } else { log.Printf( "%s: Plugin %q deprecated since version %s and will be removed in %s", - prefix, di.Name, di.Since, di.RemovalIn, + prefix, di.Name, di.info.Since, di.info.RemovalIn, ) } } func (di *deprecationInfo) printOptionDeprecationNotice(prefix, plugin string) { - if di.Notice != "" { + if di.info.Notice != "" { log.Printf( "%s: Option %q of plugin %q deprecated since version %s and will be removed in %s: %s", - prefix, di.Name, plugin, di.Since, di.RemovalIn, di.Notice, + prefix, di.Name, plugin, di.info.Since, di.info.RemovalIn, di.info.Notice, ) } else { log.Printf( "%s: Option %q of plugin %q deprecated since version %s and will be removed in %s", - prefix, di.Name, plugin, di.Since, di.RemovalIn, + prefix, di.Name, plugin, di.info.Since, di.info.RemovalIn, ) } } @@ -125,17 +125,28 @@ func (c *Config) incrementPluginOptionDeprecations(category string) { } func (c *Config) collectDeprecationInfo(category, name string, plugin interface{}, all bool) pluginDeprecationInfo { - info := pluginDeprecationInfo{} - info.Name = category + "." + name + info := pluginDeprecationInfo{ + deprecationInfo: deprecationInfo{ + Name: category + "." + name, + Level: None, + }, + } // First check if the whole plugin is deprecated - if deprecatedPlugin, ok := plugin.(telegraf.PluginDeprecator); ok { - info.Since, info.RemovalIn, info.Notice = deprecatedPlugin.DeprecationNotice() - info.determineEscalation(c.VersionMajor, c.VersionMinor) - if info.Level != None { - c.incrementPluginDeprecations(category) + switch category { + case "inputs": + if pi, deprecated := inputs.Deprecations[name]; deprecated { + info.deprecationInfo.info = pi + } + case "outputs": + if pi, deprecated := outputs.Deprecations[name]; deprecated { + info.deprecationInfo.info = pi } } + info.determineEscalation(c.VersionMajor, c.VersionMinor) + if info.Level != None { + c.incrementPluginDeprecations(category) + } // Check for deprecated options walkPluginStruct(reflect.ValueOf(plugin), func(field reflect.StructField, value reflect.Value) { @@ -148,23 +159,21 @@ func (c *Config) collectDeprecationInfo(category, name string, plugin interface{ if len(tags) < 1 || tags[0] == "" { return } - optionInfo := deprecationInfo{ - Name: field.Name, - Since: tags[0], - } - - if optionInfo.Level != None { - c.incrementPluginOptionDeprecations(category) - } + optionInfo := deprecationInfo{Name: field.Name} + optionInfo.info.Since = tags[0] if len(tags) > 1 { - optionInfo.Notice = tags[len(tags)-1] + optionInfo.info.Notice = tags[len(tags)-1] } if len(tags) > 2 { - optionInfo.RemovalIn = tags[1] + optionInfo.info.RemovalIn = tags[1] } optionInfo.determineEscalation(c.VersionMajor, c.VersionMinor) + if optionInfo.Level != None { + c.incrementPluginOptionDeprecations(category) + } + // Get the toml field name option := field.Tag.Get("toml") if option != "" { @@ -275,21 +284,27 @@ func (c *Config) CollectDeprecationInfos(inFilter, outFilter, aggFilter, procFil return infos } -func (c *Config) PrintDeprecationList(infos []pluginDeprecationInfo) { - sort.Slice(infos, func(i, j int) bool { return infos[i].Name < infos[j].Name }) +func (c *Config) PrintDeprecationList(plugins []pluginDeprecationInfo) { + sort.Slice(plugins, func(i, j int) bool { return plugins[i].Name < plugins[j].Name }) - for _, info := range infos { - switch info.Level { + for _, plugin := range plugins { + switch plugin.Level { case Warn, Error: - _, _ = fmt.Printf(" %-40s %-5s since %5s %s\n", info.Name, info.Level, info.Since, info.Notice) + _, _ = fmt.Printf( + " %-40s %-5s since %-5s removal in %-5s %s\n", + plugin.Name, plugin.Level, plugin.info.Since, plugin.info.RemovalIn, plugin.info.Notice, + ) } - if len(info.Options) < 1 { + if len(plugin.Options) < 1 { continue } - sort.Slice(info.Options, func(i, j int) bool { return info.Options[i].Name < info.Options[j].Name }) - for _, option := range info.Options { - _, _ = fmt.Printf(" %-40s %-5s since %5s %s\n", info.Name+"/"+option.Name, option.Level, option.Since, option.Notice) + sort.Slice(plugin.Options, func(i, j int) bool { return plugin.Options[i].Name < plugin.Options[j].Name }) + for _, option := range plugin.Options { + _, _ = fmt.Printf( + " %-40s %-5s since %-5s removal in %-5s %s\n", + plugin.Name+"/"+option.Name, option.Level, option.info.Since, option.info.RemovalIn, option.info.Notice, + ) } } } diff --git a/plugin.go b/plugin.go index 9bd593cb785f7..3f4004d766457 100644 --- a/plugin.go +++ b/plugin.go @@ -2,6 +2,16 @@ package telegraf var Debug bool +// DeprecationInfo contains information for marking a plugin deprecated. +type DeprecationInfo struct { + // Since specifies the version since when the plugin is deprecated + Since string + // RemovalIn optionally specifies the version when the plugin is scheduled for removal + RemovalIn string + // Notice for the user on suggested replacements etc. + Notice string +} + // Initializer is an interface that all plugin types: Inputs, Outputs, // Processors, and Aggregators can optionally implement to initialize the // plugin. @@ -23,13 +33,6 @@ type PluginDescriber interface { Description() string } -// PluginDeprecator marks a plugin as deprecated and provides hints to the user. -type PluginDeprecator interface { - // DeprecationNotice returns the version since when the plugin is deprecated and - // (optionally) provides a deprecation notice allowing to suggest replacements etc. - DeprecationNotice() (since string, removalIn, notice string) -} - // Logger defines an plugin-related interface for logging. type Logger interface { // Errorf logs an error message, patterned after log.Printf. diff --git a/plugins/inputs/cassandra/cassandra.go b/plugins/inputs/cassandra/cassandra.go index 456ec93fa2f86..d1c23caadc68a 100644 --- a/plugins/inputs/cassandra/cassandra.go +++ b/plugins/inputs/cassandra/cassandra.go @@ -313,10 +313,6 @@ func (c *Cassandra) Gather(acc telegraf.Accumulator) error { return nil } -func (*Cassandra) DeprecationNotice() (since, notice string) { - return "1.7", "use 'inputs.jolokia2' with the 'cassandra.conf' example configuration instead" -} - func init() { inputs.Add("cassandra", func() telegraf.Input { return &Cassandra{jClient: &JolokiaClientImpl{client: &http.Client{}}} diff --git a/plugins/inputs/deprecations.go b/plugins/inputs/deprecations.go new file mode 100644 index 0000000000000..edec5fcf13ac1 --- /dev/null +++ b/plugins/inputs/deprecations.go @@ -0,0 +1,15 @@ +package inputs + +import "github.com/influxdata/telegraf" + +var Deprecations = map[string]telegraf.DeprecationInfo{ + "cassandra": {"1.7", "", "use 'inputs.jolokia2' with the 'cassandra.conf' example configuration instead"}, + "http_listener_v2": {"1.9", "", "has been renamed to 'influxdb_listener', use 'inputs.influxdb_listener' or 'inputs.influxdb_listener_v2' instead"}, + "httpjson": {"1.6", "", "use 'inputs.http' instead"}, + "jolokia": {"1.5", "", "use 'inputs.jolokia2' instead"}, + "kafka_consumer_legacy": {"1.20", "", "use 'inputs.kafka_consumer' instead, NOTE: 'kafka_consumer' only supports Kafka v0.8+"}, + "logparser": {"1.15", "", "use 'inputs.tail' with 'grok' data format instead"}, + "snmp_legacy": {"1.20", "", "use 'inputs.snmp' instead"}, + "tcp_listener": {"1.3", "", "use 'inputs.socket_listener' instead"}, + "udp_listener": {"1.3", "", "use 'inputs.socket_listener' instead"}, +} diff --git a/plugins/inputs/http_listener_v2/http_listener_v2.go b/plugins/inputs/http_listener_v2/http_listener_v2.go index 92a7670098a59..d2a2e5f35214e 100644 --- a/plugins/inputs/http_listener_v2/http_listener_v2.go +++ b/plugins/inputs/http_listener_v2/http_listener_v2.go @@ -385,10 +385,6 @@ func (h *HTTPListenerV2) authenticateIfSet(handler http.HandlerFunc, res http.Re } } -func (*HTTPListenerV2) DeprecationNotice() (since, notice string) { - return "1.9", "has been renamed to 'influxdb_listener', use 'inputs.influxdb_listener' or 'inputs.influxdb_listener_v2' instead" -} - func init() { inputs.Add("http_listener_v2", func() telegraf.Input { return &HTTPListenerV2{ diff --git a/plugins/inputs/httpjson/httpjson.go b/plugins/inputs/httpjson/httpjson.go index 1528a32f09b07..10a4cb0c17643 100644 --- a/plugins/inputs/httpjson/httpjson.go +++ b/plugins/inputs/httpjson/httpjson.go @@ -283,10 +283,6 @@ func (h *HTTPJSON) sendRequest(serverURL string) (string, float64, error) { return string(body), responseTime, err } -func (*HTTPJSON) DeprecationNotice() (since, removalIn, notice string) { - return "1.6", "", "use 'inputs.http' instead" -} - func init() { inputs.Add("httpjson", func() telegraf.Input { return &HTTPJSON{ diff --git a/plugins/inputs/jolokia/jolokia.go b/plugins/inputs/jolokia/jolokia.go index 97f4afcadf503..af5e3de283800 100644 --- a/plugins/inputs/jolokia/jolokia.go +++ b/plugins/inputs/jolokia/jolokia.go @@ -318,10 +318,6 @@ func (j *Jolokia) Gather(acc telegraf.Accumulator) error { return nil } -func (*Jolokia) DeprecationNotice() (since, notice string) { - return "1.5", "use 'inputs.jolokia2' instead" -} - func init() { inputs.Add("jolokia", func() telegraf.Input { return &Jolokia{ diff --git a/plugins/inputs/kafka_consumer_legacy/kafka_consumer_legacy.go b/plugins/inputs/kafka_consumer_legacy/kafka_consumer_legacy.go index 041bf2783d25f..ab19e0875820a 100644 --- a/plugins/inputs/kafka_consumer_legacy/kafka_consumer_legacy.go +++ b/plugins/inputs/kafka_consumer_legacy/kafka_consumer_legacy.go @@ -184,10 +184,6 @@ func (k *Kafka) Gather(_ telegraf.Accumulator) error { return nil } -func (*Kafka) DeprecationNotice() (since, notice string) { - return "1.20", "use 'inputs.kafka_consumer' instead, NOTE: 'kafka_consumer' only supports Kafka v0.8+" -} - func init() { inputs.Add("kafka_consumer_legacy", func() telegraf.Input { return &Kafka{} diff --git a/plugins/inputs/logparser/logparser.go b/plugins/inputs/logparser/logparser.go index 486acb957cdab..83f5abd210bdd 100644 --- a/plugins/inputs/logparser/logparser.go +++ b/plugins/inputs/logparser/logparser.go @@ -360,10 +360,6 @@ func (l *LogParserPlugin) Stop() { offsetsMutex.Unlock() } -func (*LogParserPlugin) DeprecationNotice() (since, notice string) { - return "1.15", "use 'inputs.tail' with 'grok' data format instead" -} - func init() { inputs.Add("logparser", func() telegraf.Input { return NewLogParser() diff --git a/plugins/inputs/snmp_legacy/snmp_legacy.go b/plugins/inputs/snmp_legacy/snmp_legacy.go index 2ee19768a65b9..ce454cbfbad36 100644 --- a/plugins/inputs/snmp_legacy/snmp_legacy.go +++ b/plugins/inputs/snmp_legacy/snmp_legacy.go @@ -815,10 +815,6 @@ func (h *Host) HandleResponse( return lastOid, nil } -func (*Snmp) DeprecationNotice() (since, notice string) { - return "1.20", "use 'inputs.snmp' instead" -} - func init() { inputs.Add("snmp_legacy", func() telegraf.Input { return &Snmp{} diff --git a/plugins/inputs/tcp_listener/tcp_listener.go b/plugins/inputs/tcp_listener/tcp_listener.go index 499f57a7be913..8eeaa9cff8091 100644 --- a/plugins/inputs/tcp_listener/tcp_listener.go +++ b/plugins/inputs/tcp_listener/tcp_listener.go @@ -297,10 +297,6 @@ func (t *TCPListener) remember(id string, conn *net.TCPConn) { t.conns[id] = conn } -func (*TCPListener) DeprecationNotice() (since, notice string) { - return "1.3", "use 'inputs.socket_listener' instead" -} - func init() { inputs.Add("tcp_listener", func() telegraf.Input { return &TCPListener{ diff --git a/plugins/inputs/udp_listener/udp_listener.go b/plugins/inputs/udp_listener/udp_listener.go index d9eda53955399..39fef79ce1b98 100644 --- a/plugins/inputs/udp_listener/udp_listener.go +++ b/plugins/inputs/udp_listener/udp_listener.go @@ -221,10 +221,6 @@ func (u *UDPListener) udpParser() { } } -func (*UDPListener) DeprecationNotice() (since, notice string) { - return "1.3", "use 'inputs.socket_listener' instead" -} - func init() { inputs.Add("udp_listener", func() telegraf.Input { return &UDPListener{ diff --git a/plugins/outputs/deprecations.go b/plugins/outputs/deprecations.go new file mode 100644 index 0000000000000..900e5ffd1e36b --- /dev/null +++ b/plugins/outputs/deprecations.go @@ -0,0 +1,7 @@ +package outputs + +import "github.com/influxdata/telegraf" + +var Deprecations = map[string]telegraf.DeprecationInfo{ + "riemann_legacy": {"1.20", "", "use 'outputs.riemann' instead (see https://github.com/influxdata/telegraf/issues/1878)"}, +} diff --git a/plugins/outputs/riemann_legacy/riemann.go b/plugins/outputs/riemann_legacy/riemann.go index ff03feac63410..0bd0f6b876c68 100644 --- a/plugins/outputs/riemann_legacy/riemann.go +++ b/plugins/outputs/riemann_legacy/riemann.go @@ -147,10 +147,6 @@ func serviceName(s string, n string, t map[string]string, f string) string { return strings.Join(serviceStrings, s) } -func (*Riemann) DeprecationNotice() (since, notice string) { - return "1.20", "use 'outputs.riemann' instead (see https://github.com/influxdata/telegraf/issues/1878)" -} - func init() { outputs.Add("riemann_legacy", func() telegraf.Output { return &Riemann{} From 3374eae1632afff7646ac4ea8769e3dc3cbc3c38 Mon Sep 17 00:00:00 2001 From: Sven Rebhan Date: Tue, 9 Nov 2021 19:56:40 +0100 Subject: [PATCH 25/45] Print deprecation notice for deprecated and already removed plugins. --- config/config.go | 22 +++++++++++ config/deprecation.go | 58 +++++++++++++---------------- plugins/aggregators/deprecations.go | 5 +++ plugins/processors/deprecations.go | 5 +++ 4 files changed, 58 insertions(+), 32 deletions(-) create mode 100644 plugins/aggregators/deprecations.go create mode 100644 plugins/processors/deprecations.go diff --git a/config/config.go b/config/config.go index affba30b2ae38..7e2cb836adf3f 100644 --- a/config/config.go +++ b/config/config.go @@ -1014,6 +1014,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() @@ -1038,6 +1043,11 @@ func (c *Config) addAggregator(name string, table *ast.Table) error { 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) } @@ -1093,6 +1103,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() @@ -1130,6 +1145,7 @@ 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" { name = "diskio" @@ -1137,6 +1153,12 @@ func (c *Config) addInput(name string, table *ast.Table) error { 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() diff --git a/config/deprecation.go b/config/deprecation.go index 94104fa3dc407..8dc691d63de2f 100644 --- a/config/deprecation.go +++ b/config/deprecation.go @@ -72,34 +72,6 @@ func (di *deprecationInfo) determineEscalation(major, minor int) { } } -func (di *deprecationInfo) printPluginDeprecationNotice(prefix string) { - if di.info.Notice != "" { - log.Printf( - "%s: Plugin %q deprecated since version %s and will be removed in %s: %s", - prefix, di.Name, di.info.Since, di.info.RemovalIn, di.info.Notice, - ) - } else { - log.Printf( - "%s: Plugin %q deprecated since version %s and will be removed in %s", - prefix, di.Name, di.info.Since, di.info.RemovalIn, - ) - } -} - -func (di *deprecationInfo) printOptionDeprecationNotice(prefix, plugin string) { - if di.info.Notice != "" { - log.Printf( - "%s: Option %q of plugin %q deprecated since version %s and will be removed in %s: %s", - prefix, di.Name, plugin, di.info.Since, di.info.RemovalIn, di.info.Notice, - ) - } else { - log.Printf( - "%s: Option %q of plugin %q deprecated since version %s and will be removed in %s", - prefix, di.Name, plugin, di.info.Since, di.info.RemovalIn, - ) - } -} - // pluginDeprecationInfo holds all information about a deprecated plugin or it's options type pluginDeprecationInfo struct { deprecationInfo @@ -191,12 +163,12 @@ func (c *Config) printUserDeprecation(category, name string, plugin interface{}) switch info.Level { case Warn: prefix := "W! " + color.YellowString("DeprecationWarning") - info.printPluginDeprecationNotice(prefix) + printPluginDeprecationNotice(prefix, info.Name, info.info) // We will not check for any deprecated options as the whole plugin is deprecated anyway. return nil case Error: prefix := "E! " + color.RedString("DeprecationError") - info.printPluginDeprecationNotice(prefix) + printPluginDeprecationNotice(prefix, info.Name, info.info) // We are past the grace period return fmt.Errorf("plugin deprecated") } @@ -207,10 +179,10 @@ func (c *Config) printUserDeprecation(category, name string, plugin interface{}) switch option.Level { case Warn: prefix := "W! " + color.YellowString("DeprecationWarning") - option.printOptionDeprecationNotice(prefix, info.Name) + printOptionDeprecationNotice(prefix, info.Name, option.Name, option.info) case Error: prefix := "E! " + color.RedString("DeprecationError") - option.printOptionDeprecationNotice(prefix, info.Name) + printOptionDeprecationNotice(prefix, info.Name, option.Name, option.info) deprecatedOptions = append(deprecatedOptions, option.Name) } } @@ -309,6 +281,28 @@ func (c *Config) PrintDeprecationList(plugins []pluginDeprecationInfo) { } } +func printHistoricPluginDeprecationNotice(category, name string, info telegraf.DeprecationInfo) { + prefix := "E! " + color.RedString("DeprecationError") + log.Printf( + "%s: Plugin %q deprecated since version %s and removed: %s", + prefix, category+"."+name, info.Since, info.Notice, + ) +} + +func printPluginDeprecationNotice(prefix, name string, info telegraf.DeprecationInfo) { + log.Printf( + "%s: Plugin %q deprecated since version %s and will be removed in %s: %s", + prefix, name, info.Since, info.RemovalIn, info.Notice, + ) +} + +func printOptionDeprecationNotice(prefix, plugin, option string, info telegraf.DeprecationInfo) { + log.Printf( + "%s: Option %q of plugin %q deprecated since version %s and will be removed in %s: %s", + prefix, option, plugin, info.Since, info.RemovalIn, info.Notice, + ) +} + // walkPluginStruct iterates over the fields of a structure in depth-first search (to cover nested structures) // and calls the given function for every visited field. func walkPluginStruct(value reflect.Value, fn func(f reflect.StructField, fv reflect.Value)) { diff --git a/plugins/aggregators/deprecations.go b/plugins/aggregators/deprecations.go new file mode 100644 index 0000000000000..8acf5305045a0 --- /dev/null +++ b/plugins/aggregators/deprecations.go @@ -0,0 +1,5 @@ +package aggregators + +import "github.com/influxdata/telegraf" + +var Deprecations = map[string]telegraf.DeprecationInfo{} diff --git a/plugins/processors/deprecations.go b/plugins/processors/deprecations.go new file mode 100644 index 0000000000000..365e829045ab8 --- /dev/null +++ b/plugins/processors/deprecations.go @@ -0,0 +1,5 @@ +package processors + +import "github.com/influxdata/telegraf" + +var Deprecations = map[string]telegraf.DeprecationInfo{} From ef8bfcbc518a4f7d984d717e562375c767ab3a5c Mon Sep 17 00:00:00 2001 From: Sven Rebhan Date: Tue, 9 Nov 2021 20:04:55 +0100 Subject: [PATCH 26/45] Use keyed fields. --- plugins/inputs/deprecations.go | 45 ++++++++++++++++++++++++++------- plugins/outputs/deprecations.go | 5 +++- 2 files changed, 40 insertions(+), 10 deletions(-) diff --git a/plugins/inputs/deprecations.go b/plugins/inputs/deprecations.go index edec5fcf13ac1..3aaddc7f9ef31 100644 --- a/plugins/inputs/deprecations.go +++ b/plugins/inputs/deprecations.go @@ -3,13 +3,40 @@ package inputs import "github.com/influxdata/telegraf" var Deprecations = map[string]telegraf.DeprecationInfo{ - "cassandra": {"1.7", "", "use 'inputs.jolokia2' with the 'cassandra.conf' example configuration instead"}, - "http_listener_v2": {"1.9", "", "has been renamed to 'influxdb_listener', use 'inputs.influxdb_listener' or 'inputs.influxdb_listener_v2' instead"}, - "httpjson": {"1.6", "", "use 'inputs.http' instead"}, - "jolokia": {"1.5", "", "use 'inputs.jolokia2' instead"}, - "kafka_consumer_legacy": {"1.20", "", "use 'inputs.kafka_consumer' instead, NOTE: 'kafka_consumer' only supports Kafka v0.8+"}, - "logparser": {"1.15", "", "use 'inputs.tail' with 'grok' data format instead"}, - "snmp_legacy": {"1.20", "", "use 'inputs.snmp' instead"}, - "tcp_listener": {"1.3", "", "use 'inputs.socket_listener' instead"}, - "udp_listener": {"1.3", "", "use 'inputs.socket_listener' instead"}, + "cassandra": { + Since: "1.7", + Notice: "use 'inputs.jolokia2' with the 'cassandra.conf' example configuration instead", + }, + "http_listener_v2": { + Since: "1.9", + Notice: "has been renamed to 'influxdb_listener', use 'inputs.influxdb_listener' or 'inputs.influxdb_listener_v2' instead", + }, + "httpjson": { + Since: "1.6", + Notice: "use 'inputs.http' instead", + }, + "jolokia": { + Since: "1.5", + Notice: "use 'inputs.jolokia2' instead", + }, + "kafka_consumer_legacy": { + Since: "1.20", + Notice: "use 'inputs.kafka_consumer' instead, NOTE: 'kafka_consumer' only supports Kafka v0.8+", + }, + "logparser": { + Since: "1.15", + Notice: "use 'inputs.tail' with 'grok' data format instead", + }, + "snmp_legacy": { + Since: "1.20", + Notice: "use 'inputs.snmp' instead", + }, + "tcp_listener": { + Since: "1.3", + Notice: "use 'inputs.socket_listener' instead", + }, + "udp_listener": { + Since: "1.3", + Notice: "use 'inputs.socket_listener' instead", + }, } diff --git a/plugins/outputs/deprecations.go b/plugins/outputs/deprecations.go index 900e5ffd1e36b..de09f51fedabc 100644 --- a/plugins/outputs/deprecations.go +++ b/plugins/outputs/deprecations.go @@ -3,5 +3,8 @@ package outputs import "github.com/influxdata/telegraf" var Deprecations = map[string]telegraf.DeprecationInfo{ - "riemann_legacy": {"1.20", "", "use 'outputs.riemann' instead (see https://github.com/influxdata/telegraf/issues/1878)"}, + "riemann_legacy": { + Since: "1.20", + Notice: "use 'outputs.riemann' instead (see https://github.com/influxdata/telegraf/issues/1878)", + }, } From aa5039dd63343d7af84829249754026144b9f747 Mon Sep 17 00:00:00 2001 From: Sven Rebhan Date: Thu, 11 Nov 2021 10:19:38 +0100 Subject: [PATCH 27/45] Allow
HTML elements for Markdown as they are often the only why to enforce a linebreak. --- .markdownlint.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.markdownlint.yml b/.markdownlint.yml index 1344b312f825e..893179487d310 100644 --- a/.markdownlint.yml +++ b/.markdownlint.yml @@ -1,3 +1,6 @@ { - "MD013": false + "MD013": false, + "MD033": { + "allowed_elements": ["br"] + } } From 64e876aca54a8c075989c27312f72c25850f8a83 Mon Sep 17 00:00:00 2001 From: Sven Rebhan Date: Thu, 11 Nov 2021 10:32:01 +0100 Subject: [PATCH 28/45] Add inputs.io to list of deprecated plugins. --- config/config.go | 3 +++ config/deprecation.go | 5 +++++ plugins/inputs/deprecations.go | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/config/config.go b/config/config.go index 7e2cb836adf3f..35e4b4624e131 100644 --- a/config/config.go +++ b/config/config.go @@ -1148,6 +1148,9 @@ func (c *Config) addInput(name string, table *ast.Table) error { // Legacy support renaming io input to diskio if name == "io" { + if err := c.printUserDeprecation("inputs", name, nil); err != nil { + return err + } name = "diskio" } diff --git a/config/deprecation.go b/config/deprecation.go index 8dc691d63de2f..ca1d2d71c8dda 100644 --- a/config/deprecation.go +++ b/config/deprecation.go @@ -120,6 +120,11 @@ func (c *Config) collectDeprecationInfo(category, name string, plugin interface{ c.incrementPluginDeprecations(category) } + // Allow checking for names only. + if plugin == nil { + return info + } + // Check for deprecated options walkPluginStruct(reflect.ValueOf(plugin), func(field reflect.StructField, value reflect.Value) { // Try to report only those fields that are set diff --git a/plugins/inputs/deprecations.go b/plugins/inputs/deprecations.go index 3aaddc7f9ef31..b8b4adfc55fef 100644 --- a/plugins/inputs/deprecations.go +++ b/plugins/inputs/deprecations.go @@ -7,6 +7,10 @@ var Deprecations = map[string]telegraf.DeprecationInfo{ Since: "1.7", Notice: "use 'inputs.jolokia2' with the 'cassandra.conf' example configuration instead", }, + "io": { + Since: "1.20", + Notice: "use 'inputs.diskio' instead", + }, "http_listener_v2": { Since: "1.9", Notice: "has been renamed to 'influxdb_listener', use 'inputs.influxdb_listener' or 'inputs.influxdb_listener_v2' instead", From d51cf51abb8f81c6dfbe02b07d251ea0470ba1c9 Mon Sep 17 00:00:00 2001 From: Sven Rebhan Date: Thu, 11 Nov 2021 10:36:21 +0100 Subject: [PATCH 29/45] Remove color from deprecation output. --- config/deprecation.go | 12 +++++------- go.mod | 2 +- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/config/deprecation.go b/config/deprecation.go index ca1d2d71c8dda..4e9f17b6b31e6 100644 --- a/config/deprecation.go +++ b/config/deprecation.go @@ -8,8 +8,6 @@ import ( "strconv" "strings" - "github.com/fatih/color" - "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/plugins/aggregators" "github.com/influxdata/telegraf/plugins/inputs" @@ -167,12 +165,12 @@ func (c *Config) printUserDeprecation(category, name string, plugin interface{}) switch info.Level { case Warn: - prefix := "W! " + color.YellowString("DeprecationWarning") + prefix := "W! DeprecationWarning" printPluginDeprecationNotice(prefix, info.Name, info.info) // We will not check for any deprecated options as the whole plugin is deprecated anyway. return nil case Error: - prefix := "E! " + color.RedString("DeprecationError") + prefix := "E! DeprecationError" printPluginDeprecationNotice(prefix, info.Name, info.info) // We are past the grace period return fmt.Errorf("plugin deprecated") @@ -183,10 +181,10 @@ func (c *Config) printUserDeprecation(category, name string, plugin interface{}) for _, option := range info.Options { switch option.Level { case Warn: - prefix := "W! " + color.YellowString("DeprecationWarning") + prefix := "W! DeprecationWarning" printOptionDeprecationNotice(prefix, info.Name, option.Name, option.info) case Error: - prefix := "E! " + color.RedString("DeprecationError") + prefix := "E! DeprecationError" printOptionDeprecationNotice(prefix, info.Name, option.Name, option.info) deprecatedOptions = append(deprecatedOptions, option.Name) } @@ -287,7 +285,7 @@ func (c *Config) PrintDeprecationList(plugins []pluginDeprecationInfo) { } func printHistoricPluginDeprecationNotice(category, name string, info telegraf.DeprecationInfo) { - prefix := "E! " + color.RedString("DeprecationError") + prefix := "E! DeprecationError" log.Printf( "%s: Plugin %q deprecated since version %s and removed: %s", prefix, category+"."+name, info.Since, info.Notice, diff --git a/go.mod b/go.mod index b12d45dbb1ab2..75496c6646c71 100644 --- a/go.mod +++ b/go.mod @@ -98,7 +98,7 @@ require ( github.com/eapache/queue v1.1.0 // indirect github.com/echlebek/timeproxy v1.0.0 // indirect github.com/eclipse/paho.mqtt.golang v1.3.0 - github.com/fatih/color v1.10.0 + github.com/fatih/color v1.10.0 // indirect github.com/form3tech-oss/jwt-go v3.2.5+incompatible // indirect github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32 github.com/go-logfmt/logfmt v0.5.0 From 56ce5b02351b991a30510ac7952047616b58d530 Mon Sep 17 00:00:00 2001 From: Sven Rebhan Date: Thu, 11 Nov 2021 10:41:43 +0100 Subject: [PATCH 30/45] Fix Makefile. --- Makefile | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index 2b5864602564a..0e4b21bcb4b3d 100644 --- a/Makefile +++ b/Makefile @@ -150,19 +150,18 @@ lint-install: .PHONY: lint lint: - @which golangci-lint >/dev/null 2>&1 || { \ - echo "golangci-lint not found, please run: make lint-install"; \ - exit 1; \ - } - - golangci-lint run - - @which markdownlint >/dev/null 2>&1 || { \ - echo "markdownlint not found, please run: make lint-install"; \ - exit 1; \ - } - - markdownlint . + ifeq (, $(shell which golangci-lint)) + $(info golangci-lint can't be found, please run: make lint-install) + exit 1 + endif + + golangci-lint run + + 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 lint-branch: From 805cd32d6ebdde4addebc1fd0c6a5b4572d81231 Mon Sep 17 00:00:00 2001 From: Sven Rebhan Date: Thu, 11 Nov 2021 11:04:42 +0100 Subject: [PATCH 31/45] Use go-semver for versioning. --- cmd/telegraf/telegraf.go | 4 +-- config/config.go | 10 ++++++-- config/deprecation.go | 54 ++++++++++++++++------------------------ go.mod | 2 +- 4 files changed, 33 insertions(+), 37 deletions(-) diff --git a/cmd/telegraf/telegraf.go b/cmd/telegraf/telegraf.go index 4dd2b5a1c19f0..cdac666d49519 100644 --- a/cmd/telegraf/telegraf.go +++ b/cmd/telegraf/telegraf.go @@ -197,7 +197,7 @@ func runAgent(ctx context.Context, // If no other options are specified, load the config file and run. c := config.NewConfig() - c.VersionMajor, c.VersionMinor = config.ParseVersion(version) + c.SetVersion(version) c.OutputFilters = outputFilters c.InputFilters = inputFilters var err error @@ -410,7 +410,7 @@ func main() { switch { case *fDeprecationList: c := config.NewConfig() - c.VersionMajor, c.VersionMinor = config.ParseVersion(version) + c.SetVersion(version) infos := c.CollectDeprecationInfos( inputFilters, outputFilters, diff --git a/config/config.go b/config/config.go index 35e4b4624e131..f8f47e7b85b4c 100644 --- a/config/config.go +++ b/config/config.go @@ -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" @@ -78,8 +80,7 @@ type Config struct { Processors models.RunningProcessors AggProcessors models.RunningProcessors - VersionMajor int - VersionMinor int + Version *semver.Version Deprecations map[string][]int64 } @@ -207,6 +208,11 @@ type AgentConfig struct { OmitHostname bool } +// SetVersion stores the telegraf version +func (c *Config) SetVersion(version string) { + c.Version = semver.New(version) +} + // InputNames returns a list of strings of the configured inputs. func (c *Config) InputNames() []string { var name []string diff --git a/config/deprecation.go b/config/deprecation.go index 4e9f17b6b31e6..f38a781a730a7 100644 --- a/config/deprecation.go +++ b/config/deprecation.go @@ -5,9 +5,10 @@ import ( "log" //nolint:revive // log is ok here as the logging facility is not set-up yet "reflect" "sort" - "strconv" "strings" + "github.com/coreos/go-semver/semver" + "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/plugins/aggregators" "github.com/influxdata/telegraf/plugins/inputs" @@ -46,28 +47,35 @@ type deprecationInfo struct { info telegraf.DeprecationInfo } -func (di *deprecationInfo) determineEscalation(major, minor int) { - var removalMajor, removalMinor int - +func (di *deprecationInfo) determineEscalation(version *semver.Version) error { di.Level = None if di.info.Since == "" { - return + return nil + } + + since, err := semver.NewVersion(di.info.Since+".0") + if err != nil { + return fmt.Errorf("cannot parse 'since' version %q: %v", di.info.Since+".0", err) } - sinceMajor, sinceMinor := ParseVersion(di.info.Since) + var removal *semver.Version if di.info.RemovalIn != "" { - removalMajor, removalMinor = ParseVersion(di.info.RemovalIn) + removal, err = semver.NewVersion(di.info.RemovalIn+".0") + if err != nil { + return fmt.Errorf("cannot parse 'removal' version %q: %v", di.info.RemovalIn+".0", err) + } } else { - removalMajor, removalMinor = sinceMajor+1, 0 - di.info.RemovalIn = fmt.Sprintf("%d.%d", removalMajor, removalMinor) + removal = &semver.Version{Major: since.Major, Minor: since.Minor} + removal.BumpMajor() + di.info.RemovalIn = removal.String() } - di.Level = None - if major > removalMajor || (major == removalMajor && minor >= removalMinor) { + if !version.LessThan(*removal) { di.Level = Error - } else if major > sinceMajor || (major == sinceMajor && minor >= sinceMinor) { + } else if !version.LessThan(*since) { di.Level = Warn } + return nil } // pluginDeprecationInfo holds all information about a deprecated plugin or it's options @@ -113,7 +121,7 @@ func (c *Config) collectDeprecationInfo(category, name string, plugin interface{ info.deprecationInfo.info = pi } } - info.determineEscalation(c.VersionMajor, c.VersionMinor) + info.determineEscalation(c.Version) if info.Level != None { c.incrementPluginDeprecations(category) } @@ -143,7 +151,7 @@ func (c *Config) collectDeprecationInfo(category, name string, plugin interface{ if len(tags) > 2 { optionInfo.info.RemovalIn = tags[1] } - optionInfo.determineEscalation(c.VersionMajor, c.VersionMinor) + optionInfo.determineEscalation(c.Version) if optionInfo.Level != None { c.incrementPluginOptionDeprecations(category) @@ -349,21 +357,3 @@ func walkPluginStruct(value reflect.Value, fn func(f reflect.StructField, fv ref fn(field, fieldValue) } } - -func ParseVersion(version string) (major, minor int) { - parts := strings.SplitN(version, ".", 3) - if len(parts) < 2 { - panic(fmt.Errorf("insufficient version fields in %q", version)) - } - - major, err := strconv.Atoi(parts[0]) - if err != nil { - panic(fmt.Errorf("invalid version major in %q", version)) - } - - minor, err = strconv.Atoi(parts[1]) - if err != nil { - panic(fmt.Errorf("invalid version major in %q", version)) - } - return major, minor -} diff --git a/go.mod b/go.mod index 75496c6646c71..a03a24cb6a87b 100644 --- a/go.mod +++ b/go.mod @@ -78,7 +78,7 @@ require ( github.com/cisco-ie/nx-telemetry-proto v0.0.0-20190531143454-82441e232cf6 github.com/containerd/cgroups v1.0.1 // indirect github.com/containerd/containerd v1.5.7 // indirect - github.com/coreos/go-semver v0.3.0 // indirect + github.com/coreos/go-semver v0.3.0 github.com/couchbase/go-couchbase v0.1.0 github.com/couchbase/gomemcached v0.1.3 // indirect github.com/couchbase/goutils v0.1.0 // indirect From 041cc5dad78595c66846d9627649517d9a8519e1 Mon Sep 17 00:00:00 2001 From: Sven Rebhan Date: Thu, 11 Nov 2021 11:25:06 +0100 Subject: [PATCH 32/45] Simplify version handling in telegraf. --- cmd/telegraf/telegraf.go | 17 +++++------------ config/config.go | 12 +++++++----- config/deprecation.go | 8 ++++---- internal/internal.go | 4 ++++ 4 files changed, 20 insertions(+), 21 deletions(-) diff --git a/cmd/telegraf/telegraf.go b/cmd/telegraf/telegraf.go index cdac666d49519..66cdd35315301 100644 --- a/cmd/telegraf/telegraf.go +++ b/cmd/telegraf/telegraf.go @@ -197,7 +197,6 @@ func runAgent(ctx context.Context, // If no other options are specified, load the config file and run. c := config.NewConfig() - c.SetVersion(version) c.OutputFilters = outputFilters c.InputFilters = inputFilters var err error @@ -364,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) @@ -410,7 +414,6 @@ func main() { switch { case *fDeprecationList: c := config.NewConfig() - c.SetVersion(version) infos := c.CollectDeprecationInfos( inputFilters, outputFilters, @@ -473,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, diff --git a/config/config.go b/config/config.go index f8f47e7b85b4c..f5fcada77f8ee 100644 --- a/config/config.go +++ b/config/config.go @@ -110,6 +110,13 @@ func NewConfig() *Config { Deprecations: make(map[string][]int64), } + // Handle unknown version + version := internal.Version() + if version == "" || version == "unknown" { + version = "0.0.0-unknown" + } + c.Version = semver.New(version) + tomlCfg := &toml.Config{ NormFieldName: toml.DefaultConfig.NormFieldName, FieldToKey: toml.DefaultConfig.FieldToKey, @@ -208,11 +215,6 @@ type AgentConfig struct { OmitHostname bool } -// SetVersion stores the telegraf version -func (c *Config) SetVersion(version string) { - c.Version = semver.New(version) -} - // InputNames returns a list of strings of the configured inputs. func (c *Config) InputNames() []string { var name []string diff --git a/config/deprecation.go b/config/deprecation.go index f38a781a730a7..74f5faac2079a 100644 --- a/config/deprecation.go +++ b/config/deprecation.go @@ -53,21 +53,21 @@ func (di *deprecationInfo) determineEscalation(version *semver.Version) error { return nil } - since, err := semver.NewVersion(di.info.Since+".0") + since, err := semver.NewVersion(di.info.Since + ".0") if err != nil { return fmt.Errorf("cannot parse 'since' version %q: %v", di.info.Since+".0", err) } var removal *semver.Version if di.info.RemovalIn != "" { - removal, err = semver.NewVersion(di.info.RemovalIn+".0") + removal, err = semver.NewVersion(di.info.RemovalIn + ".0") if err != nil { return fmt.Errorf("cannot parse 'removal' version %q: %v", di.info.RemovalIn+".0", err) } } else { - removal = &semver.Version{Major: since.Major, Minor: since.Minor} + removal = &semver.Version{Major: since.Major, Minor: since.Minor} removal.BumpMajor() - di.info.RemovalIn = removal.String() + di.info.RemovalIn = strings.TrimSuffix(removal.String(), ".0") } if !version.LessThan(*removal) { diff --git a/internal/internal.go b/internal/internal.go index 4441e9acfbf03..49f92bfcd1265 100644 --- a/internal/internal.go +++ b/internal/internal.go @@ -42,6 +42,10 @@ func SetVersion(v string) error { return ErrorVersionAlreadySet } version = v + if version == "" { + version = "unknown" + } + return nil } From 1dcb0d77b1408dc7ee9eaade6aa48729231f7e77 Mon Sep 17 00:00:00 2001 From: Sven Rebhan Date: Thu, 11 Nov 2021 11:26:59 +0100 Subject: [PATCH 33/45] Make version internal. --- config/config.go | 4 ++-- config/deprecation.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/config/config.go b/config/config.go index f5fcada77f8ee..4121c71687e66 100644 --- a/config/config.go +++ b/config/config.go @@ -80,8 +80,8 @@ type Config struct { Processors models.RunningProcessors AggProcessors models.RunningProcessors - Version *semver.Version Deprecations map[string][]int64 + version *semver.Version } // NewConfig creates a new struct to hold the Telegraf config. @@ -115,7 +115,7 @@ func NewConfig() *Config { if version == "" || version == "unknown" { version = "0.0.0-unknown" } - c.Version = semver.New(version) + c.version = semver.New(version) tomlCfg := &toml.Config{ NormFieldName: toml.DefaultConfig.NormFieldName, diff --git a/config/deprecation.go b/config/deprecation.go index 74f5faac2079a..81f824ec74fe1 100644 --- a/config/deprecation.go +++ b/config/deprecation.go @@ -121,7 +121,7 @@ func (c *Config) collectDeprecationInfo(category, name string, plugin interface{ info.deprecationInfo.info = pi } } - info.determineEscalation(c.Version) + info.determineEscalation(c.version) if info.Level != None { c.incrementPluginDeprecations(category) } @@ -151,7 +151,7 @@ func (c *Config) collectDeprecationInfo(category, name string, plugin interface{ if len(tags) > 2 { optionInfo.info.RemovalIn = tags[1] } - optionInfo.determineEscalation(c.Version) + optionInfo.determineEscalation(c.version) if optionInfo.Level != None { c.incrementPluginOptionDeprecations(category) From 2a2115050661033f7a8034bc8d1653efa98e2740 Mon Sep 17 00:00:00 2001 From: Sven Rebhan Date: Thu, 11 Nov 2021 11:39:33 +0100 Subject: [PATCH 34/45] Fix linter error. --- config/deprecation.go | 9 ++++----- docs/LICENSE_OF_DEPENDENCIES.md | 1 + 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/config/deprecation.go b/config/deprecation.go index 81f824ec74fe1..66524d746d4ef 100644 --- a/config/deprecation.go +++ b/config/deprecation.go @@ -47,22 +47,22 @@ type deprecationInfo struct { info telegraf.DeprecationInfo } -func (di *deprecationInfo) determineEscalation(version *semver.Version) error { +func (di *deprecationInfo) determineEscalation(version *semver.Version) { di.Level = None if di.info.Since == "" { - return nil + return } since, err := semver.NewVersion(di.info.Since + ".0") if err != nil { - return fmt.Errorf("cannot parse 'since' version %q: %v", di.info.Since+".0", err) + panic(fmt.Errorf("cannot parse 'since' version %q: %v", di.info.Since+".0", err)) } var removal *semver.Version if di.info.RemovalIn != "" { removal, err = semver.NewVersion(di.info.RemovalIn + ".0") if err != nil { - return fmt.Errorf("cannot parse 'removal' version %q: %v", di.info.RemovalIn+".0", err) + panic(fmt.Errorf("cannot parse 'removal' version %q: %v", di.info.RemovalIn+".0", err)) } } else { removal = &semver.Version{Major: since.Major, Minor: since.Minor} @@ -75,7 +75,6 @@ func (di *deprecationInfo) determineEscalation(version *semver.Version) error { } else if !version.LessThan(*since) { di.Level = Warn } - return nil } // pluginDeprecationInfo holds all information about a deprecated plugin or it's options diff --git a/docs/LICENSE_OF_DEPENDENCIES.md b/docs/LICENSE_OF_DEPENDENCIES.md index e1caaf320a0f9..24f8760b4a95d 100644 --- a/docs/LICENSE_OF_DEPENDENCIES.md +++ b/docs/LICENSE_OF_DEPENDENCIES.md @@ -64,6 +64,7 @@ following works: - github.com/cespare/xxhash [MIT License](https://github.com/cespare/xxhash/blob/master/LICENSE.txt) - github.com/cisco-ie/nx-telemetry-proto [Apache License 2.0](https://github.com/cisco-ie/nx-telemetry-proto/blob/master/LICENSE) - github.com/containerd/containerd [Apache License 2.0](https://github.com/containerd/containerd/blob/master/LICENSE) +- github.com/coreos/go-semver [Apache License 2.0](https://github.com/coreos/go-semver/blob/main/LICENSE) - github.com/couchbase/go-couchbase [MIT License](https://github.com/couchbase/go-couchbase/blob/master/LICENSE) - github.com/couchbase/gomemcached [MIT License](https://github.com/couchbase/gomemcached/blob/master/LICENSE) - github.com/couchbase/goutils [Apache License 2.0](https://github.com/couchbase/goutils/blob/master/LICENSE.md) From b9bb624bec3e9ebccb2c149f9b0a9c4e7af81501 Mon Sep 17 00:00:00 2001 From: Sven Rebhan Date: Thu, 11 Nov 2021 11:40:47 +0100 Subject: [PATCH 35/45] Improve error message. --- config/deprecation.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/config/deprecation.go b/config/deprecation.go index 66524d746d4ef..24bab51985999 100644 --- a/config/deprecation.go +++ b/config/deprecation.go @@ -53,19 +53,19 @@ func (di *deprecationInfo) determineEscalation(version *semver.Version) { return } - since, err := semver.NewVersion(di.info.Since + ".0") + since, err := semver.NewVersion(di.info.Since+".0") if err != nil { - panic(fmt.Errorf("cannot parse 'since' version %q: %v", di.info.Since+".0", err)) + panic(fmt.Errorf("cannot parse 'since' version %q: %v", di.info.Since, err)) } var removal *semver.Version if di.info.RemovalIn != "" { - removal, err = semver.NewVersion(di.info.RemovalIn + ".0") + removal, err = semver.NewVersion(di.info.RemovalIn+".0") if err != nil { - panic(fmt.Errorf("cannot parse 'removal' version %q: %v", di.info.RemovalIn+".0", err)) + panic(fmt.Errorf("cannot parse 'removal' version %q: %v", di.info.RemovalIn, err)) } } else { - removal = &semver.Version{Major: since.Major, Minor: since.Minor} + removal = &semver.Version{Major: since.Major, Minor: since.Minor} removal.BumpMajor() di.info.RemovalIn = strings.TrimSuffix(removal.String(), ".0") } From 4b1e449eefbc55a8cb6a8c0fec7070e78cc62bd9 Mon Sep 17 00:00:00 2001 From: Sven Rebhan Date: Thu, 11 Nov 2021 11:42:40 +0100 Subject: [PATCH 36/45] Formatting. --- config/deprecation.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/config/deprecation.go b/config/deprecation.go index 24bab51985999..07f460d95d20c 100644 --- a/config/deprecation.go +++ b/config/deprecation.go @@ -53,19 +53,19 @@ func (di *deprecationInfo) determineEscalation(version *semver.Version) { return } - since, err := semver.NewVersion(di.info.Since+".0") + since, err := semver.NewVersion(di.info.Since + ".0") if err != nil { panic(fmt.Errorf("cannot parse 'since' version %q: %v", di.info.Since, err)) } var removal *semver.Version if di.info.RemovalIn != "" { - removal, err = semver.NewVersion(di.info.RemovalIn+".0") + removal, err = semver.NewVersion(di.info.RemovalIn + ".0") if err != nil { panic(fmt.Errorf("cannot parse 'removal' version %q: %v", di.info.RemovalIn, err)) } } else { - removal = &semver.Version{Major: since.Major, Minor: since.Minor} + removal = &semver.Version{Major: since.Major, Minor: since.Minor} removal.BumpMajor() di.info.RemovalIn = strings.TrimSuffix(removal.String(), ".0") } From 57cb42942104d03c30573865c0e68af7c14a12bb Mon Sep 17 00:00:00 2001 From: Sven Rebhan Date: Thu, 11 Nov 2021 12:10:38 +0100 Subject: [PATCH 37/45] Update deprecation information from Changelog. --- plugins/inputs/deprecations.go | 9 +++++---- plugins/outputs/deprecations.go | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/plugins/inputs/deprecations.go b/plugins/inputs/deprecations.go index b8b4adfc55fef..084c206000d52 100644 --- a/plugins/inputs/deprecations.go +++ b/plugins/inputs/deprecations.go @@ -8,8 +8,9 @@ var Deprecations = map[string]telegraf.DeprecationInfo{ Notice: "use 'inputs.jolokia2' with the 'cassandra.conf' example configuration instead", }, "io": { - Since: "1.20", - Notice: "use 'inputs.diskio' instead", + Since: "0.10", + RemovalIn: "2.0", + Notice: "use 'inputs.diskio' instead", }, "http_listener_v2": { Since: "1.9", @@ -24,7 +25,7 @@ var Deprecations = map[string]telegraf.DeprecationInfo{ Notice: "use 'inputs.jolokia2' instead", }, "kafka_consumer_legacy": { - Since: "1.20", + Since: "1.4", Notice: "use 'inputs.kafka_consumer' instead, NOTE: 'kafka_consumer' only supports Kafka v0.8+", }, "logparser": { @@ -32,7 +33,7 @@ var Deprecations = map[string]telegraf.DeprecationInfo{ Notice: "use 'inputs.tail' with 'grok' data format instead", }, "snmp_legacy": { - Since: "1.20", + Since: "1.0", Notice: "use 'inputs.snmp' instead", }, "tcp_listener": { diff --git a/plugins/outputs/deprecations.go b/plugins/outputs/deprecations.go index de09f51fedabc..70b61d6825822 100644 --- a/plugins/outputs/deprecations.go +++ b/plugins/outputs/deprecations.go @@ -4,7 +4,7 @@ import "github.com/influxdata/telegraf" var Deprecations = map[string]telegraf.DeprecationInfo{ "riemann_legacy": { - Since: "1.20", + Since: "1.3", Notice: "use 'outputs.riemann' instead (see https://github.com/influxdata/telegraf/issues/1878)", }, } From 5db8685b199377501c935aec8abd6852118c1ff8 Mon Sep 17 00:00:00 2001 From: Sven Rebhan Date: Thu, 11 Nov 2021 12:15:21 +0100 Subject: [PATCH 38/45] Revert "Remove color from deprecation output." This reverts commit 3b95f310f0e8f99835f9e7555a6fbda25f66a402. --- config/deprecation.go | 11 ++++++----- go.mod | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/config/deprecation.go b/config/deprecation.go index 07f460d95d20c..dd91001e947c5 100644 --- a/config/deprecation.go +++ b/config/deprecation.go @@ -8,6 +8,7 @@ import ( "strings" "github.com/coreos/go-semver/semver" + "github.com/fatih/color" "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/plugins/aggregators" @@ -172,12 +173,12 @@ func (c *Config) printUserDeprecation(category, name string, plugin interface{}) switch info.Level { case Warn: - prefix := "W! DeprecationWarning" + prefix := "W! " + color.YellowString("DeprecationWarning") printPluginDeprecationNotice(prefix, info.Name, info.info) // We will not check for any deprecated options as the whole plugin is deprecated anyway. return nil case Error: - prefix := "E! DeprecationError" + prefix := "E! " + color.RedString("DeprecationError") printPluginDeprecationNotice(prefix, info.Name, info.info) // We are past the grace period return fmt.Errorf("plugin deprecated") @@ -188,10 +189,10 @@ func (c *Config) printUserDeprecation(category, name string, plugin interface{}) for _, option := range info.Options { switch option.Level { case Warn: - prefix := "W! DeprecationWarning" + prefix := "W! " + color.YellowString("DeprecationWarning") printOptionDeprecationNotice(prefix, info.Name, option.Name, option.info) case Error: - prefix := "E! DeprecationError" + prefix := "E! " + color.RedString("DeprecationError") printOptionDeprecationNotice(prefix, info.Name, option.Name, option.info) deprecatedOptions = append(deprecatedOptions, option.Name) } @@ -292,7 +293,7 @@ func (c *Config) PrintDeprecationList(plugins []pluginDeprecationInfo) { } func printHistoricPluginDeprecationNotice(category, name string, info telegraf.DeprecationInfo) { - prefix := "E! DeprecationError" + prefix := "E! " + color.RedString("DeprecationError") log.Printf( "%s: Plugin %q deprecated since version %s and removed: %s", prefix, category+"."+name, info.Since, info.Notice, diff --git a/go.mod b/go.mod index a03a24cb6a87b..1e7ccaeafa75b 100644 --- a/go.mod +++ b/go.mod @@ -98,7 +98,7 @@ require ( github.com/eapache/queue v1.1.0 // indirect github.com/echlebek/timeproxy v1.0.0 // indirect github.com/eclipse/paho.mqtt.golang v1.3.0 - github.com/fatih/color v1.10.0 // indirect + github.com/fatih/color v1.10.0 github.com/form3tech-oss/jwt-go v3.2.5+incompatible // indirect github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32 github.com/go-logfmt/logfmt v0.5.0 From 0a3411889c774fc0f3c33f38473e0dfa8a58ea10 Mon Sep 17 00:00:00 2001 From: Sven Rebhan Date: Tue, 16 Nov 2021 11:34:20 +0100 Subject: [PATCH 39/45] Handle processor and aggregator deprecations as well. --- config/deprecation.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/config/deprecation.go b/config/deprecation.go index dd91001e947c5..74926e727e223 100644 --- a/config/deprecation.go +++ b/config/deprecation.go @@ -112,6 +112,10 @@ func (c *Config) collectDeprecationInfo(category, name string, plugin interface{ // First check if the whole plugin is deprecated switch category { + case "aggregators": + if pi, deprecated := aggregators.Deprecations[name]; deprecated { + info.deprecationInfo.info = pi + } case "inputs": if pi, deprecated := inputs.Deprecations[name]; deprecated { info.deprecationInfo.info = pi @@ -120,6 +124,10 @@ func (c *Config) collectDeprecationInfo(category, name string, plugin interface{ if pi, deprecated := outputs.Deprecations[name]; deprecated { info.deprecationInfo.info = pi } + case "processors": + if pi, deprecated := processors.Deprecations[name]; deprecated { + info.deprecationInfo.info = pi + } } info.determineEscalation(c.version) if info.Level != None { From 253cc5940760aa29863a5afb8b4493f9c26ae9a3 Mon Sep 17 00:00:00 2001 From: Sven Rebhan Date: Tue, 16 Nov 2021 11:36:58 +0100 Subject: [PATCH 40/45] Rename 'Level' to 'LogLevel'. --- config/deprecation.go | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/config/deprecation.go b/config/deprecation.go index 74926e727e223..3d37ffb47999b 100644 --- a/config/deprecation.go +++ b/config/deprecation.go @@ -43,13 +43,13 @@ const ( type deprecationInfo struct { // Name of the plugin or plugin option Name string - // Level of deprecation - Level Escalation - info telegraf.DeprecationInfo + // LogLevel is the level of deprecation which currently corresponds to a log-level + LogLevel Escalation + info telegraf.DeprecationInfo } func (di *deprecationInfo) determineEscalation(version *semver.Version) { - di.Level = None + di.LogLevel = None if di.info.Since == "" { return } @@ -72,9 +72,9 @@ func (di *deprecationInfo) determineEscalation(version *semver.Version) { } if !version.LessThan(*removal) { - di.Level = Error + di.LogLevel = Error } else if !version.LessThan(*since) { - di.Level = Warn + di.LogLevel = Warn } } @@ -105,8 +105,8 @@ func (c *Config) incrementPluginOptionDeprecations(category string) { func (c *Config) collectDeprecationInfo(category, name string, plugin interface{}, all bool) pluginDeprecationInfo { info := pluginDeprecationInfo{ deprecationInfo: deprecationInfo{ - Name: category + "." + name, - Level: None, + Name: category + "." + name, + LogLevel: None, }, } @@ -130,7 +130,7 @@ func (c *Config) collectDeprecationInfo(category, name string, plugin interface{ } } info.determineEscalation(c.version) - if info.Level != None { + if info.LogLevel != None { c.incrementPluginDeprecations(category) } @@ -161,7 +161,7 @@ func (c *Config) collectDeprecationInfo(category, name string, plugin interface{ } optionInfo.determineEscalation(c.version) - if optionInfo.Level != None { + if optionInfo.LogLevel != None { c.incrementPluginOptionDeprecations(category) } @@ -179,7 +179,7 @@ func (c *Config) collectDeprecationInfo(category, name string, plugin interface{ func (c *Config) printUserDeprecation(category, name string, plugin interface{}) error { info := c.collectDeprecationInfo(category, name, plugin, false) - switch info.Level { + switch info.LogLevel { case Warn: prefix := "W! " + color.YellowString("DeprecationWarning") printPluginDeprecationNotice(prefix, info.Name, info.info) @@ -195,7 +195,7 @@ func (c *Config) printUserDeprecation(category, name string, plugin interface{}) // Print deprecated options deprecatedOptions := make([]string, 0) for _, option := range info.Options { - switch option.Level { + switch option.LogLevel { case Warn: prefix := "W! " + color.YellowString("DeprecationWarning") printOptionDeprecationNotice(prefix, info.Name, option.Name, option.info) @@ -225,7 +225,7 @@ func (c *Config) CollectDeprecationInfos(inFilter, outFilter, aggFilter, procFil plugin := creator() info := c.collectDeprecationInfo("inputs", name, plugin, true) - if info.Level != None || len(info.Options) > 0 { + if info.LogLevel != None || len(info.Options) > 0 { infos["inputs"] = append(infos["inputs"], info) } } @@ -239,7 +239,7 @@ func (c *Config) CollectDeprecationInfos(inFilter, outFilter, aggFilter, procFil plugin := creator() info := c.collectDeprecationInfo("outputs", name, plugin, true) - if info.Level != None || len(info.Options) > 0 { + if info.LogLevel != None || len(info.Options) > 0 { infos["outputs"] = append(infos["outputs"], info) } } @@ -253,7 +253,7 @@ func (c *Config) CollectDeprecationInfos(inFilter, outFilter, aggFilter, procFil plugin := creator() info := c.collectDeprecationInfo("processors", name, plugin, true) - if info.Level != None || len(info.Options) > 0 { + if info.LogLevel != None || len(info.Options) > 0 { infos["processors"] = append(infos["processors"], info) } } @@ -267,7 +267,7 @@ func (c *Config) CollectDeprecationInfos(inFilter, outFilter, aggFilter, procFil plugin := creator() info := c.collectDeprecationInfo("aggregators", name, plugin, true) - if info.Level != None || len(info.Options) > 0 { + if info.LogLevel != None || len(info.Options) > 0 { infos["aggregators"] = append(infos["aggregators"], info) } } @@ -279,11 +279,11 @@ func (c *Config) PrintDeprecationList(plugins []pluginDeprecationInfo) { sort.Slice(plugins, func(i, j int) bool { return plugins[i].Name < plugins[j].Name }) for _, plugin := range plugins { - switch plugin.Level { + switch plugin.LogLevel { case Warn, Error: _, _ = fmt.Printf( " %-40s %-5s since %-5s removal in %-5s %s\n", - plugin.Name, plugin.Level, plugin.info.Since, plugin.info.RemovalIn, plugin.info.Notice, + plugin.Name, plugin.LogLevel, plugin.info.Since, plugin.info.RemovalIn, plugin.info.Notice, ) } @@ -294,7 +294,7 @@ func (c *Config) PrintDeprecationList(plugins []pluginDeprecationInfo) { for _, option := range plugin.Options { _, _ = fmt.Printf( " %-40s %-5s since %-5s removal in %-5s %s\n", - plugin.Name+"/"+option.Name, option.Level, option.info.Since, option.info.RemovalIn, option.info.Notice, + plugin.Name+"/"+option.Name, option.LogLevel, option.info.Since, option.info.RemovalIn, option.info.Notice, ) } } From 1a3b87d870f54c572a4ec34ba98a1e1f335b04f2 Mon Sep 17 00:00:00 2001 From: Sven Rebhan Date: Wed, 17 Nov 2021 14:23:41 +0100 Subject: [PATCH 41/45] Make all versions tri-dotted format. --- config/deprecation.go | 8 +++---- plugins/aggregators/deprecations.go | 1 + plugins/inputs/deprecations.go | 23 ++++++++++--------- plugins/inputs/http_response/http_response.go | 2 +- plugins/outputs/deprecations.go | 3 ++- plugins/processors/deprecations.go | 1 + 6 files changed, 21 insertions(+), 17 deletions(-) diff --git a/config/deprecation.go b/config/deprecation.go index 3d37ffb47999b..49d1eb1e68a62 100644 --- a/config/deprecation.go +++ b/config/deprecation.go @@ -54,21 +54,21 @@ func (di *deprecationInfo) determineEscalation(version *semver.Version) { return } - since, err := semver.NewVersion(di.info.Since + ".0") + since, err := semver.NewVersion(di.info.Since) if err != nil { panic(fmt.Errorf("cannot parse 'since' version %q: %v", di.info.Since, err)) } var removal *semver.Version if di.info.RemovalIn != "" { - removal, err = semver.NewVersion(di.info.RemovalIn + ".0") + removal, err = semver.NewVersion(di.info.RemovalIn) if err != nil { panic(fmt.Errorf("cannot parse 'removal' version %q: %v", di.info.RemovalIn, err)) } } else { - removal = &semver.Version{Major: since.Major, Minor: since.Minor} + removal = &semver.Version{Major: since.Major} removal.BumpMajor() - di.info.RemovalIn = strings.TrimSuffix(removal.String(), ".0") + di.info.RemovalIn = removal.String() } if !version.LessThan(*removal) { diff --git a/plugins/aggregators/deprecations.go b/plugins/aggregators/deprecations.go index 8acf5305045a0..dd2302e0255c3 100644 --- a/plugins/aggregators/deprecations.go +++ b/plugins/aggregators/deprecations.go @@ -2,4 +2,5 @@ package aggregators import "github.com/influxdata/telegraf" +// Deprecations lists the deprecated plugins var Deprecations = map[string]telegraf.DeprecationInfo{} diff --git a/plugins/inputs/deprecations.go b/plugins/inputs/deprecations.go index 084c206000d52..14a497baff30a 100644 --- a/plugins/inputs/deprecations.go +++ b/plugins/inputs/deprecations.go @@ -2,46 +2,47 @@ package inputs import "github.com/influxdata/telegraf" +// Deprecations lists the deprecated plugins var Deprecations = map[string]telegraf.DeprecationInfo{ "cassandra": { - Since: "1.7", + Since: "1.7.0", Notice: "use 'inputs.jolokia2' with the 'cassandra.conf' example configuration instead", }, "io": { - Since: "0.10", - RemovalIn: "2.0", + Since: "0.10.0", + RemovalIn: "2.0.0", Notice: "use 'inputs.diskio' instead", }, "http_listener_v2": { - Since: "1.9", + Since: "1.9.0", Notice: "has been renamed to 'influxdb_listener', use 'inputs.influxdb_listener' or 'inputs.influxdb_listener_v2' instead", }, "httpjson": { - Since: "1.6", + Since: "1.6.0", Notice: "use 'inputs.http' instead", }, "jolokia": { - Since: "1.5", + Since: "1.5.0", Notice: "use 'inputs.jolokia2' instead", }, "kafka_consumer_legacy": { - Since: "1.4", + Since: "1.4.0", Notice: "use 'inputs.kafka_consumer' instead, NOTE: 'kafka_consumer' only supports Kafka v0.8+", }, "logparser": { - Since: "1.15", + Since: "1.15.0", Notice: "use 'inputs.tail' with 'grok' data format instead", }, "snmp_legacy": { - Since: "1.0", + Since: "1.0.0", Notice: "use 'inputs.snmp' instead", }, "tcp_listener": { - Since: "1.3", + Since: "1.3.0", Notice: "use 'inputs.socket_listener' instead", }, "udp_listener": { - Since: "1.3", + Since: "1.3.0", Notice: "use 'inputs.socket_listener' instead", }, } diff --git a/plugins/inputs/http_response/http_response.go b/plugins/inputs/http_response/http_response.go index ef5a1f4e85069..f0da6294aa263 100644 --- a/plugins/inputs/http_response/http_response.go +++ b/plugins/inputs/http_response/http_response.go @@ -28,7 +28,7 @@ const ( // HTTPResponse struct type HTTPResponse struct { - Address string `toml:"address" deprecated:"1.12;use 'urls' instead"` + Address string `toml:"address" deprecated:"1.12.0;use 'urls' instead"` URLs []string `toml:"urls"` HTTPProxy string `toml:"http_proxy"` Body string diff --git a/plugins/outputs/deprecations.go b/plugins/outputs/deprecations.go index 70b61d6825822..6c318cdf6bc4b 100644 --- a/plugins/outputs/deprecations.go +++ b/plugins/outputs/deprecations.go @@ -2,9 +2,10 @@ package outputs import "github.com/influxdata/telegraf" +// Deprecations lists the deprecated plugins var Deprecations = map[string]telegraf.DeprecationInfo{ "riemann_legacy": { - Since: "1.3", + Since: "1.3.0", Notice: "use 'outputs.riemann' instead (see https://github.com/influxdata/telegraf/issues/1878)", }, } diff --git a/plugins/processors/deprecations.go b/plugins/processors/deprecations.go index 365e829045ab8..fa344d8cb155e 100644 --- a/plugins/processors/deprecations.go +++ b/plugins/processors/deprecations.go @@ -2,4 +2,5 @@ package processors import "github.com/influxdata/telegraf" +// Deprecations lists the deprecated plugins var Deprecations = map[string]telegraf.DeprecationInfo{} From 18dd40c1d5dd20ae29677f3c232cc928e7a70cc2 Mon Sep 17 00:00:00 2001 From: Sven Rebhan Date: Wed, 17 Nov 2021 14:29:41 +0100 Subject: [PATCH 42/45] Print origin for version panic to ease debugging. --- config/deprecation.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/config/deprecation.go b/config/deprecation.go index 49d1eb1e68a62..51e4a63a9f114 100644 --- a/config/deprecation.go +++ b/config/deprecation.go @@ -48,22 +48,22 @@ type deprecationInfo struct { info telegraf.DeprecationInfo } -func (di *deprecationInfo) determineEscalation(version *semver.Version) { +func (di *deprecationInfo) determineEscalation(version *semver.Version) error { di.LogLevel = None if di.info.Since == "" { - return + return nil } since, err := semver.NewVersion(di.info.Since) if err != nil { - panic(fmt.Errorf("cannot parse 'since' version %q: %v", di.info.Since, err)) + return fmt.Errorf("cannot parse 'since' version %q: %v", di.info.Since, err) } var removal *semver.Version if di.info.RemovalIn != "" { removal, err = semver.NewVersion(di.info.RemovalIn) if err != nil { - panic(fmt.Errorf("cannot parse 'removal' version %q: %v", di.info.RemovalIn, err)) + return fmt.Errorf("cannot parse 'removal' version %q: %v", di.info.RemovalIn, err) } } else { removal = &semver.Version{Major: since.Major} @@ -76,6 +76,7 @@ func (di *deprecationInfo) determineEscalation(version *semver.Version) { } else if !version.LessThan(*since) { di.LogLevel = Warn } + return nil } // pluginDeprecationInfo holds all information about a deprecated plugin or it's options @@ -129,7 +130,9 @@ func (c *Config) collectDeprecationInfo(category, name string, plugin interface{ info.deprecationInfo.info = pi } } - info.determineEscalation(c.version) + if err := info.determineEscalation(c.version); err != nil { + panic(fmt.Errorf("plugin %q: %v", info.Name, err)) + } if info.LogLevel != None { c.incrementPluginDeprecations(category) } @@ -159,7 +162,9 @@ func (c *Config) collectDeprecationInfo(category, name string, plugin interface{ if len(tags) > 2 { optionInfo.info.RemovalIn = tags[1] } - optionInfo.determineEscalation(c.version) + if err := optionInfo.determineEscalation(c.version); err != nil { + panic(fmt.Errorf("plugin %q option %q: %v", info.Name, field.Name, err)) + } if optionInfo.LogLevel != None { c.incrementPluginOptionDeprecations(category) From 7bde16442555553557e2b82dc105bf092aa13269 Mon Sep 17 00:00:00 2001 From: Sven Rebhan Date: Wed, 17 Nov 2021 14:51:53 +0100 Subject: [PATCH 43/45] Switch to 'github.com/blang/semver' as we already have this as a (indirect) dependency. --- config/config.go | 6 +++--- config/deprecation.go | 17 ++++++++--------- docs/LICENSE_OF_DEPENDENCIES.md | 2 +- go.mod | 4 +++- go.sum | 1 + 5 files changed, 16 insertions(+), 14 deletions(-) diff --git a/config/config.go b/config/config.go index 4121c71687e66..396ebf271dec8 100644 --- a/config/config.go +++ b/config/config.go @@ -17,7 +17,7 @@ import ( "strings" "time" - "github.com/coreos/go-semver/semver" + "github.com/blang/semver" "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/internal" @@ -81,7 +81,7 @@ type Config struct { AggProcessors models.RunningProcessors Deprecations map[string][]int64 - version *semver.Version + version semver.Version } // NewConfig creates a new struct to hold the Telegraf config. @@ -115,7 +115,7 @@ func NewConfig() *Config { if version == "" || version == "unknown" { version = "0.0.0-unknown" } - c.version = semver.New(version) + c.version = semver.MustParse(version) tomlCfg := &toml.Config{ NormFieldName: toml.DefaultConfig.NormFieldName, diff --git a/config/deprecation.go b/config/deprecation.go index 51e4a63a9f114..8f99b5d034cf1 100644 --- a/config/deprecation.go +++ b/config/deprecation.go @@ -7,7 +7,7 @@ import ( "sort" "strings" - "github.com/coreos/go-semver/semver" + "github.com/blang/semver" "github.com/fatih/color" "github.com/influxdata/telegraf" @@ -48,32 +48,31 @@ type deprecationInfo struct { info telegraf.DeprecationInfo } -func (di *deprecationInfo) determineEscalation(version *semver.Version) error { +func (di *deprecationInfo) determineEscalation(version semver.Version) error { di.LogLevel = None if di.info.Since == "" { return nil } - since, err := semver.NewVersion(di.info.Since) + since, err := semver.Parse(di.info.Since) if err != nil { return fmt.Errorf("cannot parse 'since' version %q: %v", di.info.Since, err) } - var removal *semver.Version + var removal semver.Version if di.info.RemovalIn != "" { - removal, err = semver.NewVersion(di.info.RemovalIn) + removal, err = semver.Parse(di.info.RemovalIn) if err != nil { return fmt.Errorf("cannot parse 'removal' version %q: %v", di.info.RemovalIn, err) } } else { - removal = &semver.Version{Major: since.Major} - removal.BumpMajor() + removal = semver.Version{Major: since.Major + 1} di.info.RemovalIn = removal.String() } - if !version.LessThan(*removal) { + if version.GTE(removal) { di.LogLevel = Error - } else if !version.LessThan(*since) { + } else if version.GTE(since) { di.LogLevel = Warn } return nil diff --git a/docs/LICENSE_OF_DEPENDENCIES.md b/docs/LICENSE_OF_DEPENDENCIES.md index 24f8760b4a95d..3be61cec7fb9b 100644 --- a/docs/LICENSE_OF_DEPENDENCIES.md +++ b/docs/LICENSE_OF_DEPENDENCIES.md @@ -58,13 +58,13 @@ following works: - github.com/awslabs/kinesis-aggregation/go [Apache License 2.0](https://github.com/awslabs/kinesis-aggregation/blob/master/LICENSE.txt) - github.com/benbjohnson/clock [MIT License](https://github.com/benbjohnson/clock/blob/master/LICENSE) - github.com/beorn7/perks [MIT License](https://github.com/beorn7/perks/blob/master/LICENSE) +- github.com/blang/semver [MIT License](https://github.com/blang/semver/blob/master/LICENSE) - github.com/bmatcuk/doublestar [MIT License](https://github.com/bmatcuk/doublestar/blob/master/LICENSE) - github.com/caio/go-tdigest [MIT License](https://github.com/caio/go-tdigest/blob/master/LICENSE) - github.com/cenkalti/backoff [MIT License](https://github.com/cenkalti/backoff/blob/master/LICENSE) - github.com/cespare/xxhash [MIT License](https://github.com/cespare/xxhash/blob/master/LICENSE.txt) - github.com/cisco-ie/nx-telemetry-proto [Apache License 2.0](https://github.com/cisco-ie/nx-telemetry-proto/blob/master/LICENSE) - github.com/containerd/containerd [Apache License 2.0](https://github.com/containerd/containerd/blob/master/LICENSE) -- github.com/coreos/go-semver [Apache License 2.0](https://github.com/coreos/go-semver/blob/main/LICENSE) - github.com/couchbase/go-couchbase [MIT License](https://github.com/couchbase/go-couchbase/blob/master/LICENSE) - github.com/couchbase/gomemcached [MIT License](https://github.com/couchbase/gomemcached/blob/master/LICENSE) - github.com/couchbase/goutils [Apache License 2.0](https://github.com/couchbase/goutils/blob/master/LICENSE.md) diff --git a/go.mod b/go.mod index 1e7ccaeafa75b..5e307fc910065 100644 --- a/go.mod +++ b/go.mod @@ -78,7 +78,7 @@ require ( github.com/cisco-ie/nx-telemetry-proto v0.0.0-20190531143454-82441e232cf6 github.com/containerd/cgroups v1.0.1 // indirect github.com/containerd/containerd v1.5.7 // indirect - github.com/coreos/go-semver v0.3.0 + github.com/coreos/go-semver v0.3.0 // indirect github.com/couchbase/go-couchbase v0.1.0 github.com/couchbase/gomemcached v0.1.3 // indirect github.com/couchbase/goutils v0.1.0 // indirect @@ -330,6 +330,8 @@ require ( sigs.k8s.io/yaml v1.2.0 // indirect ) +require github.com/blang/semver v3.5.1+incompatible + require github.com/libp2p/go-reuseport v0.1.0 require ( diff --git a/go.sum b/go.sum index 727dc6e6d2611..323ef35feabff 100644 --- a/go.sum +++ b/go.sum @@ -425,6 +425,7 @@ github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJm github.com/bketelsen/crypt v0.0.4/go.mod h1:aI6NrJ0pMGgvZKL1iVgXLnfIFJtfV+bKCoqOes/6LfM= github.com/bkielbasa/cyclop v1.2.0/go.mod h1:qOI0yy6A7dYC4Zgsa72Ppm9kONl0RoIlPbzot9mhmeI= github.com/blang/semver v3.1.0+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk= +github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdnnjpJbkM4JQ= github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk= github.com/bmatcuk/doublestar/v3 v3.0.0 h1:TQtVPlDnAYwcrVNB2JiGuMc++H5qzWZd9PhkNo5WyHI= github.com/bmatcuk/doublestar/v3 v3.0.0/go.mod h1:6PcTVMw80pCY1RVuoqu3V++99uQB3vsSYKPTd8AWA0k= From 28ae44775ccdb1ada3756213b1703c899226fbbe Mon Sep 17 00:00:00 2001 From: Sven Rebhan Date: Wed, 17 Nov 2021 14:55:34 +0100 Subject: [PATCH 44/45] Drop potential pre-release tags for telegraf when comparing the versions. --- config/deprecation.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/config/deprecation.go b/config/deprecation.go index 8f99b5d034cf1..1316b5b6664ab 100644 --- a/config/deprecation.go +++ b/config/deprecation.go @@ -48,7 +48,7 @@ type deprecationInfo struct { info telegraf.DeprecationInfo } -func (di *deprecationInfo) determineEscalation(version semver.Version) error { +func (di *deprecationInfo) determineEscalation(telegrafVersion semver.Version) error { di.LogLevel = None if di.info.Since == "" { return nil @@ -70,6 +70,12 @@ func (di *deprecationInfo) determineEscalation(version semver.Version) error { di.info.RemovalIn = removal.String() } + // Drop potential pre-release tags + version := semver.Version{ + Major: telegrafVersion.Major, + Minor: telegrafVersion.Minor, + Patch: telegrafVersion.Patch, + } if version.GTE(removal) { di.LogLevel = Error } else if version.GTE(since) { From eeb9d7afb6c8c17ba68d04f2a8b3038eb6ca3fa0 Mon Sep 17 00:00:00 2001 From: Sven Rebhan Date: Thu, 18 Nov 2021 14:46:38 +0100 Subject: [PATCH 45/45] Revert "Switch to 'github.com/blang/semver' as we already have this as a (indirect) dependency." This reverts commit 184d745cc59d366971395e8384366043241fda69. --- config/config.go | 6 +++--- config/deprecation.go | 17 +++++++++-------- docs/LICENSE_OF_DEPENDENCIES.md | 2 +- go.mod | 4 +--- go.sum | 1 - 5 files changed, 14 insertions(+), 16 deletions(-) diff --git a/config/config.go b/config/config.go index 396ebf271dec8..4121c71687e66 100644 --- a/config/config.go +++ b/config/config.go @@ -17,7 +17,7 @@ import ( "strings" "time" - "github.com/blang/semver" + "github.com/coreos/go-semver/semver" "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/internal" @@ -81,7 +81,7 @@ type Config struct { AggProcessors models.RunningProcessors Deprecations map[string][]int64 - version semver.Version + version *semver.Version } // NewConfig creates a new struct to hold the Telegraf config. @@ -115,7 +115,7 @@ func NewConfig() *Config { if version == "" || version == "unknown" { version = "0.0.0-unknown" } - c.version = semver.MustParse(version) + c.version = semver.New(version) tomlCfg := &toml.Config{ NormFieldName: toml.DefaultConfig.NormFieldName, diff --git a/config/deprecation.go b/config/deprecation.go index 1316b5b6664ab..ab5d2a0caba46 100644 --- a/config/deprecation.go +++ b/config/deprecation.go @@ -7,7 +7,7 @@ import ( "sort" "strings" - "github.com/blang/semver" + "github.com/coreos/go-semver/semver" "github.com/fatih/color" "github.com/influxdata/telegraf" @@ -48,25 +48,26 @@ type deprecationInfo struct { info telegraf.DeprecationInfo } -func (di *deprecationInfo) determineEscalation(telegrafVersion semver.Version) error { +func (di *deprecationInfo) determineEscalation(telegrafVersion *semver.Version) error { di.LogLevel = None if di.info.Since == "" { return nil } - since, err := semver.Parse(di.info.Since) + since, err := semver.NewVersion(di.info.Since) if err != nil { return fmt.Errorf("cannot parse 'since' version %q: %v", di.info.Since, err) } - var removal semver.Version + var removal *semver.Version if di.info.RemovalIn != "" { - removal, err = semver.Parse(di.info.RemovalIn) + removal, err = semver.NewVersion(di.info.RemovalIn) if err != nil { return fmt.Errorf("cannot parse 'removal' version %q: %v", di.info.RemovalIn, err) } } else { - removal = semver.Version{Major: since.Major + 1} + removal = &semver.Version{Major: since.Major} + removal.BumpMajor() di.info.RemovalIn = removal.String() } @@ -76,9 +77,9 @@ func (di *deprecationInfo) determineEscalation(telegrafVersion semver.Version) e Minor: telegrafVersion.Minor, Patch: telegrafVersion.Patch, } - if version.GTE(removal) { + if !version.LessThan(*removal) { di.LogLevel = Error - } else if version.GTE(since) { + } else if !version.LessThan(*since) { di.LogLevel = Warn } return nil diff --git a/docs/LICENSE_OF_DEPENDENCIES.md b/docs/LICENSE_OF_DEPENDENCIES.md index 3be61cec7fb9b..24f8760b4a95d 100644 --- a/docs/LICENSE_OF_DEPENDENCIES.md +++ b/docs/LICENSE_OF_DEPENDENCIES.md @@ -58,13 +58,13 @@ following works: - github.com/awslabs/kinesis-aggregation/go [Apache License 2.0](https://github.com/awslabs/kinesis-aggregation/blob/master/LICENSE.txt) - github.com/benbjohnson/clock [MIT License](https://github.com/benbjohnson/clock/blob/master/LICENSE) - github.com/beorn7/perks [MIT License](https://github.com/beorn7/perks/blob/master/LICENSE) -- github.com/blang/semver [MIT License](https://github.com/blang/semver/blob/master/LICENSE) - github.com/bmatcuk/doublestar [MIT License](https://github.com/bmatcuk/doublestar/blob/master/LICENSE) - github.com/caio/go-tdigest [MIT License](https://github.com/caio/go-tdigest/blob/master/LICENSE) - github.com/cenkalti/backoff [MIT License](https://github.com/cenkalti/backoff/blob/master/LICENSE) - github.com/cespare/xxhash [MIT License](https://github.com/cespare/xxhash/blob/master/LICENSE.txt) - github.com/cisco-ie/nx-telemetry-proto [Apache License 2.0](https://github.com/cisco-ie/nx-telemetry-proto/blob/master/LICENSE) - github.com/containerd/containerd [Apache License 2.0](https://github.com/containerd/containerd/blob/master/LICENSE) +- github.com/coreos/go-semver [Apache License 2.0](https://github.com/coreos/go-semver/blob/main/LICENSE) - github.com/couchbase/go-couchbase [MIT License](https://github.com/couchbase/go-couchbase/blob/master/LICENSE) - github.com/couchbase/gomemcached [MIT License](https://github.com/couchbase/gomemcached/blob/master/LICENSE) - github.com/couchbase/goutils [Apache License 2.0](https://github.com/couchbase/goutils/blob/master/LICENSE.md) diff --git a/go.mod b/go.mod index 5e307fc910065..1e7ccaeafa75b 100644 --- a/go.mod +++ b/go.mod @@ -78,7 +78,7 @@ require ( github.com/cisco-ie/nx-telemetry-proto v0.0.0-20190531143454-82441e232cf6 github.com/containerd/cgroups v1.0.1 // indirect github.com/containerd/containerd v1.5.7 // indirect - github.com/coreos/go-semver v0.3.0 // indirect + github.com/coreos/go-semver v0.3.0 github.com/couchbase/go-couchbase v0.1.0 github.com/couchbase/gomemcached v0.1.3 // indirect github.com/couchbase/goutils v0.1.0 // indirect @@ -330,8 +330,6 @@ require ( sigs.k8s.io/yaml v1.2.0 // indirect ) -require github.com/blang/semver v3.5.1+incompatible - require github.com/libp2p/go-reuseport v0.1.0 require ( diff --git a/go.sum b/go.sum index 323ef35feabff..727dc6e6d2611 100644 --- a/go.sum +++ b/go.sum @@ -425,7 +425,6 @@ github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJm github.com/bketelsen/crypt v0.0.4/go.mod h1:aI6NrJ0pMGgvZKL1iVgXLnfIFJtfV+bKCoqOes/6LfM= github.com/bkielbasa/cyclop v1.2.0/go.mod h1:qOI0yy6A7dYC4Zgsa72Ppm9kONl0RoIlPbzot9mhmeI= github.com/blang/semver v3.1.0+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk= -github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdnnjpJbkM4JQ= github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk= github.com/bmatcuk/doublestar/v3 v3.0.0 h1:TQtVPlDnAYwcrVNB2JiGuMc++H5qzWZd9PhkNo5WyHI= github.com/bmatcuk/doublestar/v3 v3.0.0/go.mod h1:6PcTVMw80pCY1RVuoqu3V++99uQB3vsSYKPTd8AWA0k=