]> git.ipfire.org Git - thirdparty/collectd.git/commitdiff
Special case NaN double values for GAUGE metrics. 3226/head
authorJaroslaw Przybylowicz <jaroslaw.przybylowicz@gmail.com>
Fri, 19 Jul 2019 17:12:55 +0000 (17:12 +0000)
committerJaroslaw Przybylowicz <jaroslaw.przybylowicz@gmail.com>
Fri, 19 Jul 2019 17:12:55 +0000 (17:12 +0000)
JSON does not support NaN values and the Stackdriver POST requests are malformed becuase of cutting the request in the middle.
This change special-cases NaN values and prevents them from being written to the backend.

src/utils/format_stackdriver/format_stackdriver.c

index ccb1c77deed6920c2adbc291008286d6d6e32154..3c45aacb42192dd2e0522178168b0950691f807c 100644 (file)
@@ -30,6 +30,7 @@
 #include "utils_cache.h"
 #include "utils_time.h"
 
+#include <math.h>
 #include <yajl/yajl_gen.h>
 #include <yajl/yajl_parse.h>
 #if HAVE_YAJL_YAJL_VERSION_H
@@ -411,6 +412,12 @@ static int format_time_series(yajl_gen gen, data_set_t const *ds,
     /* for cumulative metrics, the interval must not be zero. */
     return EAGAIN;
   }
+  if (ds_type == DS_TYPE_GAUGE) {
+    double d = (double)vl->values[ds_index].gauge;
+    if (isnan(d) || isinf(d)) {
+      return EAGAIN;
+    }
+  }
 
   yajl_gen_map_open(gen);
 
@@ -564,7 +571,7 @@ int sd_output_add(sd_output_t *out, data_set_t const *ds,
   for (size_t i = 0; i < ds->ds_num; i++) {
     int status = format_time_series(out->gen, ds, vl, i, out->res);
     if (status == EAGAIN) {
-      /* first instance of a cumulative metric */
+      /* first instance of a cumulative metric or NaN value */
       continue;
     }
     if (status != 0) {