Skip to content

Commit 65af190

Browse files
pkoutsovasilismergify[bot]
authored andcommitted
fix: scheduled upgrade details state (#9562)
* fix: persisting and reporting of upgrade details * ci: align and extend dispatcher unit-tests * ci: update coordinator and application new signatures in unit-tests * ci: add integration tests for scheduled upgrade details * doc: add changelog fragment * doc: reword existing and add more comments in code * feat: change queuedUpgradeActions inside dispatchCancelActions to have values of struct{} * fix: remove redundant continue * fix: dedupe upgrade actions from fleetgateway actions, handle correctly the expiration of retried stored actions, and update upgrade details on retries (cherry picked from commit ff80471) # Conflicts: # internal/pkg/agent/application/application.go # internal/pkg/agent/application/coordinator/coordinator.go # internal/pkg/agent/cmd/run.go
1 parent ccf6241 commit 65af190

File tree

14 files changed

+1120
-301
lines changed

14 files changed

+1120
-301
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
kind: bug-fix
2+
summary: fix reporting of scheduled upgrade details across restarts and cancels
3+
component: elastic-agent
4+
pr: https://github.com/elastic/elastic-agent/pull/9562
5+
issue: https://github.com/elastic/elastic-agent/issues/8778

internal/pkg/agent/application/actions/handlers/handler_action_upgrade_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ func TestUpgradeHandler(t *testing.T) {
115115
return nil, nil
116116
},
117117
},
118-
nil, nil, nil, nil, nil, false, nil, nil)
118+
nil, nil, nil, nil, nil, false, nil, nil, nil)
119119
//nolint:errcheck // We don't need the termination state of the Coordinator
120120
go c.Run(ctx)
121121

@@ -174,7 +174,7 @@ func TestUpgradeHandlerSameVersion(t *testing.T) {
174174
return nil, err
175175
},
176176
},
177-
nil, nil, nil, nil, nil, false, nil, nil)
177+
nil, nil, nil, nil, nil, false, nil, nil, nil)
178178
//nolint:errcheck // We don't need the termination state of the Coordinator
179179
go c.Run(ctx)
180180

@@ -233,7 +233,7 @@ func TestDuplicateActionsHandled(t *testing.T) {
233233
return nil, nil
234234
},
235235
},
236-
nil, nil, nil, nil, nil, false, nil, acker)
236+
nil, nil, nil, nil, nil, false, nil, acker, nil)
237237
//nolint:errcheck // We don't need the termination state of the Coordinator
238238
go c.Run(ctx)
239239

@@ -327,7 +327,7 @@ func TestUpgradeHandlerNewVersion(t *testing.T) {
327327
return nil, nil
328328
},
329329
},
330-
nil, nil, nil, nil, nil, false, nil, nil)
330+
nil, nil, nil, nil, nil, false, nil, nil, nil)
331331
//nolint:errcheck // We don't need the termination state of the Coordinator
332332
go c.Run(ctx)
333333

