fix(input.redis): Discard invalid errorstat lines (#15312)
This commit is contained in:
parent
0e9b39a769
commit
7f4d27d99c
|
|
@ -665,11 +665,18 @@ func gatherErrorstatsLine(
|
|||
}
|
||||
tags["err"] = strings.TrimPrefix(name, "errorstat_")
|
||||
kv := strings.Split(line, "=")
|
||||
ival, err := strconv.ParseInt(kv[1], 10, 64)
|
||||
if err == nil {
|
||||
fields := map[string]interface{}{"total": ival}
|
||||
acc.AddFields("redis_errorstat", fields, tags)
|
||||
if len(kv) < 2 {
|
||||
acc.AddError(fmt.Errorf("invalid line for %q: %s", name, line))
|
||||
return
|
||||
}
|
||||
ival, err := strconv.ParseInt(kv[1], 10, 64)
|
||||
if err != nil {
|
||||
acc.AddError(fmt.Errorf("parsing value in line %q failed: %w", line, err))
|
||||
return
|
||||
}
|
||||
|
||||
fields := map[string]interface{}{"total": ival}
|
||||
acc.AddFields("redis_errorstat", fields, tags)
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
|
|
|||
|
|
@ -15,8 +15,7 @@ import (
|
|||
"github.com/influxdata/telegraf/testutil"
|
||||
)
|
||||
|
||||
type testClient struct {
|
||||
}
|
||||
type testClient struct{}
|
||||
|
||||
func (t *testClient) BaseTags() map[string]string {
|
||||
return map[string]string{"host": "redis.net"}
|
||||
|
|
@ -386,6 +385,24 @@ func TestRedis_ParseIntOnString(t *testing.T) {
|
|||
require.IsType(t, int64(0), clientsInTimeout)
|
||||
}
|
||||
|
||||
func TestRedis_GatherErrorstatsLine(t *testing.T) {
|
||||
var acc testutil.Accumulator
|
||||
globalTags := map[string]string{}
|
||||
|
||||
gatherErrorstatsLine("FOO", "BAR", &acc, globalTags)
|
||||
require.Len(t, acc.Errors, 1)
|
||||
require.Equal(t, "invalid line for \"FOO\": BAR", acc.Errors[0].Error())
|
||||
|
||||
acc = testutil.Accumulator{}
|
||||
gatherErrorstatsLine("FOO", "BAR=a", &acc, globalTags)
|
||||
require.Len(t, acc.Errors, 1)
|
||||
require.Equal(t, "parsing value in line \"BAR=a\" failed: strconv.ParseInt: parsing \"a\": invalid syntax", acc.Errors[0].Error())
|
||||
|
||||
acc = testutil.Accumulator{}
|
||||
gatherErrorstatsLine("FOO", "BAR=77", &acc, globalTags)
|
||||
require.Empty(t, acc.Errors)
|
||||
}
|
||||
|
||||
const testOutput = `# Server
|
||||
redis_version:6.0.9
|
||||
redis_git_sha1:00000000
|
||||
|
|
|
|||
Loading…
Reference in New Issue