@@ -23,9 +23,11 @@ import (
23
23
"fmt"
24
24
"sync"
25
25
26
+ "github.com/joeshaw/multierror"
26
27
"golang.org/x/sync/errgroup"
27
28
28
29
"github.com/elastic/beats/v7/libbeat/beat"
30
+ "github.com/elastic/beats/v7/libbeat/cfgfile"
29
31
"github.com/elastic/beats/v7/libbeat/common/reload"
30
32
"github.com/elastic/elastic-agent-libs/config"
31
33
"github.com/elastic/elastic-agent-libs/logp"
@@ -109,11 +111,21 @@ func (r *Reloader) Run(ctx context.Context) error {
109
111
}
110
112
111
113
// 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.
112
116
//
113
117
// Note: reloadInputs may be called before the Reloader is running.
114
118
func (r * Reloader ) reloadInputs (configs []* reload.ConfigWithMeta ) error {
115
119
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 ()
117
129
}
118
130
r .mu .Lock ()
119
131
defer r .mu .Unlock ()
@@ -123,11 +135,21 @@ func (r *Reloader) reloadInputs(configs []*reload.ConfigWithMeta) error {
123
135
// increasing revision number.
124
136
revision , err := cfg .Int ("revision" , - 1 )
125
137
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 ()
127
144
}
128
145
129
146
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 ()
131
153
}
132
154
r .inputConfig = cfg
133
155
r .logger .With (logp .Int64 ("revision" , revision )).Info ("loaded input config" )
0 commit comments