From: Florian Forster Date: Tue, 26 Dec 2023 07:14:39 +0000 (+0100) Subject: write_prometheus plugin: Insert a newline between metric families. X-Git-Tag: 6.0.0-rc0~23^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=53111bc5c01657c6a4fd22b7d85dce2dfc85f7d0;p=thirdparty%2Fcollectd.git write_prometheus plugin: Insert a newline between metric families. --- diff --git a/src/write_prometheus.c b/src/write_prometheus.c index a09aab65f..1054697b4 100644 --- a/src/write_prometheus.c +++ b/src/write_prometheus.c @@ -248,8 +248,9 @@ void format_metric_family(strbuf_t *buf, metric_family_t const *prom_fam) { strbuf_printf(buf, "\n"); } } - STRBUF_DESTROY(family_name); + + strbuf_printf(buf, "\n"); } /* target_info prints a special "info" metric that contains all the "target @@ -301,8 +302,8 @@ static void format_text(strbuf_t *buf) { } c_avl_iterator_destroy(iter); - strbuf_printf(buf, "\n# collectd/write_prometheus %s at %s\n", - PACKAGE_VERSION, hostname_g); + strbuf_printf(buf, "# collectd/write_prometheus %s at %s\n", PACKAGE_VERSION, + hostname_g); pthread_mutex_unlock(&prom_metrics_lock); } diff --git a/src/write_prometheus_test.c b/src/write_prometheus_test.c index 851430e05..4391e9122 100644 --- a/src/write_prometheus_test.c +++ b/src/write_prometheus_test.c @@ -127,7 +127,8 @@ DEF_TEST(format_metric_family) { }, .want = "# HELP unit_test_total\n" "# TYPE unit_test_total counter\n" - "unit_test_total 42\n", + "unit_test_total 42\n" + "\n", }, { .name = "metric with one label", @@ -158,7 +159,8 @@ DEF_TEST(format_metric_family) { }, .want = "# HELP unittest\n" "# TYPE unittest gauge\n" - "unittest{foo=\"bar\"} 42\n", + "unittest{foo=\"bar\"} 42\n" + "\n", }, { .name = "invalid characters are replaced", @@ -189,7 +191,8 @@ DEF_TEST(format_metric_family) { }, .want = "# HELP unit_test\n" "# TYPE unit_test untyped\n" - "unit_test{metric_name=\"unit.test\"} 42\n", + "unit_test{metric_name=\"unit.test\"} 42\n" + "\n", }, { .name = "most resource attributes are ignored", @@ -231,7 +234,8 @@ DEF_TEST(format_metric_family) { .want = "# HELP unit_test\n" "# TYPE unit_test untyped\n" "unit_test{job=\"service name\",instance=\"service instance " - "id\",metric_name=\"unit.test\"} 42\n", + "id\",metric_name=\"unit.test\"} 42\n" + "\n", }, };