]> git.ipfire.org Git - thirdparty/collectd.git/commitdiff
Changed string formatting in function format_metric_distribution and adjusted unit...
authorelene-margalit <elene.margalit@gmail.com>
Tue, 1 Sep 2020 10:28:44 +0000 (12:28 +0200)
committerelene-margalit <elene.margalit@gmail.com>
Tue, 1 Sep 2020 10:28:44 +0000 (12:28 +0200)
src/utils/format_json/format_json.c
src/utils/format_json/format_json_test.c

index 6c9754ccda5e1d48146336b89795f3cb63173070..8a1092ca4d1f19f54d6cfca20a3e6b0aa30ce368 100644 (file)
@@ -126,11 +126,11 @@ static int format_metric_distribution(strbuf_t buf, yajl_gen g,
 
     double max = buckets.buckets[i].maximum;
     char max_char[32];
-    ssnprintf(max_char, sizeof(max_char), "%.2f", max);
+    ssnprintf(max_char, sizeof(max_char), GAUGE_FORMAT, max);
 
     uint64_t bucket_counter = buckets.buckets[i].bucket_counter;
     char counter_char[32];
-    ssnprintf(counter_char, sizeof(bucket_counter), "%" PRIu64, bucket_counter);
+    ssnprintf(counter_char, sizeof(counter_char), "%" PRIu64, bucket_counter);
     CHECK(json_add_string(g, max_char));
     CHECK(json_add_string(g, counter_char));
   }
index 9805cbcb225b58f92200469d7db961f50d9b2f04..cb40d9f16b677611a704f91d14d254f8d7bef7b4 100644 (file)
@@ -207,7 +207,7 @@ DEF_TEST(metric_family) {
         .want = "[{\"name\":\"distribution_metric\",\"type\":\"DISTRIBUTION\","
                 "\"metrics\":["
                 "{\"timestamp_ms\":\"1592987324125\",\"buckets\":"
-                "{\"20.00\":\"0\",\"inf\":\"0\"},\"count\":\"0\",\"sum\":\"0\""
+                "{\"20\":\"0\",\"inf\":\"0\"},\"count\":\"0\",\"sum\":\"0\""
                 "}]}]",
     },
     {
@@ -218,9 +218,9 @@ DEF_TEST(metric_family) {
         .want = "[{\"name\":\"distribution_metric\",\"type\":\"DISTRIBUTION\","
                 "\"metrics\":["
                 "{\"timestamp_ms\":\"1592987324125\",\"buckets\":"
-                "{\"3.00\":\"0\",\"6.00\":\"0\",\"12.00\":\"0\",\"24.00\":"
-                "\"0\",\"48.00\":\"0\",\"96.00\":\"0\",\"192.00\":\"0\",\"384."
-                "00\":\"0\",\"768.00\":\"0\",\"inf\":\"0\"},"
+                "{\"3\":\"0\",\"6\":\"0\",\"12\":\"0\",\"24\":"
+                "\"0\",\"48\":\"0\",\"96\":\"0\",\"192\":\"0\",\"384\":"
+                "\"0\",\"768\":\"0\",\"inf\":\"0\"},"
                 "\"count\":\"0\",\"sum\":\"0\""
                 "}]}]",
     },
@@ -233,7 +233,7 @@ DEF_TEST(metric_family) {
         .want = "[{\"name\":\"distribution_metric\",\"type\":\"DISTRIBUTION\","
                 "\"metrics\":["
                 "{\"timestamp_ms\":\"1592987324125\",\"buckets\":"
-                "{\"3.00\":\"0\",\"10.00\":\"0\",\"50.00\":\"0\",\"100.00\":"
+                "{\"3\":\"0\",\"10\":\"0\",\"50\":\"0\",\"100\":"
                 "\"0\",\"inf\":\"0\"},"
                 "\"count\":\"0\",\"sum\":\"0\""
                 "}]}]",
@@ -335,6 +335,5 @@ int main(void) {
   RUN_TEST(notification);
   RUN_TEST(metric_family);
   RUN_TEST(metric_family_append);
-
   END_TEST;
 }