Skip to content

Commit 95ab857

Browse files
fix: persisting and reporting of upgrade details
1 parent 6060b9c commit 95ab857

File tree

5 files changed

+234
-126
lines changed

5 files changed

+234
-126
lines changed

internal/pkg/agent/application/application.go

Lines changed: 17 additions & 3 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
}
@@ -230,7 +244,7 @@ func New(
230244
if err != nil {
231245
return nil, nil, nil, fmt.Errorf("failed to create otel manager: %w", err)
232246
}
233-
coord := coordinator.New(log, cfg, logLevel, agentInfo, specs, reexec, upgrader, runtime, configMgr, varsManager, caps, monitor, isManaged, otelManager, actionAcker, compModifiers...)
247+
coord := coordinator.New(log, cfg, logLevel, agentInfo, specs, reexec, upgrader, runtime, configMgr, varsManager, caps, monitor, isManaged, otelManager, actionAcker, initialUpgradeDetails, compModifiers...)
234248
if managed != nil {
235249
// the coordinator requires the config manager as well as in managed-mode the config manager requires the
236250
// coordinator, so it must be set here once the coordinator is created

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,7 @@ func New(
420420
isManaged bool,
421421
otelMgr OTelManager,
422422
fleetAcker acker.Acker,
423+
initialUpgradeDetails *details.Details,
423424
modifiers ...ComponentsModifier,
424425
) *Coordinator {
425426
var fleetState cproto.State
@@ -430,11 +431,12 @@ func New(
430431
fleetMessage = "Not enrolled into Fleet"
431432
}
432433
state := State{
433-
State: agentclient.Starting,
434-
Message: "Starting",
435-
FleetState: fleetState,
436-
FleetMessage: fleetMessage,
437-
LogLevel: logLevel,
434+
State: agentclient.Starting,
435+
Message: "Starting",
436+
FleetState: fleetState,
437+
FleetMessage: fleetMessage,
438+
LogLevel: logLevel,
439+
UpgradeDetails: initialUpgradeDetails,
438440
}
439441
c := &Coordinator{
440442
logger: logger,

0 commit comments

Comments
 (0)