diff options
author | Gabriela Moldovan <gabi@torproject.org> | 2023-02-15 14:52:35 +0000 |
---|---|---|
committer | David Goulet <dgoulet@torproject.org> | 2023-03-07 09:46:05 -0500 |
commit | 16c6788fbc30cf0a2611dd021d1797931a53a86d (patch) | |
tree | 10486dd6918e9c97c85fc1539abe6bfec0f5a3ff /src/lib/metrics | |
parent | 119b84c365da867a6dcb85877f1d13dcf06c59a4 (diff) | |
download | tor-16c6788fbc30cf0a2611dd021d1797931a53a86d.tar.gz tor-16c6788fbc30cf0a2611dd021d1797931a53a86d.zip |
metrics: Add a `reason` label to the HS error metrics.
This adds a `reason` label to the `hs_intro_rejected_intro_req_count` and
`hs_rdv_error_count` metrics introduced in #40755.
Metric look up and intialization is now more a bit more involved. This may be
fine for now, but it will become unwieldy if/when we add more labels (and as
such will need to be refactored).
Also, in the future, we may want to introduce finer grained `reason` labels.
For example, the `invalid_introduce2` label actually covers multiple types of
errors that can happen during the processing of an INTRODUCE2 cell (such as
cell parse errors, replays, decryption errors).
Signed-off-by: Gabriela Moldovan <gabi@torproject.org>
Diffstat (limited to 'src/lib/metrics')
-rw-r--r-- | src/lib/metrics/metrics_store_entry.c | 20 | ||||
-rw-r--r-- | src/lib/metrics/metrics_store_entry.h | 3 |
2 files changed, 23 insertions, 0 deletions
diff --git a/src/lib/metrics/metrics_store_entry.c b/src/lib/metrics/metrics_store_entry.c index 482ec8d7d9..971d9379bd 100644 --- a/src/lib/metrics/metrics_store_entry.c +++ b/src/lib/metrics/metrics_store_entry.c @@ -127,3 +127,23 @@ metrics_store_entry_has_label(const metrics_store_entry_t *entry, return smartlist_contains_string(entry->labels, label); } + +/** Return the first entry that has the given label, or NULL if none + * of the entries have the label. */ +metrics_store_entry_t * +metrics_store_find_entry_with_label(const smartlist_t *entries, + const char *label) +{ + tor_assert(entries); + tor_assert(label); + + SMARTLIST_FOREACH_BEGIN(entries, metrics_store_entry_t *, entry) { + tor_assert(entry); + + if (smartlist_contains_string(entry->labels, label)) { + return entry; + } + } SMARTLIST_FOREACH_END(entry); + + return NULL; +} diff --git a/src/lib/metrics/metrics_store_entry.h b/src/lib/metrics/metrics_store_entry.h index e4dc7a8b9a..0e09e099fe 100644 --- a/src/lib/metrics/metrics_store_entry.h +++ b/src/lib/metrics/metrics_store_entry.h @@ -12,6 +12,7 @@ #include "lib/cc/torint.h" #include "lib/metrics/metrics_common.h" +#include "lib/container/smartlist.h" #ifdef METRICS_STORE_ENTRY_PRIVATE @@ -57,6 +58,8 @@ void metrics_store_entry_free_(metrics_store_entry_t *entry); int64_t metrics_store_entry_get_value(const metrics_store_entry_t *entry); bool metrics_store_entry_has_label(const metrics_store_entry_t *entry, const char *label); +metrics_store_entry_t *metrics_store_find_entry_with_label( + const smartlist_t *entries, const char *label); /* Modifiers. */ void metrics_store_entry_add_label(metrics_store_entry_t *entry, |