Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for opentsdb output-plugin for NaN and Inf in float64 value #7908

Merged
merged 2 commits into from
Aug 6, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like elsewhere these are serialized as null. should we be doing that instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like elsewhere these are serialized as null. should we be doing that instead?

I do not think so. I dont found any of. So. Here we have a type checking, its logical to add checking of float64 for NaN or Inf. And we have errors for NaN from 1.14 version =)

}
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