Skip to content

Commit

Permalink
Remove fx.Supply(params) from system-probe, enable trace-agent, fix t…
Browse files Browse the repository at this point in the history
…ests
  • Loading branch information
dustmop committed Nov 22, 2023
1 parent aa138cb commit fcc35c3
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 11 deletions.
4 changes: 2 additions & 2 deletions cmd/agent/subcommands/diagnose/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ func TestShowMetadataInventoryHostCommand(t *testing.T) {
Commands(&command.GlobalParams{}),
[]string{"diagnose", "show-metadata", "inventory-host"},
printPayload,
func(cliParams *cliParams, coreParams core.BundleParams) {
require.Equal(t, false, coreParams.ConfigLoadSecrets())
func(cliParams *cliParams, coreParams core.BundleParams, secretParams secrets.Params) {
require.Equal(t, false, secretParams.Enabled)
require.Equal(t, "inventory-host", cliParams.payloadName)
})
}
2 changes: 1 addition & 1 deletion cmd/agent/subcommands/run/command_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ func StartAgentWithDefaults(ctxChan <-chan context.Context) (<-chan error, error
hostMetadata,
invAgent,
invHost,
secretResolver,
)
secretResolver)
if err != nil {
return err
}
Expand Down
4 changes: 0 additions & 4 deletions cmd/system-probe/subcommands/run/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ import (
"github.com/DataDog/datadog-agent/cmd/system-probe/utils"
"github.com/DataDog/datadog-agent/comp/core/config"
"github.com/DataDog/datadog-agent/comp/core/log"
"github.com/DataDog/datadog-agent/comp/core/secrets"
"github.com/DataDog/datadog-agent/comp/core/secrets/secretsimpl"
"github.com/DataDog/datadog-agent/comp/core/sysprobeconfig"
"github.com/DataDog/datadog-agent/comp/core/sysprobeconfig/sysprobeconfigimpl"
"github.com/DataDog/datadog-agent/comp/core/telemetry"
Expand Down Expand Up @@ -74,13 +72,11 @@ func Commands(globalParams *command.GlobalParams) []*cobra.Command {
fx.Supply(cliParams),
fx.Supply(config.NewAgentParams("", config.WithConfigMissingOK(true))),
fx.Supply(sysprobeconfigimpl.NewParams(sysprobeconfigimpl.WithSysProbeConfFilePath(globalParams.ConfFilePath))),
fx.Supply(secrets.NewDisabledParams()),
fx.Supply(log.ForDaemon("SYS-PROBE", "log_file", common.DefaultLogFile)),
config.Module,
telemetry.Module,
sysprobeconfigimpl.Module,
rcclient.Module,
secretsimpl.Module,
// use system-probe config instead of agent config for logging
fx.Provide(func(lc fx.Lifecycle, params log.Params, sysprobeconfig sysprobeconfig.Component) (log.Component, error) {
return log.NewLogger(lc, params, sysprobeconfig)
Expand Down
2 changes: 2 additions & 0 deletions cmd/trace-agent/subcommands/run/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
coreconfig "github.com/DataDog/datadog-agent/comp/core/config"
corelog "github.com/DataDog/datadog-agent/comp/core/log"
"github.com/DataDog/datadog-agent/comp/core/secrets"
"github.com/DataDog/datadog-agent/comp/core/secrets/secretsimpl"
"github.com/DataDog/datadog-agent/comp/core/workloadmeta"
"github.com/DataDog/datadog-agent/comp/core/workloadmeta/collectors"
"github.com/DataDog/datadog-agent/comp/trace"
Expand Down Expand Up @@ -64,6 +65,7 @@ func runFx(ctx context.Context, cliParams *RunParams, defaultConfPath string) er
// to allow the agent to work as a service.
fx.Provide(func() context.Context { return ctx }), // fx.Supply(ctx) fails with a missing type error.
fx.Supply(coreconfig.NewAgentParams(cliParams.ConfPath)),
secretsimpl.Module,
fx.Supply(secrets.NewEnabledParams()),
coreconfig.Module,
fx.Provide(func() corelog.Params {
Expand Down
2 changes: 1 addition & 1 deletion cmd/trace-agent/test/testsuite/secrets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestSecrets(t *testing.T) {

// install trace-agent with -tags=secrets
binTraceAgent := filepath.Join(tmpDir, "trace-agent")
cmd := exec.Command("go", "build", "-o", binTraceAgent, "-tags=secrets", "github.com/DataDog/datadog-agent/cmd/trace-agent")
cmd := exec.Command("go", "build", "-o", binTraceAgent, "github.com/DataDog/datadog-agent/cmd/trace-agent")
cmd.Stdout = io.Discard
if err := cmd.Run(); err != nil {
t.Skip(err.Error())
Expand Down
3 changes: 2 additions & 1 deletion comp/core/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ type dependencies struct {
fx.In

Params Params
Secret secrets.Component
// secrets Component is optional, if not provided, the config will not decrypt secrets
Secret secrets.Component `optional:"true"`
}

func (d dependencies) getParams() *Params {
Expand Down
7 changes: 5 additions & 2 deletions comp/core/secrets/secretsimpl/exec_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,11 @@ func getServicePid(serviceName string) (uint32, error) {
m := &mgr.Mgr{Handle: h}
defer m.Disconnect()

hSvc, err := windows.OpenService(m.Handle, syscall.StringToUTF16Ptr(serviceName),
windows.SERVICE_QUERY_STATUS)
utf16ServiceName, err := syscall.UTF16PtrFromString(serviceName)
if err != nil {
return 0, fmt.Errorf("invalid service name %s: %v", serviceName, err)
}
hSvc, err := windows.OpenService(m.Handle, utf16ServiceName, windows.SERVICE_QUERY_STATUS)
if err != nil {
return 0, fmt.Errorf("could not access service %s: %v", serviceName, err)
}
Expand Down

0 comments on commit fcc35c3

Please sign in to comment.