diff --git a/cmd/agent/subcommands/diagnose/command.go b/cmd/agent/subcommands/diagnose/command.go index 5b8e50a432a9f..3ed8ad5949f41 100644 --- a/cmd/agent/subcommands/diagnose/command.go +++ b/cmd/agent/subcommands/diagnose/command.go @@ -33,6 +33,7 @@ import ( pkgconfigsetup "github.com/DataDog/datadog-agent/pkg/config/setup" "github.com/DataDog/datadog-agent/pkg/diagnose" "github.com/DataDog/datadog-agent/pkg/diagnose/diagnosis" + "github.com/DataDog/datadog-agent/pkg/util/containers/metrics" "github.com/DataDog/datadog-agent/pkg/util/fxutil" "github.com/DataDog/datadog-agent/pkg/util/optional" @@ -102,6 +103,11 @@ func Commands(globalParams *command.GlobalParams) []*cobra.Command { fx.Supply(optional.NewNoneOption[collector.Component]()), taggerimpl.Module(), fx.Provide(func(config config.Component) tagger.Params { return tagger.NewTaggerParamsForCoreAgent(config) }), + // GetProvider must be called before the application starts so components using either GetProvider or GetMetaCollector can function correctly. + // TODO: (component) - create a container metrics provider component. + fx.Invoke(func(wmeta optional.Option[workloadmeta.Component]) { + metrics.GetProvider(wmeta) + }), autodiscoveryimpl.Module(), compressionimpl.Module(), diagnosesendermanagerimpl.Module(), diff --git a/cmd/agent/subcommands/flare/command.go b/cmd/agent/subcommands/flare/command.go index 97ee057642e52..d58a4cee388e5 100644 --- a/cmd/agent/subcommands/flare/command.go +++ b/cmd/agent/subcommands/flare/command.go @@ -54,6 +54,7 @@ import ( pkgconfigsetup "github.com/DataDog/datadog-agent/pkg/config/setup" procnet "github.com/DataDog/datadog-agent/pkg/process/net" "github.com/DataDog/datadog-agent/pkg/serializer" + "github.com/DataDog/datadog-agent/pkg/util/containers/metrics" "github.com/DataDog/datadog-agent/pkg/util/defaultpaths" "github.com/DataDog/datadog-agent/pkg/util/fxutil" "github.com/DataDog/datadog-agent/pkg/util/input" @@ -127,6 +128,11 @@ func Commands(globalParams *command.GlobalParams) []*cobra.Command { }), fx.Provide(tagger.NewTaggerParams), taggerimpl.Module(), + // GetProvider must be called before the application starts so components using either GetProvider or GetMetaCollector can function correctly. + // TODO: (component) - create a container metrics provider component. + fx.Invoke(func(wmeta optional.Option[workloadmeta.Component]) { + metrics.GetProvider(wmeta) + }), autodiscoveryimpl.Module(), fx.Supply(optional.NewNoneOption[collector.Component]()), compressionimpl.Module(), diff --git a/cmd/agent/subcommands/jmx/command.go b/cmd/agent/subcommands/jmx/command.go index 851be12dfe138..aa7b3b8ee814e 100644 --- a/cmd/agent/subcommands/jmx/command.go +++ b/cmd/agent/subcommands/jmx/command.go @@ -59,6 +59,7 @@ import ( pkgcollector "github.com/DataDog/datadog-agent/pkg/collector" "github.com/DataDog/datadog-agent/pkg/config/model" proccontainers "github.com/DataDog/datadog-agent/pkg/process/util/containers" + "github.com/DataDog/datadog-agent/pkg/util/containers/metrics" "github.com/DataDog/datadog-agent/pkg/util/defaultpaths" "github.com/DataDog/datadog-agent/pkg/util/fxutil" "github.com/DataDog/datadog-agent/pkg/util/optional" @@ -161,12 +162,15 @@ func Commands(globalParams *command.GlobalParams) []*cobra.Command { autodiscoveryimpl.Module(), agent.Bundle(jmxloggerimpl.NewCliParams(cliParams.logFile)), // InitSharedContainerProvider must be called before the application starts so the workloadmeta collector can be initiailized correctly. - // Since the tagger depends on the workloadmeta collector, we can not make the tagger a dependency of workloadmeta as it would create a circular dependency. - // TODO: (component) - once we remove the dependency of workloadmeta component from the tagger component - // we can include the tagger as part of the workloadmeta component. + // TODO: (component) - create a container provider component. fx.Invoke(func(wmeta workloadmeta.Component, tagger tagger.Component) { proccontainers.InitSharedContainerProvider(wmeta, tagger) }), + // GetProvider must be called before the application starts so components using either GetProvider or GetMetaCollector can function correctly. + // TODO: (component) - create a container metrics provider component. + fx.Invoke(func(wmeta optional.Option[workloadmeta.Component]) { + metrics.GetProvider(wmeta) + }), ) } diff --git a/cmd/agent/subcommands/run/command.go b/cmd/agent/subcommands/run/command.go index b52522c07de86..a11e8d0f62f9c 100644 --- a/cmd/agent/subcommands/run/command.go +++ b/cmd/agent/subcommands/run/command.go @@ -146,6 +146,7 @@ import ( pkgTelemetry "github.com/DataDog/datadog-agent/pkg/telemetry" "github.com/DataDog/datadog-agent/pkg/util" pkgcommon "github.com/DataDog/datadog-agent/pkg/util/common" + "github.com/DataDog/datadog-agent/pkg/util/containers/metrics" "github.com/DataDog/datadog-agent/pkg/util/defaultpaths" "github.com/DataDog/datadog-agent/pkg/util/flavor" "github.com/DataDog/datadog-agent/pkg/util/fxutil" @@ -397,12 +398,15 @@ func getSharedFxOption() fx.Option { taggerimpl.Module(), autodiscoveryimpl.Module(), // InitSharedContainerProvider must be called before the application starts so the workloadmeta collector can be initiailized correctly. - // Since the tagger depends on the workloadmeta collector, we can not make the tagger a dependency of workloadmeta as it would create a circular dependency. - // TODO: (component) - once we remove the dependency of workloadmeta component from the tagger component - // we can include the tagger as part of the workloadmeta component. + // TODO: (component) - create a container provider component. fx.Invoke(func(wmeta workloadmeta.Component, tagger tagger.Component) { proccontainers.InitSharedContainerProvider(wmeta, tagger) }), + // GetProvider must be called before the application starts so components using either GetProvider or GetMetaCollector can function correctly. + // TODO: (component) - create a container metrics provider component. + fx.Invoke(func(wmeta optional.Option[workloadmeta.Component]) { + metrics.GetProvider(wmeta) + }), // TODO: (components) - some parts of the agent (such as the logs agent) implicitly depend on the global state // set up by LoadComponents. In order for components to use lifecycle hooks that also depend on this global state, we // have to ensure this code gets run first. Once the common package is made into a component, this can be removed. diff --git a/cmd/cluster-agent-cloudfoundry/subcommands/run/command.go b/cmd/cluster-agent-cloudfoundry/subcommands/run/command.go index d9fdf6db14a4d..4c90a41a7c16c 100644 --- a/cmd/cluster-agent-cloudfoundry/subcommands/run/command.go +++ b/cmd/cluster-agent-cloudfoundry/subcommands/run/command.go @@ -59,6 +59,7 @@ import ( "github.com/DataDog/datadog-agent/pkg/serializer" "github.com/DataDog/datadog-agent/pkg/status/health" "github.com/DataDog/datadog-agent/pkg/util/cloudproviders/cloudfoundry" + "github.com/DataDog/datadog-agent/pkg/util/containers/metrics" "github.com/DataDog/datadog-agent/pkg/util/defaultpaths" "github.com/DataDog/datadog-agent/pkg/util/fxutil" "github.com/DataDog/datadog-agent/pkg/util/hostname" @@ -121,12 +122,15 @@ func Commands(globalParams *command.GlobalParams) []*cobra.Command { }), healthprobefx.Module(), // InitSharedContainerProvider must be called before the application starts so the workloadmeta collector can be initiailized correctly. - // Since the tagger depends on the workloadmeta collector, we can not make the tagger a dependency of workloadmeta as it would create a circular dependency. - // TODO: (component) - once we remove the dependency of workloadmeta component from the tagger component - // we can include the tagger as part of the workloadmeta component. + // TODO: (component) - create a container provider component. fx.Invoke(func(wmeta workloadmeta.Component, tagger tagger.Component) { proccontainers.InitSharedContainerProvider(wmeta, tagger) }), + // GetProvider must be called before the application starts so components using either GetProvider or GetMetaCollector can function correctly. + // TODO: (component) - create a container metrics provider component. + fx.Invoke(func(wmeta optional.Option[workloadmeta.Component]) { + metrics.GetProvider(wmeta) + }), ) }, } diff --git a/cmd/cluster-agent/subcommands/start/command.go b/cmd/cluster-agent/subcommands/start/command.go index db1f4cc2e9ba0..c54b578e51fd0 100644 --- a/cmd/cluster-agent/subcommands/start/command.go +++ b/cmd/cluster-agent/subcommands/start/command.go @@ -21,6 +21,7 @@ import ( "github.com/DataDog/datadog-agent/pkg/remoteconfig/state" "github.com/DataDog/datadog-agent/pkg/serializer" + "github.com/DataDog/datadog-agent/pkg/util/containers/metrics" "github.com/DataDog/datadog-agent/pkg/util/defaultpaths" "github.com/DataDog/datadog-agent/pkg/util/kubernetes/apiserver/controllers" "github.com/DataDog/datadog-agent/pkg/util/optional" @@ -198,12 +199,15 @@ func Commands(globalParams *command.GlobalParams) []*cobra.Command { settingsimpl.Module(), datadogclientmodule.Module(), // InitSharedContainerProvider must be called before the application starts so the workloadmeta collector can be initiailized correctly. - // Since the tagger depends on the workloadmeta collector, we can not make the tagger a dependency of workloadmeta as it would create a circular dependency. - // TODO: (component) - once we remove the dependency of workloadmeta component from the tagger component - // we can include the tagger as part of the workloadmeta component. + // TODO: (component) - create a container provider component. fx.Invoke(func(wmeta workloadmeta.Component, tagger tagger.Component) { proccontainers.InitSharedContainerProvider(wmeta, tagger) }), + // GetProvider must be called before the application starts so components using either GetProvider or GetMetaCollector can function correctly. + // TODO: (component) - create a container metrics provider component. + fx.Invoke(func(wmeta optional.Option[workloadmeta.Component]) { + metrics.GetProvider(wmeta) + }), ) }, } diff --git a/cmd/dogstatsd/subcommands/start/command.go b/cmd/dogstatsd/subcommands/start/command.go index 8be7d95034864..d9fda8c702ed3 100644 --- a/cmd/dogstatsd/subcommands/start/command.go +++ b/cmd/dogstatsd/subcommands/start/command.go @@ -58,6 +58,7 @@ import ( "github.com/DataDog/datadog-agent/pkg/serializer" "github.com/DataDog/datadog-agent/pkg/status/health" "github.com/DataDog/datadog-agent/pkg/util" + "github.com/DataDog/datadog-agent/pkg/util/containers/metrics" "github.com/DataDog/datadog-agent/pkg/util/fxutil" pkglog "github.com/DataDog/datadog-agent/pkg/util/log" pkglogsetup "github.com/DataDog/datadog-agent/pkg/util/log/setup" @@ -152,6 +153,11 @@ func RunDogstatsdFct(cliParams *CLIParams, defaultConfPath string, defaultLogFil eventplatformreceiverimpl.Module(), hostnameimpl.Module(), taggerimpl.Module(), + // GetProvider must be called before the application starts so components using either GetProvider or GetMetaCollector can function correctly. + // TODO: (component) - create a container metrics provider component. + fx.Invoke(func(wmeta optional.Option[workloadmeta.Component]) { + metrics.GetProvider(wmeta) + }), fx.Provide(tagger.NewTaggerParams), // injecting the shared Serializer to FX until we migrate it to a prpoper component. This allows other // already migrated components to request it. diff --git a/cmd/dogstatsd/subcommands/start/command_test.go b/cmd/dogstatsd/subcommands/start/command_test.go index af6d7c60d5cb1..19c20efc19813 100644 --- a/cmd/dogstatsd/subcommands/start/command_test.go +++ b/cmd/dogstatsd/subcommands/start/command_test.go @@ -8,18 +8,19 @@ package start import ( "testing" - "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/pkg/util/fxutil" "github.com/spf13/cobra" "github.com/stretchr/testify/require" + + "github.com/DataDog/datadog-agent/comp/core/config" + "github.com/DataDog/datadog-agent/pkg/util/fxutil" ) func TestStartCommand(t *testing.T) { fxutil.TestOneShotSubcommand(t, []*cobra.Command{MakeCommand("defaultLogFile")}, - []string{"start", "--cfgpath", "PATH"}, + []string{"start"}, start, func(cliParams *CLIParams, _ config.Params) { - require.Equal(t, "PATH", cliParams.confPath) + require.Equal(t, "", cliParams.confPath) }) } diff --git a/cmd/otel-agent/subcommands/run/command.go b/cmd/otel-agent/subcommands/run/command.go index 18d92faa72f3e..b83b91a19e446 100644 --- a/cmd/otel-agent/subcommands/run/command.go +++ b/cmd/otel-agent/subcommands/run/command.go @@ -54,6 +54,7 @@ import ( pkgconfigsetup "github.com/DataDog/datadog-agent/pkg/config/setup" "github.com/DataDog/datadog-agent/pkg/serializer" "github.com/DataDog/datadog-agent/pkg/trace/telemetry" + "github.com/DataDog/datadog-agent/pkg/util/containers/metrics" "github.com/DataDog/datadog-agent/pkg/util/fxutil" "github.com/DataDog/datadog-agent/pkg/util/optional" @@ -189,6 +190,11 @@ func runOTelAgentCommand(ctx context.Context, params *subcommands.GlobalParams, return tagger.NewNodeRemoteTaggerParamsWithFallback() }), taggerimpl.Module(), + // GetProvider must be called before the application starts so components using either GetProvider or GetMetaCollector can function correctly. + // TODO: (component) - create a container metrics provider component. + fx.Invoke(func(wmeta optional.Option[workloadmeta.Component]) { + metrics.GetProvider(wmeta) + }), telemetryimpl.Module(), fx.Provide(func(cfg traceconfig.Component) telemetry.TelemetryCollector { return telemetry.NewCollector(cfg.Object()) diff --git a/cmd/security-agent/subcommands/start/command.go b/cmd/security-agent/subcommands/start/command.go index 317adad3c0b9b..1a2537873553f 100644 --- a/cmd/security-agent/subcommands/start/command.go +++ b/cmd/security-agent/subcommands/start/command.go @@ -62,6 +62,7 @@ import ( "github.com/DataDog/datadog-agent/pkg/security/utils" "github.com/DataDog/datadog-agent/pkg/status/health" "github.com/DataDog/datadog-agent/pkg/util" + "github.com/DataDog/datadog-agent/pkg/util/containers/metrics" "github.com/DataDog/datadog-agent/pkg/util/fxutil" "github.com/DataDog/datadog-agent/pkg/util/optional" "github.com/DataDog/datadog-agent/pkg/util/profiling" @@ -118,6 +119,11 @@ func Commands(globalParams *command.GlobalParams) []*cobra.Command { } return tagger.NewTaggerParams() }), + // GetProvider must be called before the application starts so components using either GetProvider or GetMetaCollector can function correctly. + // TODO: (component) - create a container metrics provider component. + fx.Invoke(func(wmeta optional.Option[workloadmeta.Component]) { + metrics.GetProvider(wmeta) + }), fx.Provide(func() startstop.Stopper { return startstop.NewSerialStopper() }), diff --git a/cmd/trace-agent/subcommands/run/command.go b/cmd/trace-agent/subcommands/run/command.go index 51b81c6a3aa4e..4f1eaa862f4a7 100644 --- a/cmd/trace-agent/subcommands/run/command.go +++ b/cmd/trace-agent/subcommands/run/command.go @@ -38,6 +38,7 @@ import ( zstdfx "github.com/DataDog/datadog-agent/comp/trace/compression/fx-zstd" "github.com/DataDog/datadog-agent/comp/trace/config" "github.com/DataDog/datadog-agent/pkg/trace/telemetry" + "github.com/DataDog/datadog-agent/pkg/util/containers/metrics" "github.com/DataDog/datadog-agent/pkg/util/fxutil" "github.com/DataDog/datadog-agent/pkg/util/optional" ) @@ -105,6 +106,11 @@ func runTraceAgentProcess(ctx context.Context, cliParams *Params, defaultConfPat return tagger.NewTaggerParams() }), taggerimpl.Module(), + // GetProvider must be called before the application starts so components using either GetProvider or GetMetaCollector can function correctly. + // TODO: (component) - create a container metrics provider component. + fx.Invoke(func(wmeta optional.Option[workloadmeta.Component]) { + metrics.GetProvider(wmeta) + }), fx.Invoke(func(_ config.Component) {}), // Required to avoid cyclic imports. fx.Provide(func(cfg config.Component) telemetry.TelemetryCollector { return telemetry.NewCollector(cfg.Object()) }),