Add call to optional Init function for all plugins (#5899)
This commit is contained in:
@@ -39,8 +39,14 @@ func (a *Agent) Run(ctx context.Context) error {
|
||||
return ctx.Err()
|
||||
}
|
||||
|
||||
log.Printf("D! [agent] Initializing plugins")
|
||||
err := a.initPlugins()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
log.Printf("D! [agent] Connecting outputs")
|
||||
err := a.connectOutputs(ctx)
|
||||
err = a.connectOutputs(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -185,6 +191,11 @@ func (a *Agent) Test(ctx context.Context, waitDuration time.Duration) error {
|
||||
}
|
||||
|
||||
for _, input := range a.Config.Inputs {
|
||||
err := input.Init()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return nil
|
||||
@@ -596,6 +607,39 @@ func (a *Agent) flushOnce(
|
||||
|
||||
}
|
||||
|
||||
// initPlugins runs the Init function on plugins.
|
||||
func (a *Agent) initPlugins() error {
|
||||
for _, input := range a.Config.Inputs {
|
||||
err := input.Init()
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not initialize input %s: %v",
|
||||
input.Config.Name, err)
|
||||
}
|
||||
}
|
||||
for _, processor := range a.Config.Processors {
|
||||
err := processor.Init()
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not initialize processor %s: %v",
|
||||
processor.Config.Name, err)
|
||||
}
|
||||
}
|
||||
for _, aggregator := range a.Config.Aggregators {
|
||||
err := aggregator.Init()
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not initialize aggregator %s: %v",
|
||||
aggregator.Config.Name, err)
|
||||
}
|
||||
}
|
||||
for _, output := range a.Config.Outputs {
|
||||
err := output.Init()
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not initialize output %s: %v",
|
||||
output.Config.Name, err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// connectOutputs connects to all outputs.
|
||||
func (a *Agent) connectOutputs(ctx context.Context) error {
|
||||
for _, output := range a.Config.Outputs {
|
||||
|
||||
Reference in New Issue
Block a user