]> git.ipfire.org Git - thirdparty/collectd.git/commitdiff
write_prometheus plugin: Insert a newline between metric families.
authorFlorian Forster <octo@collectd.org>
Tue, 26 Dec 2023 07:14:39 +0000 (08:14 +0100)
committerFlorian Forster <octo@collectd.org>
Thu, 28 Dec 2023 19:13:31 +0000 (20:13 +0100)
src/write_prometheus.c
src/write_prometheus_test.c

index a09aab65fcb10c5124cb96380b65e8fd96ba8997..1054697b48c43b980eed062f06ebd57ed464ab74 100644 (file)
@@ -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);
 }
index 851430e05eb843755d26a5854695021cf1c56987..4391e9122a0d1dbf4265afe797c9dea67296088d 100644 (file)
@@ -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",
       },
   };