fix: elasticsearch output float handling test (#11120)

This commit is contained in:
Joshua Powers 2022-05-17 14:28:05 -06:00 committed by GitHub
parent b4b52d1a6f
commit c8796a71ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 52 additions and 24 deletions

View File

@ -159,8 +159,31 @@ func TestConnectAndWriteMetricWithNaNValueReplacement(t *testing.T) {
t.Skip("Skipping integration test in short mode")
}
tests := []struct {
floatHandle string
floatReplacement float64
expectError bool
}{
{
"none",
0.0,
true,
},
{
"drop",
0.0,
false,
},
{
"replace",
0.0,
false,
},
}
urls := []string{"http://" + testutil.GetLocalHost() + ":9200"}
for _, test := range tests {
e := &Elasticsearch{
URLs: urls,
IndexName: "test-%Y.%m.%d",
@ -170,7 +193,8 @@ func TestConnectAndWriteMetricWithNaNValueReplacement(t *testing.T) {
OverwriteTemplate: false,
HealthCheckInterval: config.Duration(time.Second * 10),
HealthCheckTimeout: config.Duration(time.Second * 1),
FloatHandling: "3.1415",
FloatHandling: test.floatHandle,
FloatReplacement: test.floatReplacement,
Log: testutil.Logger{},
}
@ -180,15 +204,19 @@ func TestConnectAndWriteMetricWithNaNValueReplacement(t *testing.T) {
testutil.TestMetric(math.Inf(-1)),
}
// Verify that we can connect to Elasticsearch
err := e.Connect()
require.NoError(t, err)
// Verify that we can fail for metric with unhandled NaN/inf/-inf values
for _, m := range metrics {
err = e.Write([]telegraf.Metric{m})
if test.expectError {
require.Error(t, err)
} else {
require.NoError(t, err)
}
}
}
}
func TestTemplateManagementEmptyTemplateIntegration(t *testing.T) {