fix: elasticsearch output float handling test (#11120)
This commit is contained in:
parent
b4b52d1a6f
commit
c8796a71ae
|
|
@ -159,35 +159,63 @@ func TestConnectAndWriteMetricWithNaNValueReplacement(t *testing.T) {
|
||||||
t.Skip("Skipping integration test in short mode")
|
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"}
|
urls := []string{"http://" + testutil.GetLocalHost() + ":9200"}
|
||||||
|
|
||||||
e := &Elasticsearch{
|
for _, test := range tests {
|
||||||
URLs: urls,
|
e := &Elasticsearch{
|
||||||
IndexName: "test-%Y.%m.%d",
|
URLs: urls,
|
||||||
Timeout: config.Duration(time.Second * 5),
|
IndexName: "test-%Y.%m.%d",
|
||||||
ManageTemplate: true,
|
Timeout: config.Duration(time.Second * 5),
|
||||||
TemplateName: "telegraf",
|
ManageTemplate: true,
|
||||||
OverwriteTemplate: false,
|
TemplateName: "telegraf",
|
||||||
HealthCheckInterval: config.Duration(time.Second * 10),
|
OverwriteTemplate: false,
|
||||||
HealthCheckTimeout: config.Duration(time.Second * 1),
|
HealthCheckInterval: config.Duration(time.Second * 10),
|
||||||
FloatHandling: "3.1415",
|
HealthCheckTimeout: config.Duration(time.Second * 1),
|
||||||
Log: testutil.Logger{},
|
FloatHandling: test.floatHandle,
|
||||||
}
|
FloatReplacement: test.floatReplacement,
|
||||||
|
Log: testutil.Logger{},
|
||||||
|
}
|
||||||
|
|
||||||
metrics := []telegraf.Metric{
|
metrics := []telegraf.Metric{
|
||||||
testutil.TestMetric(math.NaN()),
|
testutil.TestMetric(math.NaN()),
|
||||||
testutil.TestMetric(math.Inf(1)),
|
testutil.TestMetric(math.Inf(1)),
|
||||||
testutil.TestMetric(math.Inf(-1)),
|
testutil.TestMetric(math.Inf(-1)),
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify that we can connect to Elasticsearch
|
err := e.Connect()
|
||||||
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})
|
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
for _, m := range metrics {
|
||||||
|
err = e.Write([]telegraf.Metric{m})
|
||||||
|
|
||||||
|
if test.expectError {
|
||||||
|
require.Error(t, err)
|
||||||
|
} else {
|
||||||
|
require.NoError(t, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue