Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandreYang committed Mar 6, 2025
1 parent 936a28a commit ac21a17
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
3 changes: 1 addition & 2 deletions cmd/system-probe/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,7 @@ func load() (*types.Config, error) {
if cfg.GetBool(pngNS("enabled")) {
c.EnabledModules[PingModule] = struct{}{}
}
// TODO: add test
if cfg.GetBool(tracerouteNS("enabled")) || cfg.GetBool("network_path.connections_monitoring.enabled") {
if cfg.GetBool(tracerouteNS("enabled")) || cfg.GetBool(npNS("connections_monitoring.enabled")) {
c.EnabledModules[TracerouteModule] = struct{}{}
}
if cfg.GetBool(discoveryNS("enabled")) {
Expand Down
26 changes: 26 additions & 0 deletions cmd/system-probe/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,29 @@ func TestEnableDiscovery(t *testing.T) {
assert.False(t, cfg.GetBool(discoveryNS("enabled")))
})
}

func TestNetworkPath(t *testing.T) {
mock.NewSystemProbe(t)

for i, tc := range []struct {
traceroute, connectionsMonitoring bool
usmEvents bool
enabled bool
}{
{traceroute: false, connectionsMonitoring: false, enabled: false},
{traceroute: true, connectionsMonitoring: false, enabled: true},
{traceroute: true, connectionsMonitoring: true, enabled: true},
{traceroute: false, connectionsMonitoring: true, enabled: true},
} {
t.Run(fmt.Sprintf("index_%d", i), func(t *testing.T) {
t.Logf("%+v\n", tc)
t.Setenv("DD_TRACEROUTE_ENABLED", strconv.FormatBool(tc.traceroute))
t.Setenv("DD_NETWORK_PATH_CONNECTIONS_MONITORING_ENABLED", strconv.FormatBool(tc.connectionsMonitoring))

cfg, err := New("/doesnotexist", "")
t.Logf("%+v\n", cfg)
require.NoError(t, err)
assert.Equal(t, tc.enabled, cfg.ModuleIsEnabled(TracerouteModule))
})
}
}
5 changes: 5 additions & 0 deletions cmd/system-probe/config/ns.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ func tracerouteNS(k ...string) string {
return NSkey("traceroute", k...)
}

// npNS adds `network_path` namespace to config key
func npNS(k ...string) string {
return NSkey("network_path", k...)
}

// discoveryNS adds `discovery` namespace to config key
func discoveryNS(k ...string) string {
return NSkey("discovery", k...)
Expand Down
4 changes: 3 additions & 1 deletion pkg/config/setup/system_probe.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const (
wcdNS = "windows_crash_detection"
pngNS = "ping"
tracerouteNS = "traceroute"
npNS = "network_path"
discoveryNS = "discovery"
gpuNS = "gpu_monitoring"
defaultConnsMessageBatchSize = 600
Expand Down Expand Up @@ -412,8 +413,9 @@ func InitSystemProbeConfig(cfg pkgconfigmodel.Config) {
// Ping
cfg.BindEnvAndSetDefault(join(pngNS, "enabled"), false)

// Traceroute
// Traceroute / Network Path
cfg.BindEnvAndSetDefault(join(tracerouteNS, "enabled"), false)
cfg.BindEnvAndSetDefault(join(npNS, "connections_monitoring.enabled"), false)

// CCM config
cfg.BindEnvAndSetDefault(join(ccmNS, "enabled"), false)
Expand Down

0 comments on commit ac21a17

Please sign in to comment.