From: elene-margalit Date: Tue, 1 Sep 2020 10:28:44 +0000 (+0200) Subject: Changed string formatting in function format_metric_distribution and adjusted unit... X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=24dea8559ed114bef5298cde7d0a2a2d0ed3d6bf;p=thirdparty%2Fcollectd.git Changed string formatting in function format_metric_distribution and adjusted unit test. --- diff --git a/src/utils/format_json/format_json.c b/src/utils/format_json/format_json.c index 6c9754ccd..8a1092ca4 100644 --- a/src/utils/format_json/format_json.c +++ b/src/utils/format_json/format_json.c @@ -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)); } diff --git a/src/utils/format_json/format_json_test.c b/src/utils/format_json/format_json_test.c index 9805cbcb2..cb40d9f16 100644 --- a/src/utils/format_json/format_json_test.c +++ b/src/utils/format_json/format_json_test.c @@ -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; }