Skip to content

Commit

Permalink
Fix retries in generator (#786)
Browse files Browse the repository at this point in the history
Fix parsing of `0` in retries in the generator config by making the
struct value a pointer[0].

Fixes: #785

[0]: https://www.sohamkamani.com/golang/omitempty/#the-difference-between-0--and-nil

Signed-off-by: SuperQ <[email protected]>
  • Loading branch information
SuperQ authored Aug 4, 2022
1 parent a7b1ccb commit 74f0ae5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func ScrapeTarget(ctx context.Context, target string, config *config.Module, log
snmp := gosnmp.GoSNMP{}
snmp.Context = ctx
snmp.MaxRepetitions = config.WalkParams.MaxRepetitions
snmp.Retries = config.WalkParams.Retries
snmp.Retries = *config.WalkParams.Retries
snmp.Timeout = config.WalkParams.Timeout
snmp.UseUnconnectedUDPSocket = config.WalkParams.UseUnconnectedUDPSocket
snmp.LocalAddr = *srcAddress
Expand Down
6 changes: 4 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ func LoadFile(filename string) (*Config, error) {
}

var (
defaultRetries int = 3

DefaultAuth = Auth{
Community: "public",
SecurityLevel: "noAuthNoPriv",
Expand All @@ -46,7 +48,7 @@ var (
DefaultWalkParams = WalkParams{
Version: 2,
MaxRepetitions: 25,
Retries: 3,
Retries: &defaultRetries,
Timeout: time.Second * 5,
Auth: DefaultAuth,
UseUnconnectedUDPSocket: false,
Expand All @@ -66,7 +68,7 @@ type Config map[string]*Module
type WalkParams struct {
Version int `yaml:"version,omitempty"`
MaxRepetitions uint32 `yaml:"max_repetitions,omitempty"`
Retries int `yaml:"retries,omitempty"`
Retries *int `yaml:"retries,omitempty"`
Timeout time.Duration `yaml:"timeout,omitempty"`
Auth Auth `yaml:"auth,omitempty"`
UseUnconnectedUDPSocket bool `yaml:"use_unconnected_udp_socket,omitempty"`
Expand Down

0 comments on commit 74f0ae5

Please sign in to comment.