@@ -11,45 +11,24 @@ import (
1111 "github.com/fatih/color"
1212
1313 "github.com/influxdata/telegraf"
14+ "github.com/influxdata/telegraf/models"
1415 "github.com/influxdata/telegraf/plugins/aggregators"
1516 "github.com/influxdata/telegraf/plugins/inputs"
1617 "github.com/influxdata/telegraf/plugins/outputs"
1718 "github.com/influxdata/telegraf/plugins/processors"
1819)
1920
20- // Escalation level for the plugin or option
21- type Escalation int
22-
23- func (e Escalation ) String () string {
24- switch e {
25- case Warn :
26- return "WARN"
27- case Error :
28- return "ERROR"
29- }
30- return "NONE"
31- }
32-
33- const (
34- // None means no deprecation
35- None Escalation = iota
36- // Warn means deprecated but still within the grace period
37- Warn
38- // Error means deprecated and beyond grace period
39- Error
40- )
41-
4221// deprecationInfo contains all important information to describe a deprecated entity
4322type deprecationInfo struct {
4423 // Name of the plugin or plugin option
4524 Name string
4625 // LogLevel is the level of deprecation which currently corresponds to a log-level
47- LogLevel Escalation
26+ LogLevel telegraf. Escalation
4827 info telegraf.DeprecationInfo
4928}
5029
5130func (di * deprecationInfo ) determineEscalation (telegrafVersion * semver.Version ) error {
52- di .LogLevel = None
31+ di .LogLevel = telegraf . None
5332 if di .info .Since == "" {
5433 return nil
5534 }
@@ -78,9 +57,9 @@ func (di *deprecationInfo) determineEscalation(telegrafVersion *semver.Version)
7857 Patch : telegrafVersion .Patch ,
7958 }
8059 if ! version .LessThan (* removal ) {
81- di .LogLevel = Error
60+ di .LogLevel = telegraf . Error
8261 } else if ! version .LessThan (* since ) {
83- di .LogLevel = Warn
62+ di .LogLevel = telegraf . Warn
8463 }
8564 return nil
8665}
@@ -113,7 +92,7 @@ func (c *Config) collectDeprecationInfo(category, name string, plugin interface{
11392 info := pluginDeprecationInfo {
11493 deprecationInfo : deprecationInfo {
11594 Name : category + "." + name ,
116- LogLevel : None ,
95+ LogLevel : telegraf . None ,
11796 },
11897 }
11998
@@ -139,7 +118,7 @@ func (c *Config) collectDeprecationInfo(category, name string, plugin interface{
139118 if err := info .determineEscalation (c .version ); err != nil {
140119 panic (fmt .Errorf ("plugin %q: %v" , info .Name , err ))
141120 }
142- if info .LogLevel != None {
121+ if info .LogLevel != telegraf . None {
143122 c .incrementPluginDeprecations (category )
144123 }
145124
@@ -172,7 +151,7 @@ func (c *Config) collectDeprecationInfo(category, name string, plugin interface{
172151 panic (fmt .Errorf ("plugin %q option %q: %v" , info .Name , field .Name , err ))
173152 }
174153
175- if optionInfo .LogLevel != None {
154+ if optionInfo .LogLevel != telegraf . None {
176155 c .incrementPluginOptionDeprecations (category )
177156 }
178157
@@ -189,30 +168,17 @@ func (c *Config) collectDeprecationInfo(category, name string, plugin interface{
189168
190169func (c * Config ) printUserDeprecation (category , name string , plugin interface {}) error {
191170 info := c .collectDeprecationInfo (category , name , plugin , false )
171+ models .PrintPluginDeprecationNotice (info .LogLevel , info .Name , info .info )
192172
193- switch info .LogLevel {
194- case Warn :
195- prefix := "W! " + color .YellowString ("DeprecationWarning" )
196- printPluginDeprecationNotice (prefix , info .Name , info .info )
197- // We will not check for any deprecated options as the whole plugin is deprecated anyway.
198- return nil
199- case Error :
200- prefix := "E! " + color .RedString ("DeprecationError" )
201- printPluginDeprecationNotice (prefix , info .Name , info .info )
202- // We are past the grace period
173+ if info .LogLevel == telegraf .Error {
203174 return fmt .Errorf ("plugin deprecated" )
204175 }
205176
206177 // Print deprecated options
207178 deprecatedOptions := make ([]string , 0 )
208179 for _ , option := range info .Options {
209- switch option .LogLevel {
210- case Warn :
211- prefix := "W! " + color .YellowString ("DeprecationWarning" )
212- printOptionDeprecationNotice (prefix , info .Name , option .Name , option .info )
213- case Error :
214- prefix := "E! " + color .RedString ("DeprecationError" )
215- printOptionDeprecationNotice (prefix , info .Name , option .Name , option .info )
180+ models .PrintOptionDeprecationNotice (option .LogLevel , info .Name , option .Name , option .info )
181+ if option .LogLevel == telegraf .Error {
216182 deprecatedOptions = append (deprecatedOptions , option .Name )
217183 }
218184 }
@@ -236,7 +202,7 @@ func (c *Config) CollectDeprecationInfos(inFilter, outFilter, aggFilter, procFil
236202 plugin := creator ()
237203 info := c .collectDeprecationInfo ("inputs" , name , plugin , true )
238204
239- if info .LogLevel != None || len (info .Options ) > 0 {
205+ if info .LogLevel != telegraf . None || len (info .Options ) > 0 {
240206 infos ["inputs" ] = append (infos ["inputs" ], info )
241207 }
242208 }
@@ -250,7 +216,7 @@ func (c *Config) CollectDeprecationInfos(inFilter, outFilter, aggFilter, procFil
250216 plugin := creator ()
251217 info := c .collectDeprecationInfo ("outputs" , name , plugin , true )
252218
253- if info .LogLevel != None || len (info .Options ) > 0 {
219+ if info .LogLevel != telegraf . None || len (info .Options ) > 0 {
254220 infos ["outputs" ] = append (infos ["outputs" ], info )
255221 }
256222 }
@@ -264,7 +230,7 @@ func (c *Config) CollectDeprecationInfos(inFilter, outFilter, aggFilter, procFil
264230 plugin := creator ()
265231 info := c .collectDeprecationInfo ("processors" , name , plugin , true )
266232
267- if info .LogLevel != None || len (info .Options ) > 0 {
233+ if info .LogLevel != telegraf . None || len (info .Options ) > 0 {
268234 infos ["processors" ] = append (infos ["processors" ], info )
269235 }
270236 }
@@ -278,7 +244,7 @@ func (c *Config) CollectDeprecationInfos(inFilter, outFilter, aggFilter, procFil
278244 plugin := creator ()
279245 info := c .collectDeprecationInfo ("aggregators" , name , plugin , true )
280246
281- if info .LogLevel != None || len (info .Options ) > 0 {
247+ if info .LogLevel != telegraf . None || len (info .Options ) > 0 {
282248 infos ["aggregators" ] = append (infos ["aggregators" ], info )
283249 }
284250 }
@@ -291,7 +257,7 @@ func (c *Config) PrintDeprecationList(plugins []pluginDeprecationInfo) {
291257
292258 for _ , plugin := range plugins {
293259 switch plugin .LogLevel {
294- case Warn , Error :
260+ case telegraf . Warn , telegraf . Error :
295261 _ , _ = fmt .Printf (
296262 " %-40s %-5s since %-5s removal in %-5s %s\n " ,
297263 plugin .Name , plugin .LogLevel , plugin .info .Since , plugin .info .RemovalIn , plugin .info .Notice ,
@@ -319,20 +285,6 @@ func printHistoricPluginDeprecationNotice(category, name string, info telegraf.D
319285 )
320286}
321287
322- func printPluginDeprecationNotice (prefix , name string , info telegraf.DeprecationInfo ) {
323- log .Printf (
324- "%s: Plugin %q deprecated since version %s and will be removed in %s: %s" ,
325- prefix , name , info .Since , info .RemovalIn , info .Notice ,
326- )
327- }
328-
329- func printOptionDeprecationNotice (prefix , plugin , option string , info telegraf.DeprecationInfo ) {
330- log .Printf (
331- "%s: Option %q of plugin %q deprecated since version %s and will be removed in %s: %s" ,
332- prefix , option , plugin , info .Since , info .RemovalIn , info .Notice ,
333- )
334- }
335-
336288// walkPluginStruct iterates over the fields of a structure in depth-first search (to cover nested structures)
337289// and calls the given function for every visited field.
338290func walkPluginStruct (value reflect.Value , fn func (f reflect.StructField , fv reflect.Value )) {
0 commit comments