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

added an option to skip failed outputs in agent startup #10111

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
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
20 changes: 13 additions & 7 deletions agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func (a *Agent) Run(ctx context.Context) error {
startTime := time.Now()

log.Printf("D! [agent] Connecting outputs")
next, ou, err := a.startOutputs(ctx, a.Config.Outputs)
next, ou, err := a.startOutputs(ctx, a.Config.Outputs, a.Config.Agent.SkipFailedOutputs)
if err != nil {
return err
}
Expand Down Expand Up @@ -674,19 +674,25 @@ func (a *Agent) push(
func (a *Agent) startOutputs(
ctx context.Context,
outputs []*models.RunningOutput,
skipFailedOutputs bool,
) (chan<- telegraf.Metric, *outputUnit, error) {
src := make(chan telegraf.Metric, 100)
unit := &outputUnit{src: src}
for _, output := range outputs {
err := a.connectOutput(ctx, output)
if err != nil {
for _, output := range unit.outputs {
output.Close()
if !skipFailedOutputs {
for _, output := range unit.outputs {
output.Close()
}
return nil, nil, fmt.Errorf("connecting output %s: %w", output.LogName(), err)
}
return nil, nil, fmt.Errorf("connecting output %s: %w", output.LogName(), err)
} else {
unit.outputs = append(unit.outputs, output)
}

unit.outputs = append(unit.outputs, output)
}
if skipFailedOutputs && (unit.outputs == nil || len(unit.outputs) == 0) {
return nil, nil, fmt.Errorf("all outputs failed to start")
}

return src, unit, nil
Expand Down Expand Up @@ -984,7 +990,7 @@ func (a *Agent) once(ctx context.Context, wait time.Duration) error {
startTime := time.Now()

log.Printf("D! [agent] Connecting outputs")
next, ou, err := a.startOutputs(ctx, a.Config.Outputs)
next, ou, err := a.startOutputs(ctx, a.Config.Outputs, a.Config.Agent.SkipFailedOutputs)
if err != nil {
return err
}
Expand Down
3 changes: 3 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ type AgentConfig struct {

Hostname string
OmitHostname bool

// Allows running the agents even if some outputs fail
SkipFailedOutputs bool `toml:"skip_failed_outputs"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Please also update related agentConfig with example configuration.

Copy link
Contributor

Choose a reason for hiding this comment

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

As well as the etc/telegraf.conf and etc/telegraf_windows.conf

}

// InputNames returns a list of strings of the configured inputs.
Expand Down
3 changes: 3 additions & 0 deletions docs/CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@ The agent table configures Telegraf and the defaults used across all plugins.
- **omit_hostname**:
If set to true, do no set the "host" tag in the telegraf agent.

- **skip_failed_outputs**:
If set to true, skips failed outputs and starts the agent

### Plugins

Telegraf plugins are divided into 4 types: [inputs][], [outputs][],
Expand Down