diff --git a/cmd/agent/common/loader.go b/cmd/agent/common/loader.go index bdd39a9664aa52..50e5fba09c93f4 100644 --- a/cmd/agent/common/loader.go +++ b/cmd/agent/common/loader.go @@ -45,6 +45,15 @@ func GetWorkloadmetaInit() workloadmeta.InitHelper { t = local.NewTagger(wm) } + // SBOM scanner needs to be called here as initialization is required prior to the + // catalog getting instantiated and initialized. + sbomScanner, err := scanner.CreateGlobalScanner(config.Datadog) + if err != nil { + log.Errorf("failed to create SBOM scanner: %s", err) + } else if sbomScanner != nil { + sbomScanner.Start(ctx) + } + tagger.SetDefaultTagger(t) if err := tagger.Init(ctx); err != nil { e = fmt.Errorf("failed to start the tagger: %s", err) @@ -56,7 +65,7 @@ func GetWorkloadmetaInit() workloadmeta.InitHelper { // LoadComponents configures several common Agent components: // tagger, collector, scheduler and autodiscovery -func LoadComponents(ctx context.Context, senderManager sender.SenderManager, confdPath string) { +func LoadComponents(senderManager sender.SenderManager, confdPath string) { confSearchPaths := []string{ confdPath, @@ -73,13 +82,6 @@ func LoadComponents(ctx context.Context, senderManager sender.SenderManager, con // because of subscription to metadata store. AC = setupAutoDiscovery(confSearchPaths, scheduler.NewMetaScheduler()) - sbomScanner, err := scanner.CreateGlobalScanner(config.Datadog) - if err != nil { - log.Errorf("failed to create SBOM scanner: %s", err) - } else if sbomScanner != nil { - sbomScanner.Start(ctx) - } - // create the Collector instance and start all the components // NOTICE: this will also setup the Python environment, if available Coll = collector.NewCollector(senderManager, GetPythonPaths()...) diff --git a/cmd/agent/subcommands/jmx/command.go b/cmd/agent/subcommands/jmx/command.go index 150dec6de33581..5a2b872ab11940 100644 --- a/cmd/agent/subcommands/jmx/command.go +++ b/cmd/agent/subcommands/jmx/command.go @@ -252,7 +252,7 @@ func runJmxCommandConsole(config config.Component, cliParams *cliParams, wmeta w } // The Autoconfig instance setup happens in the workloadmeta start hook // create and setup the Collector and others. - common.LoadComponents(context.Background(), senderManager, config.GetString("confd_path")) + common.LoadComponents(senderManager, config.GetString("confd_path")) common.AC.LoadAndRun(context.Background()) // Create the CheckScheduler, but do not attach it to diff --git a/cmd/agent/subcommands/run/command.go b/cmd/agent/subcommands/run/command.go index 9cf28852450a70..a1d4f9747d0d37 100644 --- a/cmd/agent/subcommands/run/command.go +++ b/cmd/agent/subcommands/run/command.go @@ -323,11 +323,9 @@ func getSharedFxOption() fx.Option { fx.Invoke(func(lc fx.Lifecycle, demultiplexer demultiplexer.Component, _ workloadmeta.Component) { lc.Append(fx.Hook{ OnStart: func(ctx context.Context) error { - // Main context passed to components - mainCtx, _ := pkgcommon.GetMainCtxCancel() // create and setup the Autoconfig instance - common.LoadComponents(mainCtx, demultiplexer, pkgconfig.Datadog.GetString("confd_path")) + common.LoadComponents(demultiplexer, pkgconfig.Datadog.GetString("confd_path")) return nil }, OnStop: func(ctx context.Context) error { diff --git a/cmd/cluster-agent-cloudfoundry/subcommands/run/command.go b/cmd/cluster-agent-cloudfoundry/subcommands/run/command.go index 374e6611bd5747..1de8486ada8d14 100644 --- a/cmd/cluster-agent-cloudfoundry/subcommands/run/command.go +++ b/cmd/cluster-agent-cloudfoundry/subcommands/run/command.go @@ -131,7 +131,7 @@ func run(log log.Component, demultiplexer demultiplexer.Component, wmeta workloa // create and setup the Autoconfig instance // The Autoconfig instance setup happens in the workloadmeta start hook // create and setup the Collector and others. - common.LoadComponents(mainCtx, demultiplexer, pkgconfig.Datadog.GetString("confd_path")) + common.LoadComponents(demultiplexer, pkgconfig.Datadog.GetString("confd_path")) // Set up check collector common.AC.AddScheduler("check", collector.InitCheckScheduler(common.Coll, demultiplexer), true) diff --git a/cmd/cluster-agent/subcommands/start/command.go b/cmd/cluster-agent/subcommands/start/command.go index d78fff1a63ed6f..ff73f444b8cce4 100644 --- a/cmd/cluster-agent/subcommands/start/command.go +++ b/cmd/cluster-agent/subcommands/start/command.go @@ -256,7 +256,7 @@ func start(log log.Component, config config.Component, telemetry telemetry.Compo // create and setup the Autoconfig instance // The Autoconfig instance setup happens in the workloadmeta start hook // create and setup the Collector and others. - common.LoadComponents(mainCtx, demultiplexer, pkgconfig.Datadog.GetString("confd_path")) + common.LoadComponents(demultiplexer, pkgconfig.Datadog.GetString("confd_path")) // Set up check collector common.AC.AddScheduler("check", collector.InitCheckScheduler(common.Coll, demultiplexer), true) diff --git a/comp/core/workloadmeta/workloadmeta.go b/comp/core/workloadmeta/workloadmeta.go index 08a973d3dabf2c..af89301b37af3e 100644 --- a/comp/core/workloadmeta/workloadmeta.go +++ b/comp/core/workloadmeta/workloadmeta.go @@ -83,16 +83,18 @@ func newWorkloadMeta(deps dependencies) Component { var err error + // Main context passed to components + // TODO(components): this mainCtx should probably be replaced by the + // context provided to the OnStart hook. + mainCtx, _ := common.GetMainCtxCancel() + // create and setup the Autoconfig instance if deps.Params.InitHelper != nil { - err = deps.Params.InitHelper(c, wm) + err = deps.Params.InitHelper(mainCtx, wm) if err != nil { return err } } - - // Main context passed to components - mainCtx, _ := common.GetMainCtxCancel() wm.Start(mainCtx) return nil }}) diff --git a/pkg/cli/subcommands/check/command.go b/pkg/cli/subcommands/check/command.go index 028a8095426593..eaa871c683615b 100644 --- a/pkg/cli/subcommands/check/command.go +++ b/pkg/cli/subcommands/check/command.go @@ -203,7 +203,7 @@ func run(config config.Component, cliParams *cliParams, demultiplexer demultiple return nil } - common.LoadComponents(context.Background(), demultiplexer, pkgconfig.Datadog.GetString("confd_path")) + common.LoadComponents(demultiplexer, pkgconfig.Datadog.GetString("confd_path")) common.AC.LoadAndRun(context.Background()) // Create the CheckScheduler, but do not attach it to