]> git.sesse.net Git - nageru/commitdiff
Fix a problem where Prometheus cannot handle negative NaNs.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Thu, 15 Jun 2017 15:21:56 +0000 (17:21 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Thu, 15 Jun 2017 16:32:57 +0000 (18:32 +0200)
metrics.cpp

index f44ced2c15a66715977b352736122442c9ba4541..fafc38915a9601732d27df973daf903f82412214 100644 (file)
@@ -118,7 +118,13 @@ string Metrics::serialize() const
                if (metric.data_type == DATA_TYPE_INT64) {
                        ss << name << " " << metric.location_int64->load() << "\n";
                } else if (metric.data_type == DATA_TYPE_DOUBLE) {
-                       ss << name << " " << metric.location_double->load() << "\n";
+                       double val = metric.location_double->load();
+                       if (isnan(val)) {
+                               // Prometheus can't handle “-nan”.
+                               ss << name << " NaN\n";
+                       } else {
+                               ss << name << " " << val << "\n";
+                       }
                } else {
                        ss << metric.location_histogram->serialize(key_and_metric.first.name, key_and_metric.first.labels);
                }