@@ -12,7 +12,6 @@ import (
12
12
13
13
eaclient "github.com/elastic/elastic-agent-client/v7/pkg/client"
14
14
"github.com/elastic/elastic-agent/internal/pkg/agent/application/coordinator"
15
- "github.com/elastic/elastic-agent/internal/pkg/agent/application/gateway"
16
15
"github.com/elastic/elastic-agent/internal/pkg/agent/application/info"
17
16
"github.com/elastic/elastic-agent/internal/pkg/agent/errors"
18
17
"github.com/elastic/elastic-agent/internal/pkg/core/backoff"
@@ -66,7 +65,7 @@ type stateStore interface {
66
65
Actions () []fleetapi.Action
67
66
}
68
67
69
- type fleetGateway struct {
68
+ type FleetGateway struct {
70
69
log * logger.Logger
71
70
client client.Sender
72
71
scheduler scheduler.Scheduler
@@ -89,7 +88,7 @@ func New(
89
88
acker acker.Acker ,
90
89
stateFetcher func () coordinator.State ,
91
90
stateStore stateStore ,
92
- ) (gateway. FleetGateway , error ) {
91
+ ) (* FleetGateway , error ) {
93
92
94
93
scheduler := scheduler .NewPeriodicJitter (defaultGatewaySettings .Duration , defaultGatewaySettings .Jitter )
95
94
return newFleetGatewayWithScheduler (
@@ -113,8 +112,8 @@ func newFleetGatewayWithScheduler(
113
112
acker acker.Acker ,
114
113
stateFetcher func () coordinator.State ,
115
114
stateStore stateStore ,
116
- ) (gateway. FleetGateway , error ) {
117
- return & fleetGateway {
115
+ ) (* FleetGateway , error ) {
116
+ return & FleetGateway {
118
117
log : log ,
119
118
client : client ,
120
119
settings : settings ,
@@ -128,11 +127,11 @@ func newFleetGatewayWithScheduler(
128
127
}, nil
129
128
}
130
129
131
- func (f * fleetGateway ) Actions () <- chan []fleetapi.Action {
130
+ func (f * FleetGateway ) Actions () <- chan []fleetapi.Action {
132
131
return f .actionCh
133
132
}
134
133
135
- func (f * fleetGateway ) Run (ctx context.Context ) error {
134
+ func (f * FleetGateway ) Run (ctx context.Context ) error {
136
135
// Backoff implementation doesn't support the use of a context [cancellation] as the shutdown mechanism.
137
136
// So we keep a done channel that will be closed when the current context is shutdown.
138
137
done := make (chan struct {})
@@ -174,11 +173,11 @@ func (f *fleetGateway) Run(ctx context.Context) error {
174
173
}
175
174
176
175
// Errors returns the channel to watch for reported errors.
177
- func (f * fleetGateway ) Errors () <- chan error {
176
+ func (f * FleetGateway ) Errors () <- chan error {
178
177
return f .errCh
179
178
}
180
179
181
- func (f * fleetGateway ) doExecute (ctx context.Context , bo backoff.Backoff ) (* fleetapi.CheckinResponse , error ) {
180
+ func (f * FleetGateway ) doExecute (ctx context.Context , bo backoff.Backoff ) (* fleetapi.CheckinResponse , error ) {
182
181
bo .Reset ()
183
182
184
183
// Guard if the context is stopped by a out of bound call,
@@ -222,7 +221,12 @@ func (f *fleetGateway) doExecute(ctx context.Context, bo backoff.Backoff) (*flee
222
221
}
223
222
224
223
f .checkinFailCounter = 0
225
- f .errCh <- nil
224
+ if resp .FleetWarning != "" {
225
+ f .errCh <- coordinator .NewWarningError (resp .FleetWarning )
226
+ } else {
227
+ f .errCh <- nil
228
+ }
229
+
226
230
// Request was successful, return the collected actions.
227
231
return resp , nil
228
232
}
@@ -232,7 +236,7 @@ func (f *fleetGateway) doExecute(ctx context.Context, bo backoff.Backoff) (*flee
232
236
return nil , ctx .Err ()
233
237
}
234
238
235
- func (f * fleetGateway ) convertToCheckinComponents (components []runtime.ComponentComponentState ) []fleetapi.CheckinComponent {
239
+ func (f * FleetGateway ) convertToCheckinComponents (components []runtime.ComponentComponentState ) []fleetapi.CheckinComponent {
236
240
if components == nil {
237
241
return nil
238
242
}
@@ -307,7 +311,7 @@ func (f *fleetGateway) convertToCheckinComponents(components []runtime.Component
307
311
return checkinComponents
308
312
}
309
313
310
- func (f * fleetGateway ) execute (ctx context.Context ) (* fleetapi.CheckinResponse , time.Duration , error ) {
314
+ func (f * FleetGateway ) execute (ctx context.Context ) (* fleetapi.CheckinResponse , time.Duration , error ) {
311
315
ecsMeta , err := info .Metadata (ctx , f .log )
312
316
if err != nil {
313
317
f .log .Error (errors .New ("failed to load metadata" , err ))
@@ -367,15 +371,15 @@ func (f *fleetGateway) execute(ctx context.Context) (*fleetapi.CheckinResponse,
367
371
}
368
372
369
373
// shouldUnenroll checks if the max number of trying an invalid key is reached
370
- func (f * fleetGateway ) shouldUnenroll () bool {
374
+ func (f * FleetGateway ) shouldUnenroll () bool {
371
375
return f .unauthCounter > maxUnauthCounter
372
376
}
373
377
374
378
func isUnauth (err error ) bool {
375
379
return errors .Is (err , client .ErrInvalidAPIKey )
376
380
}
377
381
378
- func (f * fleetGateway ) SetClient (c client.Sender ) {
382
+ func (f * FleetGateway ) SetClient (c client.Sender ) {
379
383
f .client = c
380
384
}
381
385
0 commit comments