-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Auto activate checks required by some sysprobe features #52379
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,6 @@ | ||
| ad_identifiers: | ||
| - _oom_kill | ||
|
|
||
| init_config: | ||
|
|
||
| instances: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,6 @@ | ||
| ad_identifiers: | ||
| - _tcp_queue_length | ||
|
|
||
| init_config: | ||
|
|
||
| instances: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,15 +7,27 @@ package listeners | |
|
|
||
| import ( | ||
| "github.com/DataDog/datadog-agent/comp/core/autodiscovery/integration" | ||
| sysprobeconfig "github.com/DataDog/datadog-agent/comp/core/sysprobeconfig/def" | ||
| workloadfilter "github.com/DataDog/datadog-agent/comp/core/workloadfilter/def" | ||
| workloadmeta "github.com/DataDog/datadog-agent/comp/core/workloadmeta/def" | ||
| "github.com/DataDog/datadog-agent/pkg/config/env" | ||
| "github.com/DataDog/datadog-agent/pkg/util/log" | ||
| "github.com/DataDog/datadog-agent/pkg/util/option" | ||
| ) | ||
|
|
||
| // Checks activated from configuration state (avoid double work to activate it for users) | ||
| var sysProbeConfigChecks = []struct { | ||
| adIdentifier string | ||
| configKey string | ||
| }{ | ||
| {adIdentifier: "_oom_kill", configKey: "system_probe_config.enable_oom_kill"}, | ||
| {adIdentifier: "_tcp_queue_length", configKey: "system_probe_config.enable_tcp_queue_length"}, | ||
| } | ||
|
|
||
| // EnvironmentListener implements a ServiceListener based on current environment | ||
| type EnvironmentListener struct { | ||
| newService chan<- Service | ||
| newService chan<- Service | ||
| sysProbeConfig option.Option[sysprobeconfig.Component] | ||
| } | ||
|
|
||
| // EnvironmentService represents services generated from EnvironmentListener | ||
|
|
@@ -27,8 +39,8 @@ type EnvironmentService struct { | |
| var _ Service = &EnvironmentService{} | ||
|
|
||
| // NewEnvironmentListener creates an EnvironmentListener | ||
| func NewEnvironmentListener(ServiceListernerDeps) (ServiceListener, error) { | ||
| return &EnvironmentListener{}, nil | ||
| func NewEnvironmentListener(deps ServiceListernerDeps) (ServiceListener, error) { | ||
| return &EnvironmentListener{sysProbeConfig: deps.SysProbeConfig}, nil | ||
| } | ||
|
|
||
| // Listen starts the goroutine to detect checks based on environment | ||
|
|
@@ -69,6 +81,16 @@ func (l *EnvironmentListener) createServices() { | |
| log.Infof("Listener created container service from environment") | ||
| l.newService <- &EnvironmentService{adIdentifier: "_container"} | ||
| } | ||
|
|
||
| // Handle checks auto-activated from system-probe configuration state. | ||
| if sysProbeConfig, ok := l.sysProbeConfig.Get(); ok { | ||
| for _, check := range sysProbeConfigChecks { | ||
| if sysProbeConfig.GetBool(check.configKey) { | ||
| log.Infof("Listener created %s service from system-probe configuration", check.adIdentifier) | ||
| l.newService <- &EnvironmentService{adIdentifier: check.adIdentifier} | ||
|
Comment on lines
+86
to
+90
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When Useful? React with 👍 / 👎. |
||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Equal returns whether the two EnvironmentService are equal | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| // Unless explicitly stated otherwise all files in this repository are licensed | ||
| // under the Apache License Version 2.0. | ||
| // This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
| // Copyright 2017-present Datadog, Inc. | ||
|
|
||
| package listeners | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
|
|
||
| sysprobeconfig "github.com/DataDog/datadog-agent/comp/core/sysprobeconfig/def" | ||
| sysprobeconfigmock "github.com/DataDog/datadog-agent/comp/core/sysprobeconfig/mock" | ||
| "github.com/DataDog/datadog-agent/pkg/util/option" | ||
| ) | ||
|
|
||
| // collectEnvironmentServices runs createServices synchronously and returns the AD | ||
| // identifiers of the emitted services. | ||
| func collectEnvironmentServices(l *EnvironmentListener) []string { | ||
| ch := make(chan Service, 16) | ||
| l.newService = ch | ||
| l.createServices() | ||
| close(ch) | ||
|
|
||
| var ids []string | ||
| for svc := range ch { | ||
| ids = append(ids, svc.GetServiceID()) | ||
| } | ||
| return ids | ||
| } | ||
|
|
||
| func TestEnvironmentListenerSysProbeChecks(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| overrides map[string]any | ||
| expected []string | ||
| absent []string | ||
| }{ | ||
| { | ||
| name: "nothing enabled", | ||
| overrides: map[string]any{}, | ||
| absent: []string{"_oom_kill", "_tcp_queue_length"}, | ||
| }, | ||
| { | ||
| name: "oom_kill enabled", | ||
| overrides: map[string]any{"system_probe_config.enable_oom_kill": true}, | ||
| expected: []string{"_oom_kill"}, | ||
| absent: []string{"_tcp_queue_length"}, | ||
| }, | ||
| { | ||
| name: "tcp_queue_length enabled", | ||
| overrides: map[string]any{"system_probe_config.enable_tcp_queue_length": true}, | ||
| expected: []string{"_tcp_queue_length"}, | ||
| absent: []string{"_oom_kill"}, | ||
| }, | ||
| { | ||
| name: "both enabled", | ||
| overrides: map[string]any{ | ||
| "system_probe_config.enable_oom_kill": true, | ||
| "system_probe_config.enable_tcp_queue_length": true, | ||
| }, | ||
| expected: []string{"_oom_kill", "_tcp_queue_length"}, | ||
| }, | ||
| } | ||
|
|
||
| for _, tc := range tests { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| sysProbeCfg := sysprobeconfigmock.NewMockWithOverrides(t, tc.overrides) | ||
| l := &EnvironmentListener{sysProbeConfig: option.New(sysProbeCfg)} | ||
|
|
||
| ids := collectEnvironmentServices(l) | ||
|
|
||
| for _, id := range tc.expected { | ||
| assert.Contains(t, ids, id) | ||
| } | ||
| for _, id := range tc.absent { | ||
| assert.NotContains(t, ids, id) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| // TestEnvironmentListenerNoSysProbeConfig ensures the listener does not panic and | ||
| // emits no system-probe based service when the sysprobeconfig component is absent. | ||
| func TestEnvironmentListenerNoSysProbeConfig(t *testing.T) { | ||
| l := &EnvironmentListener{sysProbeConfig: option.None[sysprobeconfig.Component]()} | ||
|
|
||
| ids := collectEnvironmentServices(l) | ||
|
|
||
| assert.NotContains(t, ids, "_oom_kill") | ||
| assert.NotContains(t, ids, "_tcp_queue_length") | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.