Skip to content

Commit

Permalink
ensure GetProvider is called during FX initialization process
Browse files Browse the repository at this point in the history
  • Loading branch information
GustavoCaso committed Nov 6, 2024
1 parent 7350f1a commit 3465c8f
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 16 deletions.
6 changes: 6 additions & 0 deletions cmd/agent/subcommands/diagnose/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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(),
Expand Down
6 changes: 6 additions & 0 deletions cmd/agent/subcommands/flare/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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(),
Expand Down
10 changes: 7 additions & 3 deletions cmd/agent/subcommands/jmx/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}),
)
}

Expand Down
10 changes: 7 additions & 3 deletions cmd/agent/subcommands/run/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand Down
10 changes: 7 additions & 3 deletions cmd/cluster-agent-cloudfoundry/subcommands/run/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}),
)
},
}
Expand Down
10 changes: 7 additions & 3 deletions cmd/cluster-agent/subcommands/start/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}),
)
},
}
Expand Down
6 changes: 6 additions & 0 deletions cmd/dogstatsd/subcommands/start/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand Down
9 changes: 5 additions & 4 deletions cmd/dogstatsd/subcommands/start/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}
6 changes: 6 additions & 0 deletions cmd/otel-agent/subcommands/run/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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())
Expand Down
6 changes: 6 additions & 0 deletions cmd/security-agent/subcommands/start/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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()
}),
Expand Down
6 changes: 6 additions & 0 deletions cmd/trace-agent/subcommands/run/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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()) }),
Expand Down

0 comments on commit 3465c8f

Please sign in to comment.