Skip to content

Commit

Permalink
JSON does not support values NaN and Inf (#7908)
Browse files Browse the repository at this point in the history
  • Loading branch information
Aladex authored Aug 6, 2020
1 parent 198f92b commit 2e751d0
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions plugins/outputs/opentsdb/opentsdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package opentsdb
import (
"fmt"
"log"
"math"
"net"
"net/url"
"regexp"
Expand Down Expand Up @@ -136,10 +137,14 @@ func (o *OpenTSDB) WriteHttp(metrics []telegraf.Metric, u *url.URL) error {
tags := cleanTags(m.Tags())

for fieldName, value := range m.Fields() {
switch value.(type) {
switch fv := value.(type) {
case int64:
case uint64:
case float64:
// JSON does not support these special values
if math.IsNaN(fv) || math.IsInf(fv, 0) {
continue
}
default:
log.Printf("D! OpenTSDB does not support metric value: [%s] of type [%T].\n", value, value)
continue
Expand Down Expand Up @@ -181,10 +186,14 @@ func (o *OpenTSDB) WriteTelnet(metrics []telegraf.Metric, u *url.URL) error {
tags := ToLineFormat(cleanTags(m.Tags()))

for fieldName, value := range m.Fields() {
switch value.(type) {
switch fv := value.(type) {
case int64:
case uint64:
case float64:
// JSON does not support these special values
if math.IsNaN(fv) || math.IsInf(fv, 0) {
continue
}
default:
log.Printf("D! OpenTSDB does not support metric value: [%s] of type [%T].\n", value, value)
continue
Expand Down

0 comments on commit 2e751d0

Please sign in to comment.