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

fix: Print loaded plugins and deprecations for once and test #10205

Merged
merged 5 commits into from
Dec 7, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions cmd/telegraf/telegraf.go
Original file line number Diff line number Diff line change
@@ -15,6 +15,8 @@ import (
"syscall"
"time"

"github.com/fatih/color"

"github.com/influxdata/tail/watch"
"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/agent"
@@ -256,20 +258,14 @@ func runAgent(ctx context.Context,

logger.SetupLogging(logConfig)

if *fRunOnce {
wait := time.Duration(*fTestWait) * time.Second
return ag.Once(ctx, wait)
}

if *fTest || *fTestWait != 0 {
wait := time.Duration(*fTestWait) * time.Second
return ag.Test(ctx, wait)
}

log.Printf("I! Loaded inputs: %s", strings.Join(c.InputNames(), " "))
powersj marked this conversation as resolved.
Show resolved Hide resolved
log.Printf("I! Loaded aggregators: %s", strings.Join(c.AggregatorNames(), " "))
log.Printf("I! Loaded processors: %s", strings.Join(c.ProcessorNames(), " "))
log.Printf("I! Loaded outputs: %s", strings.Join(c.OutputNames(), " "))
if !*fRunOnce && (*fTest || *fTestWait != 0) {
log.Print(color.RedString("W! Outputs are not used in testing mode!"))
} else {
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) {
@@ -285,6 +281,16 @@ func runAgent(ctx context.Context,
log.Printf("W! Deprecated outputs: %d and %d options", count[0], count[1])
}

if *fRunOnce {
wait := time.Duration(*fTestWait) * time.Second
return ag.Once(ctx, wait)
}

if *fTest || *fTestWait != 0 {
wait := time.Duration(*fTestWait) * time.Second
return ag.Test(ctx, wait)
}

if *fPidfile != "" {
f, err := os.OpenFile(*fPidfile, os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
4 changes: 2 additions & 2 deletions docs/COMMANDS_AND_FLAGS.md
Original file line number Diff line number Diff line change
@@ -36,8 +36,8 @@ telegraf [flags]
|`--section-filter` |filter config sections to output, separator is `:`. Valid values are `agent`, `global_tags`, `outputs`, `processors`, `aggregators` and `inputs`|
|`--sample-config` |print out full sample configuration|
|`--once` |enable once mode: gather metrics once, write them, and exit|
|`--test` |enable test mode: gather metrics once and print them|
|`--test-wait` |wait up to this many seconds for service inputs to complete in test or once mode|
|`--test` |enable test mode: gather metrics once and print them. **No outputs are executed!**|
|`--test-wait` |wait up to this many seconds for service inputs to complete in test or once mode. **Implies `--test` if not used with `--once`**|
|`--usage <plugin>` |print usage for a plugin, ie, `telegraf --usage mysql`|
|`--version` |display the version and exit|

7 changes: 4 additions & 3 deletions internal/usage.go
Original file line number Diff line number Diff line change
@@ -38,9 +38,10 @@ The commands & flags are:
'processors', 'aggregators' and 'inputs'
--sample-config print out full sample configuration
--once enable once mode: gather metrics once, write them, and exit
--test enable test mode: gather metrics once and print them
--test-wait wait up to this many seconds for service
inputs to complete in test or once mode
--test enable test mode: gather metrics once and print them.
No outputs are executed!
--test-wait wait up to this many seconds for service inputs to complete
in test or once mode. Implies --test if not used with --once.
--usage <plugin> print usage for a plugin, ie, 'telegraf --usage mysql'
--version display the version and exit