]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
hs: Fix multiple port label on single metric
authorDavid Goulet <dgoulet@torproject.org>
Tue, 8 Mar 2022 18:50:34 +0000 (13:50 -0500)
committerDavid Goulet <dgoulet@torproject.org>
Tue, 8 Mar 2022 18:50:34 +0000 (13:50 -0500)
Prometheus needs unique labels and so this bug was causing an onion
service with multiple ports to have multiple "port=" label for the
metrics requiring a port label.

Fixes #40581

Signed-off-by: David Goulet <dgoulet@torproject.org>
changes/ticket40581 [new file with mode: 0644]
src/feature/hs/hs_metrics.c

diff --git a/changes/ticket40581 b/changes/ticket40581
new file mode 100644 (file)
index 0000000..315215d
--- /dev/null
@@ -0,0 +1,4 @@
+  o Minor bugfixes (metrics port, onion service):
+    - Fix the metrics with a port label to be unique. Before this, all ports of
+      an onion service would be on the same line which violates the Prometheus
+      rules of unique labels. Fixes bug 40581; bugfix on 0.4.5.1-alpha.
index 0f1824c51cf83f9a25ee55cf5f3edc7439ad934d..e80d98c2ddcd58b967b935ff249f3e161130fa56 100644 (file)
@@ -43,19 +43,26 @@ init_store(hs_service_t *service)
   store = service->metrics.store;
 
   for (size_t i = 0; i < base_metrics_size; ++i) {
-    metrics_store_entry_t *entry =
-      metrics_store_add(store, base_metrics[i].type, base_metrics[i].name,
-                        base_metrics[i].help);
-
-    /* Add labels to the entry. */
-    metrics_store_entry_add_label(entry,
-                  metrics_format_label("onion", service->onion_address));
+    /* Add entries with port as label. We need one metric line per port. */
     if (base_metrics[i].port_as_label && service->config.ports) {
       SMARTLIST_FOREACH_BEGIN(service->config.ports,
                               const hs_port_config_t *, p) {
+        metrics_store_entry_t *entry =
+          metrics_store_add(store, base_metrics[i].type, base_metrics[i].name,
+                            base_metrics[i].help);
+
+        /* Add labels to the entry. */
+        metrics_store_entry_add_label(entry,
+                metrics_format_label("onion", service->onion_address));
         metrics_store_entry_add_label(entry,
                 metrics_format_label("port", port_to_str(p->virtual_port)));
       } SMARTLIST_FOREACH_END(p);
+    } else {
+      metrics_store_entry_t *entry =
+        metrics_store_add(store, base_metrics[i].type, base_metrics[i].name,
+                          base_metrics[i].help);
+      metrics_store_entry_add_label(entry,
+              metrics_format_label("onion", service->onion_address));
     }
   }
 }