internal/pkg/agent/application/application.go

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ import (
1616
"github.com/elastic/elastic-agent-libs/logp"
1717

1818
"github.com/elastic/elastic-agent/internal/pkg/agent/application/coordinator"
19+
"github.com/elastic/elastic-agent/internal/pkg/agent/application/dispatcher"
1920
"github.com/elastic/elastic-agent/internal/pkg/agent/application/info"
2021
"github.com/elastic/elastic-agent/internal/pkg/agent/application/monitoring"
2122
"github.com/elastic/elastic-agent/internal/pkg/agent/application/paths"
2223
"github.com/elastic/elastic-agent/internal/pkg/agent/application/upgrade"
24+
"github.com/elastic/elastic-agent/internal/pkg/agent/application/upgrade/details"
2325
"github.com/elastic/elastic-agent/internal/pkg/agent/configuration"
2426
"github.com/elastic/elastic-agent/internal/pkg/agent/errors"
2527
"github.com/elastic/elastic-agent/internal/pkg/agent/storage"
@@ -34,6 +36,7 @@ import (
3436
"github.com/elastic/elastic-agent/internal/pkg/fleetapi/acker/retrier"
3537
fleetclient "github.com/elastic/elastic-agent/internal/pkg/fleetapi/client"
3638
otelmanager "github.com/elastic/elastic-agent/internal/pkg/otel/manager"
39+
"github.com/elastic/elastic-agent/internal/pkg/queue"
3740
"github.com/elastic/elastic-agent/internal/pkg/release"
3841
"github.com/elastic/elastic-agent/pkg/component"
3942
"github.com/elastic/elastic-agent/pkg/component/runtime"
@@ -59,6 +62,7 @@ func New(
5962
fleetInitTimeout time.Duration,
6063
disableMonitoring bool,
6164
override CfgOverrider,
65+
initialUpgradeDetails *details.Details,
6266
modifiers ...component.PlatformModifier,
6367
) (*coordinator.Coordinator, coordinator.ConfigManager, composable.Controller, error) {
6468

@@ -143,7 +147,6 @@ func New(
143147
var compModifiers = []coordinator.ComponentsModifier{InjectAPMConfig}
144148
var composableManaged bool
145149
var isManaged bool
146-
147150
var actionAcker acker.Acker
148151
if testingMode {
149152
log.Info("Elastic Agent has been started in testing mode and is managed through the control protocol")
@@ -212,8 +215,19 @@ func New(
212215
batchedAcker := lazy.NewAcker(fleetAcker, log, lazy.WithRetrier(retrier))
213216
actionAcker = stateStore.NewStateStoreActionAcker(batchedAcker, stateStorage)
214217

218+
actionQueue, err := queue.NewActionQueue(stateStorage.Queue(), stateStorage)
219+
if err != nil {
220+
return nil, nil, nil, fmt.Errorf("unable to initialize action queue: %w", err)
221+
}
222+
223+
if initialUpgradeDetails == nil {
224+
// initial upgrade details are nil (normally the caller supplies the ones from the marker file at this point),
225+
// hence, extract any scheduled upgrade details from the action queue.
226+
initialUpgradeDetails = dispatcher.GetScheduledUpgradeDetails(log, actionQueue.Actions(), time.Now())
227+
}
228+
215229
// TODO: stop using global state
216-
managed, err = newManagedConfigManager(ctx, log, agentInfo, cfg, store, runtime, fleetInitTimeout, paths.Top(), client, fleetAcker, actionAcker, retrier, stateStorage, upgrader)
230+
managed, err = newManagedConfigManager(ctx, log, agentInfo, cfg, store, runtime, fleetInitTimeout, paths.Top(), client, fleetAcker, actionAcker, retrier, stateStorage, actionQueue, upgrader)
217231
if err != nil {
218232
return nil, nil, nil, err
219233
}
@@ -226,8 +240,16 @@ func New(
226240
return nil, nil, nil, errors.New(err, "failed to initialize composable controller")
227241
}
228242

243+
<<<<<<< HEAD
229244
otelManager := otelmanager.NewOTelManager(log.Named("otel_manager"))
230245
coord := coordinator.New(log, cfg, logLevel, agentInfo, specs, reexec, upgrader, runtime, configMgr, varsManager, caps, monitor, isManaged, otelManager, actionAcker, compModifiers...)
246+
=======
247+
otelManager, err := otelmanager.NewOTelManager(log.Named("otel_manager"), logLevel, baseLogger, otelmanager.EmbeddedExecutionMode, agentInfo, monitor.ComponentMonitoringConfig)
248+
if err != nil {
249+
return nil, nil, nil, fmt.Errorf("failed to create otel manager: %w", err)
250+
}
251+
coord := coordinator.New(log, cfg, logLevel, agentInfo, specs, reexec, upgrader, runtime, configMgr, varsManager, caps, monitor, isManaged, otelManager, actionAcker, initialUpgradeDetails, compModifiers...)
252+
>>>>>>> ff8047180 (fix: scheduled upgrade details state (#9562))
231253
if managed != nil {
232254
// the coordinator requires the config manager as well as in managed-mode the config manager requires the
233255
// coordinator, so it must be set here once the coordinator is created

internal/pkg/agent/application/application_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ func TestLimitsLog(t *testing.T) {
6464
time.Millisecond, // fleetInitTimeout
6565
true, // disable monitoring
6666
nil, // no configuration overrides
67+
nil,
6768
)
6869
require.NoError(t, err)
6970

internal/pkg/agent/application/coordinator/coordinator.go

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,29 @@ type UpdateComponentChange struct {
378378
}
379379

380380
// New creates a new coordinator.
381+
<<<<<<< HEAD
381382
func New(logger *logger.Logger, cfg *configuration.Configuration, logLevel logp.Level, agentInfo info.Agent, specs component.RuntimeSpecs, reexecMgr ReExecManager, upgradeMgr UpgradeManager, runtimeMgr RuntimeManager, configMgr ConfigManager, varsMgr VarsManager, caps capabilities.Capabilities, monitorMgr MonitorManager, isManaged bool, otelMgr OTelManager, fleetAcker acker.Acker, modifiers ...ComponentsModifier) *Coordinator {
383+
=======
384+
func New(
385+
logger *logger.Logger,
386+
cfg *configuration.Configuration,
387+
logLevel logp.Level,
388+
agentInfo info.Agent,
389+
specs component.RuntimeSpecs,
390+
reexecMgr ReExecManager,
391+
upgradeMgr UpgradeManager,
392+
runtimeMgr RuntimeManager,
393+
configMgr ConfigManager,
394+
varsMgr VarsManager,
395+
caps capabilities.Capabilities,
396+
monitorMgr MonitorManager,
397+
isManaged bool,
398+
otelMgr OTelManager,
399+
fleetAcker acker.Acker,
400+
initialUpgradeDetails *details.Details,
401+
modifiers ...ComponentsModifier,
402+
) *Coordinator {
403+
>>>>>>> ff8047180 (fix: scheduled upgrade details state (#9562))
382404
var fleetState cproto.State
383405
var fleetMessage string
384406
if !isManaged {
@@ -387,11 +409,12 @@ func New(logger *logger.Logger, cfg *configuration.Configuration, logLevel logp.
387409
fleetMessage = "Not enrolled into Fleet"
388410
}
389411
state := State{
390-
State: agentclient.Starting,
391-
Message: "Starting",
392-
FleetState: fleetState,
393-
FleetMessage: fleetMessage,
394-
LogLevel: logLevel,
412+
State: agentclient.Starting,
413+
Message: "Starting",
414+
FleetState: fleetState,
415+
FleetMessage: fleetMessage,
416+
LogLevel: logLevel,
417+
UpgradeDetails: initialUpgradeDetails,
395418
}
396419
c := &Coordinator{
397420
logger: logger,

internal/pkg/agent/application/coordinator/coordinator_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1096,7 +1096,7 @@ func createCoordinator(t testing.TB, ctx context.Context, opts ...CoordinatorOpt
10961096
acker = &fakeActionAcker{}
10971097
}
10981098

1099-
coord := New(l, nil, logp.DebugLevel, ai, specs, &fakeReExecManager{}, upgradeManager, rm, cfgMgr, varsMgr, caps, monitoringMgr, o.managed, otelMgr, acker)
1099+
coord := New(l, nil, logp.DebugLevel, ai, specs, &fakeReExecManager{}, upgradeManager, rm, cfgMgr, varsMgr, caps, monitoringMgr, o.managed, otelMgr, acker, nil)
11001100
return coord, cfgMgr, varsMgr
11011101
}
11021102

0 commit comments

Comments
 (0)