aboutsummaryrefslogtreecommitdiff
path: root/src/feature/hs/hs_metrics.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/feature/hs/hs_metrics.c')
-rw-r--r--src/feature/hs/hs_metrics.c29
1 files changed, 20 insertions, 9 deletions
diff --git a/src/feature/hs/hs_metrics.c b/src/feature/hs/hs_metrics.c
index e6d3084f26..25e2e62111 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;
}
@@ -55,19 +59,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,
- 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 rend_service_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,
+ format_label("onion", service->onion_address));
metrics_store_entry_add_label(entry,
- format_label("port", port_to_str(p->virtual_port)));
+ 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,
+ format_label("onion", service->onion_address));
}
}
}