fix: plugins/parsers/influx: avoid ParseError.Error panic (#8177)
This commit is contained in:
parent
3efec1a10c
commit
9ee87ab7c3
|
|
@ -33,9 +33,9 @@ type ParseError struct {
|
|||
|
||||
func (e *ParseError) Error() string {
|
||||
buffer := e.buf[e.LineOffset:]
|
||||
eol := strings.IndexAny(buffer, "\r\n")
|
||||
eol := strings.IndexAny(buffer, "\n")
|
||||
if eol >= 0 {
|
||||
buffer = buffer[:eol]
|
||||
buffer = strings.TrimSuffix(buffer[:eol], "\r")
|
||||
}
|
||||
if len(buffer) > maxErrorBufferSize {
|
||||
startEllipsis := true
|
||||
|
|
|
|||
|
|
@ -751,6 +751,18 @@ func TestSeriesParser(t *testing.T) {
|
|||
buf: "cpu,a=",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "error with carriage return in long line",
|
||||
input: []byte("cpu,a=" + strings.Repeat("x", maxErrorBufferSize) + "\rcd,b"),
|
||||
metrics: []telegraf.Metric{},
|
||||
err: &ParseError{
|
||||
Offset: 1031,
|
||||
LineNumber: 1,
|
||||
Column: 1032,
|
||||
msg: "parse error",
|
||||
buf: "cpu,a=" + strings.Repeat("x", maxErrorBufferSize) + "\rcd,b",
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
|
|
@ -762,6 +774,9 @@ func TestSeriesParser(t *testing.T) {
|
|||
|
||||
metrics, err := parser.Parse(tt.input)
|
||||
require.Equal(t, tt.err, err)
|
||||
if err != nil {
|
||||
require.Equal(t, tt.err.Error(), err.Error())
|
||||
}
|
||||
|
||||
require.Equal(t, len(tt.metrics), len(metrics))
|
||||
for i, expected := range tt.metrics {
|
||||
|
|
|
|||
Loading…
Reference in New Issue