]> git.ipfire.org Git - thirdparty/collectd.git/commitdiff
write_prometheus plugin: Remove invalid characers from the unit. 4220/head
authorFlorian Forster <octo@collectd.org>
Fri, 29 Dec 2023 16:07:24 +0000 (17:07 +0100)
committerFlorian Forster <octo@collectd.org>
Fri, 29 Dec 2023 16:07:24 +0000 (17:07 +0100)
src/write_prometheus.c
src/write_prometheus_test.c

index f4f28eb02a16c098c06bf232d58fc521a8230db0..fd663c4d0e6cfbd8db5b7f579d01a890fbad8ea8 100644 (file)
@@ -263,7 +263,8 @@ void format_metric_family_name(strbuf_t *buf, metric_family_t const *fam) {
   if (unit != NULL) {
     strbuf_printf(buf, "_%s", unit->prometheus);
   } else if (fam->unit != NULL && fam->unit[0] != '{') {
-    strbuf_printf(buf, "_%s", fam->unit);
+    strbuf_print(buf, "_");
+    strbuf_print_restricted(buf, fam->unit, VALID_NAME_CHARS, '_');
   }
 
   if (fam->type == METRIC_TYPE_COUNTER) {
index 61d1de5cfccd9f76a099d5a262096d7fc1f1ec56..386d1eabef3848412766937c18bc9e30191fa3d5 100644 (file)
@@ -108,14 +108,15 @@ DEF_TEST(format_metric_family_name) {
           .unit = "%",
           .want = "storage_filesystem_utilization_percent",
       },
-      /* Not yet supported:
       {
           .name = "astro.light.speed",
           .type = METRIC_TYPE_GAUGE,
           .unit = "m/s",
+          .want = "astro_light_speed_m_s",
+          /* Not yet supported. Should be:
           .want = "astro_light_speed_meters_per_second",
+          */
       },
-      */
   };
 
   for (size_t i = 0; i < STATIC_ARRAY_SIZE(cases); i++) {