Skip to content

Commit cfc4040

Browse files
committed
Return error how BeatV2Manager prefers
1 parent 1a2d24b commit cfc4040

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

internal/beatcmd/reloader.go

+25-3
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ import (
2323
"fmt"
2424
"sync"
2525

26+
"github.com/joeshaw/multierror"
2627
"golang.org/x/sync/errgroup"
2728

2829
"github.com/elastic/beats/v7/libbeat/beat"
30+
"github.com/elastic/beats/v7/libbeat/cfgfile"
2931
"github.com/elastic/beats/v7/libbeat/common/reload"
3032
"github.com/elastic/elastic-agent-libs/config"
3133
"github.com/elastic/elastic-agent-libs/logp"
@@ -109,11 +111,21 @@ func (r *Reloader) Run(ctx context.Context) error {
109111
}
110112

111113
// reloadInput (re)loads input configuration.
114+
// It returns a *multierror.MultiError as libbeat manager error handling is tightly coupled
115+
// with its own reloadable list implementation in libbeat/cfgfile/list.go.
112116
//
113117
// Note: reloadInputs may be called before the Reloader is running.
114118
func (r *Reloader) reloadInputs(configs []*reload.ConfigWithMeta) error {
115119
if n := len(configs); n != 1 {
116-
return fmt.Errorf("only 1 input supported, got %d", n)
120+
var errs multierror.Errors
121+
for _, cfg := range configs {
122+
unitErr := cfgfile.UnitError{
123+
Err: fmt.Errorf("only 1 input supported, got %d", n),
124+
UnitID: cfg.InputUnitID,
125+
}
126+
errs = append(errs, unitErr)
127+
}
128+
return errs.Err()
117129
}
118130
r.mu.Lock()
119131
defer r.mu.Unlock()
@@ -123,11 +135,21 @@ func (r *Reloader) reloadInputs(configs []*reload.ConfigWithMeta) error {
123135
// increasing revision number.
124136
revision, err := cfg.Int("revision", -1)
125137
if err != nil {
126-
return fmt.Errorf("failed to extract input config revision: %w", err)
138+
return multierror.Errors{
139+
cfgfile.UnitError{
140+
Err: fmt.Errorf("failed to extract input config revision: %w", err),
141+
UnitID: configs[0].InputUnitID,
142+
},
143+
}.Err()
127144
}
128145

129146
if err := r.reload(cfg, r.outputConfig, r.apmTracingConfig); err != nil {
130-
return fmt.Errorf("failed to load input config: %w", err)
147+
return multierror.Errors{
148+
cfgfile.UnitError{
149+
Err: fmt.Errorf("failed to load input config: %w", err),
150+
UnitID: configs[0].InputUnitID,
151+
},
152+
}.Err()
131153
}
132154
r.inputConfig = cfg
133155
r.logger.With(logp.Int64("revision", revision)).Info("loaded input config")

0 commit comments

Comments
 (0)