Fix inconsistency with input error counting (#7077)
This commit is contained in:
@@ -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 "" }
|
||||
|
||||
Reference in New Issue
Block a user