summaryrefslogtreecommitdiff
path: root/src/feature
diff options
context:
space:
mode:
authorDavid Goulet <dgoulet@torproject.org>2022-03-08 13:50:34 -0500
committerDavid Goulet <dgoulet@torproject.org>2022-03-08 13:50:34 -0500
commitf4aa985cf7b5ee0b617d235d5f121f5a1762aff2 (patch)
treec7869192136a8182a541361bc81444135b7ee155 /src/feature
parent1c3cefe2cfcd9320e5be32c9659bd4726b69fa93 (diff)
downloadtor-f4aa985cf7b5ee0b617d235d5f121f5a1762aff2.tar.gz
tor-f4aa985cf7b5ee0b617d235d5f121f5a1762aff2.zip
hs: Fix multiple port label on single metric
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>
Diffstat (limited to 'src/feature')
-rw-r--r--src/feature/hs/hs_metrics.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/src/feature/hs/hs_metrics.c b/src/feature/hs/hs_metrics.c
index 0f1824c51c..e80d98c2dd 100644
--- a/src/feature/hs/hs_metrics.c
+++ b/src/feature/hs/hs_metrics.c
@@ -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));
}
}
}