]> git.ipfire.org Git - thirdparty/collectd.git/commitdiff
Extended metric_family unit test to also test new format_metric_distribution function.
authorelene-margalit <elene.margalit@gmail.com>
Thu, 27 Aug 2020 22:10:36 +0000 (00:10 +0200)
committerelene-margalit <elene.margalit@gmail.com>
Thu, 27 Aug 2020 22:10:36 +0000 (00:10 +0200)
src/utils/format_json/format_json_test.c

index 756a3104d67c405fd309d7acaaa0e388a243c1bf..159747318634baf57c9e2a2476eb2895e357d6b6 100644 (file)
@@ -198,6 +198,41 @@ DEF_TEST(metric_family) {
             "{\"timestamp_ms\":\"1592987324125\",\"value\":\"42\"}"
             "]}]",
     },
+    {
+        .identity = "distribution_metric",
+        .value.distribution = distribution_new_linear(2, 20),
+        .type = METRIC_TYPE_DISTRIBUTION,
+        .time = MS_TO_CDTIME_T(1592987324125),
+        .want =
+            "[{\"name\":\"distribution_metric\",\"type\":\"DISTRIBUTION\",\"metrics\":["
+            "{\"timestamp_ms\":\"1592987324125\",\"buckets\":"
+            "{\"20.00\":\"0\",\"inf\":\"0\"},\"count\":\"0\",\"sum\":\"0\""
+            "}]}]",
+    },
+    {
+        .identity = "distribution_metric",
+        .value.distribution = distribution_new_exponential(10, 2, 3),
+        .type = METRIC_TYPE_DISTRIBUTION,
+        .time = MS_TO_CDTIME_T(1592987324125),
+        .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\"},"
+            "\"count\":\"0\",\"sum\":\"0\""
+            "}]}]",
+    },
+    {
+        .identity = "distribution_metric",
+        .value.distribution = distribution_new_custom(4, (double[]){3, 10, 50, 100}),
+        .type = METRIC_TYPE_DISTRIBUTION,
+        .time = MS_TO_CDTIME_T(1592987324125),
+        .want =
+            "[{\"name\":\"distribution_metric\",\"type\":\"DISTRIBUTION\",\"metrics\":["
+            "{\"timestamp_ms\":\"1592987324125\",\"buckets\":"
+            "{\"3.00\":\"0\",\"10.00\":\"0\",\"50.00\":\"0\",\"100.00\":\"0\",\"inf\":\"0\"},"
+            "\"count\":\"0\",\"sum\":\"0\""
+            "}]}]",
+    },
 #if 0
       {
           .identity = "derive_max",
@@ -231,7 +266,12 @@ DEF_TEST(metric_family) {
     CHECK_NOT_NULL(m = metric_parse_identity(cases[i].identity));
 
     m->family->type = cases[i].type;
-    m->value = cases[i].value;
+    if(m->family != NULL && m->family->type == METRIC_TYPE_DISTRIBUTION) {
+        m->value.distribution = cases[i].value.distribution;
+    }
+    else {
+        m->value = cases[i].value;
+    }
     m->time = cases[i].time;
     m->interval = cases[i].interval;