Skip floats that are NaN or Inf in Datadog output. (#6198)
This commit is contained in:
@@ -3,15 +3,15 @@ package datadog
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"math"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/influxdata/telegraf/testutil"
|
||||
|
||||
"github.com/influxdata/telegraf"
|
||||
"github.com/influxdata/telegraf/testutil"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
@@ -249,3 +249,45 @@ func TestVerifyValue(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestNaNIsSkipped(t *testing.T) {
|
||||
plugin := &Datadog{
|
||||
Apikey: "testing",
|
||||
URL: "", // No request will be sent because all fields are skipped
|
||||
}
|
||||
|
||||
err := plugin.Connect()
|
||||
require.NoError(t, err)
|
||||
|
||||
err = plugin.Write([]telegraf.Metric{
|
||||
testutil.MustMetric(
|
||||
"cpu",
|
||||
map[string]string{},
|
||||
map[string]interface{}{
|
||||
"time_idle": math.NaN(),
|
||||
},
|
||||
time.Now()),
|
||||
})
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestInfIsSkipped(t *testing.T) {
|
||||
plugin := &Datadog{
|
||||
Apikey: "testing",
|
||||
URL: "", // No request will be sent because all fields are skipped
|
||||
}
|
||||
|
||||
err := plugin.Connect()
|
||||
require.NoError(t, err)
|
||||
|
||||
err = plugin.Write([]telegraf.Metric{
|
||||
testutil.MustMetric(
|
||||
"cpu",
|
||||
map[string]string{},
|
||||
map[string]interface{}{
|
||||
"time_idle": math.Inf(0),
|
||||
},
|
||||
time.Now()),
|
||||
})
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user