Fix inconsistency with input error counting (#7077)

This commit is contained in:
Steven Soroka
2020-02-25 13:40:29 -05:00
committed by GitHub
parent fc2486f24c
commit 2e32f894b6
11 changed files with 115 additions and 85 deletions

View File

@@ -4,6 +4,8 @@ import (
"testing"
"time"
"github.com/influxdata/telegraf/selfstat"
"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/metric"
"github.com/influxdata/telegraf/testutil"
@@ -256,6 +258,35 @@ func TestMakeMetricNameSuffix(t *testing.T) {
require.Equal(t, expected, m)
}
func TestMetricErrorCounters(t *testing.T) {
ri := NewRunningInput(&testInput{}, &InputConfig{
Name: "TestMetricErrorCounters",
})
getGatherErrors := func() int64 {
for _, r := range selfstat.Metrics() {
tag, hasTag := r.GetTag("input")
if r.Name() == "internal_gather" && hasTag && tag == "TestMetricErrorCounters" {
errCount, ok := r.GetField("errors")
if !ok {
t.Fatal("Expected error field")
}
return errCount.(int64)
}
}
return 0
}
before := getGatherErrors()
ri.Log().Error("Oh no")
after := getGatherErrors()
require.Greater(t, after, before)
require.GreaterOrEqual(t, int64(1), GlobalGatherErrors.Get())
}
type testInput struct{}
func (t *testInput) Description() string { return "" }