Skip floats that are NaN or Inf in Datadog output. (#6198)

This commit is contained in:
Daniel Nelson
2019-08-05 14:50:29 -07:00
committed by GitHub
parent de6416ff82
commit b5710a6a21
2 changed files with 57 additions and 6 deletions

View File

@@ -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)
}