Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't stop parsing after statsd parsing error #9423

Merged
merged 1 commit into from
Jun 24, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 13 additions & 7 deletions plugins/inputs/statsd/statsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package statsd
import (
"bufio"
"bytes"
"errors"
"fmt"
"net"
"sort"
Expand All @@ -18,6 +17,7 @@ import (
"github.com/influxdata/telegraf/plugins/inputs"
"github.com/influxdata/telegraf/plugins/parsers/graphite"
"github.com/influxdata/telegraf/selfstat"
"github.com/pkg/errors"
)

const (
Expand All @@ -35,6 +35,8 @@ const (
parserGoRoutines = 5
)

var errParsing = errors.New("error parsing statsd line")

// Statsd allows the importing of statsd and dogstatsd data.
type Statsd struct {
// Protocol used on listener - udp or tcp
Expand Down Expand Up @@ -568,6 +570,10 @@ func (s *Statsd) parser() error {
}
default:
if err := s.parseStatsdLine(line); err != nil {
if errors.Cause(err) == errParsing {
// parsing errors log when the error occurs
continue
}
return err
}
}
Expand Down Expand Up @@ -605,7 +611,7 @@ func (s *Statsd) parseStatsdLine(line string) error {
bits := strings.Split(line, ":")
if len(bits) < 2 {
s.Log.Errorf("Splitting ':', unable to parse metric: %s", line)
return errors.New("error Parsing statsd line")
return errParsing
}

// Extract bucket name from individual metric bits
Expand All @@ -621,7 +627,7 @@ func (s *Statsd) parseStatsdLine(line string) error {
pipesplit := strings.Split(bit, "|")
if len(pipesplit) < 2 {
s.Log.Errorf("Splitting '|', unable to parse metric: %s", line)
return errors.New("error parsing statsd line")
return errParsing
} else if len(pipesplit) > 2 {
sr := pipesplit[2]

Expand All @@ -645,14 +651,14 @@ func (s *Statsd) parseStatsdLine(line string) error {
m.mtype = pipesplit[1]
default:
s.Log.Errorf("Metric type %q unsupported", pipesplit[1])
return errors.New("error parsing statsd line")
return errParsing
}

// Parse the value
if strings.HasPrefix(pipesplit[0], "-") || strings.HasPrefix(pipesplit[0], "+") {
if m.mtype != "g" && m.mtype != "c" {
s.Log.Errorf("+- values are only supported for gauges & counters, unable to parse metric: %s", line)
return errors.New("error parsing statsd line")
return errParsing
}
m.additive = true
}
Expand All @@ -662,7 +668,7 @@ func (s *Statsd) parseStatsdLine(line string) error {
v, err := strconv.ParseFloat(pipesplit[0], 64)
if err != nil {
s.Log.Errorf("Parsing value to float64, unable to parse metric: %s", line)
return errors.New("error parsing statsd line")
return errParsing
}
m.floatvalue = v
case "c":
Expand All @@ -672,7 +678,7 @@ func (s *Statsd) parseStatsdLine(line string) error {
v2, err2 := strconv.ParseFloat(pipesplit[0], 64)
if err2 != nil {
s.Log.Errorf("Parsing value to int64, unable to parse metric: %s", line)
return errors.New("error parsing statsd line")
return errParsing
}
v = int64(v2)
}
Expand Down