From 6c032202e1ec5ae62854a3db1fa2eaf9c78bfc94 Mon Sep 17 00:00:00 2001 From: Aaron Rhodes Date: Wed, 23 Oct 2024 14:37:27 -0400 Subject: [PATCH] [NDM] Fix for ignored_ip_addresses in autodiscovery (#30180) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Lénaïc Huard --- pkg/config/autodiscovery/autodiscovery.go | 7 ++++--- .../autodiscovery/autodiscovery_test.go | 19 +++++++++++++++++-- ...config-autodiscovery-49d61b77e8f76f58.yaml | 11 +++++++++++ 3 files changed, 32 insertions(+), 5 deletions(-) create mode 100644 releasenotes/notes/fix-config-autodiscovery-49d61b77e8f76f58.yaml diff --git a/pkg/config/autodiscovery/autodiscovery.go b/pkg/config/autodiscovery/autodiscovery.go index 1f1455c39761e..c1fab80232a55 100644 --- a/pkg/config/autodiscovery/autodiscovery.go +++ b/pkg/config/autodiscovery/autodiscovery.go @@ -75,10 +75,11 @@ func DiscoverComponentsFromConfig() ([]pkgconfigsetup.ConfigurationProviders, [] } // Auto-activate autodiscovery without listeners: - snmp - configs := []snmplistener.Config{} - err := pkgconfigsetup.Datadog().UnmarshalKey("network_devices.autodiscovery.configs", &configs) + snmpConfig, err := snmplistener.NewListenerConfig() - if err == nil && len(configs) > 0 { + if err != nil { + log.Errorf("Error unmarshalling snmp listener config. Error: %v", err) + } else if len(snmpConfig.Configs) > 0 { detectedListeners = append(detectedListeners, pkgconfigsetup.Listeners{Name: "snmp"}) log.Info("Configs for autodiscovery detected: Adding the snmp listener") } diff --git a/pkg/config/autodiscovery/autodiscovery_test.go b/pkg/config/autodiscovery/autodiscovery_test.go index 09a7f28ae1a04..811a72de9edf5 100644 --- a/pkg/config/autodiscovery/autodiscovery_test.go +++ b/pkg/config/autodiscovery/autodiscovery_test.go @@ -10,6 +10,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" pkgconfigsetup "github.com/DataDog/datadog-agent/pkg/config/setup" ) @@ -25,7 +26,7 @@ network_devices: `)) assert.NoError(t, err) _, configListeners := DiscoverComponentsFromConfig() - assert.Len(t, configListeners, 1) + require.Len(t, configListeners, 1) assert.Equal(t, "snmp", configListeners[0].Name) err = pkgconfigsetup.Datadog().ReadConfig(strings.NewReader(` @@ -44,5 +45,19 @@ snmp_listener: `)) assert.NoError(t, err) _, configListeners = DiscoverComponentsFromConfig() - assert.Empty(t, len(configListeners)) + require.Len(t, configListeners, 1) + assert.Equal(t, "snmp", configListeners[0].Name) + + err = pkgconfigsetup.Datadog().ReadConfig(strings.NewReader(` +network_devices: + autodiscovery: + configs: + - network_address: 127.0.0.1/30 + ignored_ip_addresses: + - 127.0.0.3 +`)) + assert.NoError(t, err) + _, configListeners = DiscoverComponentsFromConfig() + require.Len(t, configListeners, 1) + assert.Equal(t, "snmp", configListeners[0].Name) } diff --git a/releasenotes/notes/fix-config-autodiscovery-49d61b77e8f76f58.yaml b/releasenotes/notes/fix-config-autodiscovery-49d61b77e8f76f58.yaml new file mode 100644 index 0000000000000..245f2938b6efa --- /dev/null +++ b/releasenotes/notes/fix-config-autodiscovery-49d61b77e8f76f58.yaml @@ -0,0 +1,11 @@ +# Each section from every release note are combined when the +# CHANGELOG.rst is rendered. So the text needs to be worded so that +# it does not depend on any information only available in another +# section. This may mean repeating some details, but each section +# must be readable independently of the other. +# +# Each section note must be formatted as reStructuredText. +--- +fixes: + - | + Fix a bug in the config parser that broke ignored_ip_addresses from working in NDM Autodiscovery.