From 2207a91117a6dd5d29a473aa01af99e1bc90e49f Mon Sep 17 00:00:00 2001 From: Jaroslaw Przybylowicz Date: Fri, 19 Jul 2019 17:12:55 +0000 Subject: [PATCH] Special case NaN double values for GAUGE metrics. 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 | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/utils/format_stackdriver/format_stackdriver.c b/src/utils/format_stackdriver/format_stackdriver.c index ccb1c77de..3c45aacb4 100644 --- a/src/utils/format_stackdriver/format_stackdriver.c +++ b/src/utils/format_stackdriver/format_stackdriver.c @@ -30,6 +30,7 @@ #include "utils_cache.h" #include "utils_time.h" +#include #include #include #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) { -- 2.47.2