@@ -14,10 +14,12 @@ import (
14
14
"github.com/elastic/elastic-agent-libs/logp"
15
15
16
16
"github.com/elastic/elastic-agent/internal/pkg/agent/application/coordinator"
17
+ "github.com/elastic/elastic-agent/internal/pkg/agent/application/dispatcher"
17
18
"github.com/elastic/elastic-agent/internal/pkg/agent/application/info"
18
19
"github.com/elastic/elastic-agent/internal/pkg/agent/application/monitoring"
19
20
"github.com/elastic/elastic-agent/internal/pkg/agent/application/paths"
20
21
"github.com/elastic/elastic-agent/internal/pkg/agent/application/upgrade"
22
+ "github.com/elastic/elastic-agent/internal/pkg/agent/application/upgrade/details"
21
23
"github.com/elastic/elastic-agent/internal/pkg/agent/configuration"
22
24
"github.com/elastic/elastic-agent/internal/pkg/agent/errors"
23
25
"github.com/elastic/elastic-agent/internal/pkg/agent/storage"
@@ -32,6 +34,7 @@ import (
32
34
"github.com/elastic/elastic-agent/internal/pkg/fleetapi/acker/retrier"
33
35
fleetclient "github.com/elastic/elastic-agent/internal/pkg/fleetapi/client"
34
36
otelmanager "github.com/elastic/elastic-agent/internal/pkg/otel/manager"
37
+ "github.com/elastic/elastic-agent/internal/pkg/queue"
35
38
"github.com/elastic/elastic-agent/internal/pkg/release"
36
39
"github.com/elastic/elastic-agent/pkg/component"
37
40
"github.com/elastic/elastic-agent/pkg/component/runtime"
@@ -57,6 +60,7 @@ func New(
57
60
fleetInitTimeout time.Duration ,
58
61
disableMonitoring bool ,
59
62
override CfgOverrider ,
63
+ initialUpgradeDetails * details.Details ,
60
64
modifiers ... component.PlatformModifier ,
61
65
) (* coordinator.Coordinator , coordinator.ConfigManager , composable.Controller , error ) {
62
66
@@ -141,7 +145,6 @@ func New(
141
145
var compModifiers = []coordinator.ComponentsModifier {InjectAPMConfig }
142
146
var composableManaged bool
143
147
var isManaged bool
144
-
145
148
var actionAcker acker.Acker
146
149
if testingMode {
147
150
log .Info ("Elastic Agent has been started in testing mode and is managed through the control protocol" )
@@ -210,8 +213,19 @@ func New(
210
213
batchedAcker := lazy .NewAcker (fleetAcker , log , lazy .WithRetrier (retrier ))
211
214
actionAcker = stateStore .NewStateStoreActionAcker (batchedAcker , stateStorage )
212
215
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
+
213
227
// 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 )
215
229
if err != nil {
216
230
return nil , nil , nil , err
217
231
}
@@ -228,7 +242,7 @@ func New(
228
242
if err != nil {
229
243
return nil , nil , nil , fmt .Errorf ("failed to create otel manager: %w" , err )
230
244
}
231
- coord := coordinator .New (log , cfg , logLevel , agentInfo , specs , reexec , upgrader , runtime , configMgr , varsManager , caps , monitor , isManaged , otelManager , actionAcker , compModifiers ... )
245
+ coord := coordinator .New (log , cfg , logLevel , agentInfo , specs , reexec , upgrader , runtime , configMgr , varsManager , caps , monitor , isManaged , otelManager , actionAcker , initialUpgradeDetails , compModifiers ... )
232
246
if managed != nil {
233
247
// the coordinator requires the config manager as well as in managed-mode the config manager requires the
234
248
// coordinator, so it must be set here once the coordinator is created
0 commit comments