Skip to content

Commit 3cc368f

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 bd57bd1 commit 3cc368f

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
@@ -14,10 +14,12 @@ import (
1414
"github.com/elastic/elastic-agent-libs/logp"
1515

1616
"github.com/elastic/elastic-agent/internal/pkg/agent/application/coordinator"
17+
"github.com/elastic/elastic-agent/internal/pkg/agent/application/dispatcher"
1718
"github.com/elastic/elastic-agent/internal/pkg/agent/application/info"
1819
"github.com/elastic/elastic-agent/internal/pkg/agent/application/monitoring"
1920
"github.com/elastic/elastic-agent/internal/pkg/agent/application/paths"
2021
"github.com/elastic/elastic-agent/internal/pkg/agent/application/upgrade"
22+
"github.com/elastic/elastic-agent/internal/pkg/agent/application/upgrade/details"
2123
"github.com/elastic/elastic-agent/internal/pkg/agent/configuration"
2224
"github.com/elastic/elastic-agent/internal/pkg/agent/errors"
2325
"github.com/elastic/elastic-agent/internal/pkg/agent/storage"
@@ -32,6 +34,7 @@ import (
3234
"github.com/elastic/elastic-agent/internal/pkg/fleetapi/acker/retrier"
3335
fleetclient "github.com/elastic/elastic-agent/internal/pkg/fleetapi/client"
3436
otelmanager "github.com/elastic/elastic-agent/internal/pkg/otel/manager"
37+
"github.com/elastic/elastic-agent/internal/pkg/queue"
3538
"github.com/elastic/elastic-agent/internal/pkg/release"
3639
"github.com/elastic/elastic-agent/pkg/component"
3740
"github.com/elastic/elastic-agent/pkg/component/runtime"
@@ -57,6 +60,7 @@ func New(
5760
fleetInitTimeout time.Duration,
5861
disableMonitoring bool,
5962
override CfgOverrider,
63+
initialUpgradeDetails *details.Details,
6064
modifiers ...component.PlatformModifier,
6165
) (*coordinator.Coordinator, coordinator.ConfigManager, composable.Controller, error) {
6266

@@ -141,7 +145,6 @@ func New(
141145
var compModifiers = []coordinator.ComponentsModifier{InjectAPMConfig}
142146
var composableManaged bool
143147
var isManaged bool
144-
145148
var actionAcker acker.Acker
146149
if testingMode {
147150
log.Info("Elastic Agent has been started in testing mode and is managed through the control protocol")
@@ -210,8 +213,19 @@ func New(
210213
batchedAcker := lazy.NewAcker(fleetAcker, log, lazy.WithRetrier(retrier))
211214
actionAcker = stateStore.NewStateStoreActionAcker(batchedAcker, stateStorage)
212215

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

241+
<<<<<<< HEAD
227242
otelManager := otelmanager.NewOTelManager(log.Named("otel_manager"))
228243
coord := coordinator.New(log, cfg, logLevel, agentInfo, specs, reexec, upgrader, runtime, configMgr, varsManager, caps, monitor, isManaged, otelManager, actionAcker, compModifiers...)
244+
=======
245+
otelManager, err := otelmanager.NewOTelManager(log.Named("otel_manager"), logLevel, baseLogger, otelmanager.EmbeddedExecutionMode, agentInfo, monitor.ComponentMonitoringConfig)
246+
if err != nil {
247+
return nil, nil, nil, fmt.Errorf("failed to create otel manager: %w", err)
248+
}
249+
coord := coordinator.New(log, cfg, logLevel, agentInfo, specs, reexec, upgrader, runtime, configMgr, varsManager, caps, monitor, isManaged, otelManager, actionAcker, initialUpgradeDetails, compModifiers...)
250+
>>>>>>> ff8047180 (fix: scheduled upgrade details state (#9562))
229251
if managed != nil {
230252
// the coordinator requires the config manager as well as in managed-mode the config manager requires the
231253
// 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)