[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/main] hs: Double quote the metrics label value



commit 3c73622f27c67eb636f19a938c5f401da8db901f
Author: David Goulet <dgoulet@xxxxxxxxxxxxxx>
Date:   Wed Feb 2 13:51:22 2022 -0500

    hs: Double quote the metrics label value
    
    Fixes #40552
    
    Signed-off-by: David Goulet <dgoulet@xxxxxxxxxxxxxx>
---
 changes/ticket40552         | 3 +++
 src/feature/hs/hs_metrics.c | 6 +++++-
 src/test/test_metrics.c     | 4 ++--
 3 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/changes/ticket40552 b/changes/ticket40552
new file mode 100644
index 0000000000..7811f3a743
--- /dev/null
+++ b/changes/ticket40552
@@ -0,0 +1,3 @@
+  o Minor bugfixes (MetricsPort, Prometheus):
+    - Add double quotes to the label values of the onion service metrics. Fixes
+      bug 40552; bugfix on 0.4.5.1-alpha.
diff --git a/src/feature/hs/hs_metrics.c b/src/feature/hs/hs_metrics.c
index e6d3084f26..452bb44419 100644
--- a/src/feature/hs/hs_metrics.c
+++ b/src/feature/hs/hs_metrics.c
@@ -32,12 +32,16 @@ port_to_str(const uint16_t port)
 /** Return a static buffer pointer that contains a formatted label on the form
  * of key=value.
  *
+ * NOTE: Important, label values MUST NOT contain double quotes else, in the
+ * case of Prometheus, it will fail with a malformed line because we force the
+ * label value to be enclosed in double quotes.
+ *
  * Subsequent call to this function invalidates the previous buffer. */
 static const char *
 format_label(const char *key, const char *value)
 {
   static char buf[128];
-  tor_snprintf(buf, sizeof(buf), "%s=%s", key, value);
+  tor_snprintf(buf, sizeof(buf), "%s=\"%s\"", key, value);
   return buf;
 }
 
diff --git a/src/test/test_metrics.c b/src/test/test_metrics.c
index 152dd99d23..58628e8483 100644
--- a/src/test/test_metrics.c
+++ b/src/test/test_metrics.c
@@ -30,8 +30,8 @@
 
 #define TEST_METRICS_ENTRY_NAME    "entryA"
 #define TEST_METRICS_ENTRY_HELP    "Description of entryA"
-#define TEST_METRICS_ENTRY_LABEL_1 "label=farfadet"
-#define TEST_METRICS_ENTRY_LABEL_2 "label=ponki"
+#define TEST_METRICS_ENTRY_LABEL_1 "label=\"farfadet\""
+#define TEST_METRICS_ENTRY_LABEL_2 "label=\"ponki\""
 
 static void
 set_metrics_port(or_options_t *options)



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits