From 87a03f60a8ea9a99edde2276f09574581d26aa06 Mon Sep 17 00:00:00 2001 From: Thibaud Cheruy Date: Fri, 20 Dec 2024 19:03:33 +0100 Subject: [PATCH] [NDM] Do not always log error on SNMP Autodiscovery unmarshal failure (#32429) (cherry picked from commit 8b859513af058e2e0d701453b15ebd18c1b56371) --- pkg/config/autodiscovery/autodiscovery.go | 4 +++- pkg/snmp/snmp.go | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/pkg/config/autodiscovery/autodiscovery.go b/pkg/config/autodiscovery/autodiscovery.go index c1fab80232a55..e0feabf9968ff 100644 --- a/pkg/config/autodiscovery/autodiscovery.go +++ b/pkg/config/autodiscovery/autodiscovery.go @@ -9,6 +9,8 @@ package autodiscovery import ( + "errors" + "github.com/DataDog/datadog-agent/comp/core/autodiscovery/providers" "github.com/DataDog/datadog-agent/comp/core/autodiscovery/providers/names" "github.com/DataDog/datadog-agent/pkg/config/env" @@ -77,7 +79,7 @@ func DiscoverComponentsFromConfig() ([]pkgconfigsetup.ConfigurationProviders, [] // Auto-activate autodiscovery without listeners: - snmp snmpConfig, err := snmplistener.NewListenerConfig() - if err != nil { + if err != nil && !errors.Is(err, snmplistener.ErrNoConfigGiven) { log.Errorf("Error unmarshalling snmp listener config. Error: %v", err) } else if len(snmpConfig.Configs) > 0 { detectedListeners = append(detectedListeners, pkgconfigsetup.Listeners{Name: "snmp"}) diff --git a/pkg/snmp/snmp.go b/pkg/snmp/snmp.go index 8e63ad76a6d3e..db35905dbabf5 100644 --- a/pkg/snmp/snmp.go +++ b/pkg/snmp/snmp.go @@ -95,6 +95,9 @@ type intOrBoolPtr interface { *int | *bool } +// ErrNoConfigGiven is returned when the SNMP listener config was not found +var ErrNoConfigGiven = errors.New("no config given for snmp_listener") + // NewListenerConfig parses configuration and returns a built ListenerConfig func NewListenerConfig() (ListenerConfig, error) { var snmpConfig ListenerConfig @@ -114,7 +117,7 @@ func NewListenerConfig() (ListenerConfig, error) { return snmpConfig, err } } else { - return snmpConfig, errors.New("no config given for snmp_listener") + return snmpConfig, ErrNoConfigGiven } if snmpConfig.AllowedFailures == 0 && snmpConfig.AllowedFailuresLegacy != 0 {