Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

feat: Implement deprecation infrastructure #10200

Merged
merged 45 commits into from
Dec 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
0d8717c
Make version available in config.
Oct 4, 2021
8c52cee
Define interface for declaring a plugin as deprecated.
Oct 4, 2021
abae081
Define telegraf version for the non-tagged case.
Oct 4, 2021
aa4790e
Implement deprecation handling.
Oct 4, 2021
f776ddf
Handle deprecation.
Oct 4, 2021
7c6e654
Deprecate httpjson as a showcase.
Oct 4, 2021
09cbfa3
Deprecate 'address' option of http_response as showcase.
Oct 4, 2021
8d23064
Color deprecation output to increase visibility.
Oct 4, 2021
ceb67fd
Report only those deprecated fields that contain data.
Oct 4, 2021
19c9cd8
Flag known deprecated packages.
Oct 4, 2021
c0678ac
Refactor deprecation handling a bit and implement deprecation listing.
Oct 4, 2021
03da755
Allow listing of deprecated plugins and options via telegraf cmd.
Oct 4, 2021
9c4c1cd
Restore the old config.NewConfig().
Oct 4, 2021
f6d5db3
Fix linter issues.
Oct 4, 2021
0792b91
Make tidy.
Oct 5, 2021
4e6e293
Add comment to walkPluginStruct().
Oct 5, 2021
b83dc36
Pimp walkPluginStruct() to also walk structs embedded in slices/array…
Oct 5, 2021
75ee66d
Print deprecation statistics which is also included in a log-file if …
Oct 13, 2021
246a650
Enable plugin filtering for deprecation list.
Oct 13, 2021
1d09c2e
Add new command-line flag to documentation.
Oct 14, 2021
86e559b
Fix doc alignment.
Oct 15, 2021
43079ae
Fix linter error.
Oct 15, 2021
529557d
Implement discussed deprecation strategy and allow to specify a custo…
Nov 9, 2021
7157598
Move deprecation info to long-term persistant tables.
Nov 9, 2021
3374eae
Print deprecation notice for deprecated and already removed plugins.
Nov 9, 2021
ef8bfcb
Use keyed fields.
Nov 9, 2021
aa5039d
Allow <br> HTML elements for Markdown as they are often the only why …
Nov 11, 2021
64e876a
Add inputs.io to list of deprecated plugins.
Nov 11, 2021
d51cf51
Remove color from deprecation output.
Nov 11, 2021
56ce5b0
Fix Makefile.
Nov 11, 2021
805cd32
Use go-semver for versioning.
Nov 11, 2021
041cc5d
Simplify version handling in telegraf.
Nov 11, 2021
1dcb0d7
Make version internal.
Nov 11, 2021
2a21150
Fix linter error.
Nov 11, 2021
b9bb624
Improve error message.
Nov 11, 2021
4b1e449
Formatting.
Nov 11, 2021
57cb429
Update deprecation information from Changelog.
Nov 11, 2021
5db8685
Revert "Remove color from deprecation output."
Nov 11, 2021
0a34118
Handle processor and aggregator deprecations as well.
Nov 16, 2021
253cc59
Rename 'Level' to 'LogLevel'.
Nov 16, 2021
1a3b87d
Make all versions tri-dotted format.
Nov 17, 2021
18dd40c
Print origin for version panic to ease debugging.
Nov 17, 2021
7bde164
Switch to 'github.com/blang/semver' as we already have this as a (ind…
Nov 17, 2021
28ae447
Drop potential pre-release tags for telegraf when comparing the versi…
Nov 17, 2021
eeb9d7a
Revert "Switch to 'github.com/blang/semver' as we already have this a…
Nov 18, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .markdownlint.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"MD013": false
"MD013": false,
"MD033": {
"allowed_elements": ["br"]
}
}
27 changes: 14 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ HOSTGO := env -u GOOS -u GOARCH -u GOARM -- go
LDFLAGS := $(LDFLAGS) -X main.commit=$(commit) -X main.branch=$(branch) -X main.goos=$(GOOS) -X main.goarch=$(GOARCH)
ifneq ($(tag),)
LDFLAGS += -X main.version=$(version)
else
LDFLAGS += -X main.version=$(version)-$(commit)
endif

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

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

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

logger.SetupLogging(logger.LogConfig{})

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

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

// switch for flags which just do something and exit immediately
switch {
case *fDeprecationList:
c := config.NewConfig()
infos := c.CollectDeprecationInfos(
inputFilters,
outputFilters,
aggregatorFilters,
processorFilters,
)
//nolint:revive // We will notice if Println fails
fmt.Println("Deprecated Input Plugins: ")
Comment on lines +423 to +424
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@reimda @srebhan I know its a little late, but just came to this nolint tag. Is there a reason we can't use this?

Suggested change
//nolint:revive // We will notice if Println fails
fmt.Println("Deprecated Input Plugins: ")
_, _ = fmt.Println("Deprecated Input Plugins: ")

c.PrintDeprecationList(infos["inputs"])
//nolint:revive // We will notice if Println fails
fmt.Println("Deprecated Output Plugins: ")
c.PrintDeprecationList(infos["outputs"])
//nolint:revive // We will notice if Println fails
fmt.Println("Deprecated Processor Plugins: ")
c.PrintDeprecationList(infos["processors"])
//nolint:revive // We will notice if Println fails
fmt.Println("Deprecated Aggregator Plugins: ")
c.PrintDeprecationList(infos["aggregators"])
return
case *fOutputList:
fmt.Println("Available Output Plugins: ")
names := make([]string, 0, len(outputs.Outputs))
Expand Down Expand Up @@ -435,16 +476,6 @@ func main() {
return
}

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

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

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

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

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

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

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

// Handle unknown version
version := internal.Version()
if version == "" || version == "unknown" {
version = "0.0.0-unknown"
}
c.version = semver.New(version)

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

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

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

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

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

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

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

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

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

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

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

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

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

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