test: add integration test for recovering after invalid data (#11994)

This commit is contained in:
Joshua Powers 2022-10-12 14:59:47 -05:00 committed by GitHub
parent fd532494ce
commit a915d2c20c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 52 additions and 0 deletions

View File

@ -1770,3 +1770,55 @@ func TestParseNoSanitize(t *testing.T) {
require.Equalf(t, name, test.outName, "Expected: %s, got %s", test.outName, name)
}
}
func TestParse_InvalidAndRecoverIntegration(t *testing.T) {
statsd := Statsd{
Log: testutil.Logger{},
Protocol: "tcp",
ServiceAddress: "localhost:8125",
AllowedPendingMessages: 10000,
MaxTCPConnections: 250,
TCPKeepAlive: true,
}
acc := &testutil.Accumulator{}
require.NoError(t, statsd.Start(acc))
defer statsd.Stop()
addr := statsd.TCPlistener.Addr().String()
conn, err := net.Dial("tcp", addr)
require.NoError(t, err)
// first write an invalid line
_, err = conn.Write([]byte("test.service.stat.missing_value:|h\n"))
require.NoError(t, err)
// pause to let statsd to parse the metric and force a collection interval
time.Sleep(100 * time.Millisecond)
require.NoError(t, statsd.Gather(acc))
// then verify we can write a valid line, service recovered
_, err = conn.Write([]byte("cpu.time_idle:42|c\n"))
require.NoError(t, err)
time.Sleep(100 * time.Millisecond)
require.NoError(t, statsd.Gather(acc))
acc.Wait(1)
expected := []telegraf.Metric{
testutil.MustMetric(
"cpu_time_idle",
map[string]string{
"metric_type": "counter",
},
map[string]interface{}{
"value": 42,
},
time.Now(),
telegraf.Counter,
),
}
testutil.RequireMetricsEqual(t, expected, acc.GetTelegrafMetrics(), testutil.IgnoreTime())
require.NoError(t, conn.Close())
}