Skip to content

Commit

Permalink
[NDM] Do not always log error on SNMP Autodiscovery unmarshal failure (
Browse files Browse the repository at this point in the history
  • Loading branch information
TCheruy authored Dec 20, 2024
1 parent fdd7787 commit 8b85951
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 3 additions & 1 deletion pkg/config/autodiscovery/autodiscovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"})
Expand Down
5 changes: 4 additions & 1 deletion pkg/snmp/snmp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down

0 comments on commit 8b85951

Please sign in to comment.