Skip to content

Commit

Permalink
fix(agent): Reload config on config update (#12721)
Browse files Browse the repository at this point in the history
(cherry picked from commit 95877a5)
  • Loading branch information
powersj committed Feb 27, 2023
1 parent 2920c16 commit f4620ab
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions cmd/telegraf/telegraf.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ func (t *Telegraf) GetSecretStore(id string) (telegraf.SecretStore, error) {
}

func (t *Telegraf) reloadLoop() error {
reloadConfig := false
cfg, err := t.loadConfiguration()
if err != nil {
return err
Expand Down Expand Up @@ -151,10 +152,11 @@ func (t *Telegraf) reloadLoop() error {
}
}()

err = t.runAgent(ctx, cfg)
err := t.runAgent(ctx, cfg, reloadConfig)
if err != nil && !errors.Is(err, context.Canceled) {
return fmt.Errorf("[telegraf] Error running agent: %w", err)
}
reloadConfig = true
}

return nil
Expand Down Expand Up @@ -230,7 +232,14 @@ func (t *Telegraf) loadConfiguration() (*config.Config, error) {
return c, nil
}

func (t *Telegraf) runAgent(ctx context.Context, c *config.Config) error {
func (t *Telegraf) runAgent(ctx context.Context, c *config.Config, reloadConfig bool) error {
var err error
if reloadConfig {
if c, err = t.loadConfiguration(); err != nil {
return err
}
}

if !(t.test || t.testWait != 0) && len(c.Outputs) == 0 {
return errors.New("no outputs found, did you provide a valid config file?")
}
Expand Down

0 comments on commit f4620ab

Please sign in to comment.