Fix crash when allow pending messgae wasn't set (#1785)
The default is 0 so we hit a division by 0 error and crash. This checks ensure we will not crash and `log` and continue to let telegraf run Also we set default allow pending message number to 10000
This commit is contained in:
parent
9ea3dbeee8
commit
1d10eda84e
|
@ -25,6 +25,7 @@ const (
|
||||||
defaultFieldName = "value"
|
defaultFieldName = "value"
|
||||||
|
|
||||||
defaultSeparator = "_"
|
defaultSeparator = "_"
|
||||||
|
defaultAllowPendingMessage = 10000
|
||||||
)
|
)
|
||||||
|
|
||||||
var dropwarn = "ERROR: statsd message queue full. " +
|
var dropwarn = "ERROR: statsd message queue full. " +
|
||||||
|
@ -297,7 +298,7 @@ func (s *Statsd) udpListen() error {
|
||||||
case s.in <- bufCopy:
|
case s.in <- bufCopy:
|
||||||
default:
|
default:
|
||||||
s.drops++
|
s.drops++
|
||||||
if s.drops == 1 || s.drops%s.AllowedPendingMessages == 0 {
|
if s.drops == 1 || s.AllowedPendingMessages == 0 || s.drops%s.AllowedPendingMessages == 0 {
|
||||||
log.Printf(dropwarn, s.drops)
|
log.Printf(dropwarn, s.drops)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -651,6 +652,7 @@ func init() {
|
||||||
inputs.Add("statsd", func() telegraf.Input {
|
inputs.Add("statsd", func() telegraf.Input {
|
||||||
return &Statsd{
|
return &Statsd{
|
||||||
MetricSeparator: "_",
|
MetricSeparator: "_",
|
||||||
|
AllowedPendingMessages: defaultAllowPendingMessage,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue