This is an automated email from the git hooks/post-receive script.
dgoulet pushed a commit to branch main in repository tor.
commit 48c67263d9b3779e1f3296564192b13b6b0895b4 Author: Micah Elizabeth Scott beth@torproject.org AuthorDate: Fri Feb 24 18:25:25 2023 -0800
hs_metrics: Proof of Work pqueue depth, suggested effort
Adds two new metrics for hs_pow, and an internal parameter within hs_metrics for implementing gauge parameters that reset before every update.
Signed-off-by: Micah Elizabeth Scott beth@torproject.org --- src/feature/hs/hs_circuit.c | 8 +++++++ src/feature/hs/hs_metrics.c | 11 ++++++--- src/feature/hs/hs_metrics.h | 47 ++++++++++++++++++++++++--------------- src/feature/hs/hs_metrics_entry.c | 12 ++++++++++ src/feature/hs/hs_metrics_entry.h | 10 ++++++--- src/feature/hs/hs_service.c | 2 ++ src/test/test_hs_metrics.c | 20 +++++++++++++---- 7 files changed, 82 insertions(+), 28 deletions(-)
diff --git a/src/feature/hs/hs_circuit.c b/src/feature/hs/hs_circuit.c index 0ac47ee19f..3684def697 100644 --- a/src/feature/hs/hs_circuit.c +++ b/src/feature/hs/hs_circuit.c @@ -791,6 +791,9 @@ handle_rend_pqueue_cb(mainloop_event_t *ev, void *arg) compare_rend_request_by_effort_, offsetof(pending_rend_t, idx));
+ hs_metrics_pow_pqueue_rdv(service, + smartlist_len(pow_state->rend_request_pqueue)); + log_notice(LD_REND, "Dequeued pending rendezvous request with effort: %u. " "Waited %d. " "Remaining requests: %u", @@ -870,6 +873,9 @@ enqueue_rend_request(const hs_service_t *service, hs_service_intro_point_t *ip, compare_rend_request_by_effort_, offsetof(pending_rend_t, idx), req);
+ hs_metrics_pow_pqueue_rdv(service, + smartlist_len(pow_state->rend_request_pqueue)); + log_notice(LD_REND, "Enqueued rendezvous request with effort: %u. " "Queued requests: %u", req->rdv_data.pow_effort, @@ -888,6 +894,8 @@ enqueue_rend_request(const hs_service_t *service, hs_service_intro_point_t *ip, if (smartlist_len(pow_state->rend_request_pqueue) >= QUEUED_REND_REQUEST_HIGH_WATER) { trim_rend_pqueue(pow_state, now); + hs_metrics_pow_pqueue_rdv(service, + smartlist_len(pow_state->rend_request_pqueue)); }
return 0; diff --git a/src/feature/hs/hs_metrics.c b/src/feature/hs/hs_metrics.c index 46c72cf539..19a330a01e 100644 --- a/src/feature/hs/hs_metrics.c +++ b/src/feature/hs/hs_metrics.c @@ -68,6 +68,8 @@ add_metric_with_labels(hs_service_t *service, hs_metrics_key_t metric, case HS_METRICS_NUM_ESTABLISHED_RDV: FALLTHROUGH; case HS_METRICS_NUM_RDV: FALLTHROUGH; case HS_METRICS_NUM_ESTABLISHED_INTRO: FALLTHROUGH; + case HS_METRICS_POW_NUM_PQUEUE_RDV: FALLTHROUGH; + case HS_METRICS_POW_SUGGESTED_EFFORT: FALLTHROUGH; case HS_METRICS_INTRO_CIRC_BUILD_TIME: FALLTHROUGH; case HS_METRICS_REND_CIRC_BUILD_TIME: FALLTHROUGH; default: @@ -146,7 +148,7 @@ void hs_metrics_update_by_service(const hs_metrics_key_t key, const hs_service_t *service, uint16_t port, const char *reason, - int64_t n, int64_t obs) + int64_t n, int64_t obs, bool reset) { tor_assert(service);
@@ -167,6 +169,9 @@ hs_metrics_update_by_service(const hs_metrics_key_t key, entry, metrics_format_label("port", port_to_str(port)))) && ((!reason || metrics_store_entry_has_label( entry, metrics_format_label("reason", reason))))) { + if (reset) { + metrics_store_entry_reset(entry); + }
if (metrics_store_entry_is_histogram(entry)) { metrics_store_hist_entry_update(entry, n, obs); @@ -190,7 +195,7 @@ void hs_metrics_update_by_ident(const hs_metrics_key_t key, const ed25519_public_key_t *ident_pk, const uint16_t port, const char *reason, - int64_t n, int64_t obs) + int64_t n, int64_t obs, bool reset) { hs_service_t *service;
@@ -204,7 +209,7 @@ hs_metrics_update_by_ident(const hs_metrics_key_t key, * service and thus the only way to know is to lookup the service. */ return; } - hs_metrics_update_by_service(key, service, port, reason, n, obs); + hs_metrics_update_by_service(key, service, port, reason, n, obs, reset); }
/** Return a list of all the onion service metrics stores. This is the diff --git a/src/feature/hs/hs_metrics.h b/src/feature/hs/hs_metrics.h index 4eff4cb498..f2e5dbd9ec 100644 --- a/src/feature/hs/hs_metrics.h +++ b/src/feature/hs/hs_metrics.h @@ -27,75 +27,86 @@ const smartlist_t *hs_metrics_get_stores(void); void hs_metrics_update_by_ident(const hs_metrics_key_t key, const ed25519_public_key_t *ident_pk, const uint16_t port, const char *reason, - int64_t n, int64_t obs); + int64_t n, int64_t obs, bool reset); void hs_metrics_update_by_service(const hs_metrics_key_t key, const hs_service_t *service, uint16_t port, const char *reason, - int64_t n, int64_t obs); + int64_t n, int64_t obs, bool reset);
/** New introducion request received. */ #define hs_metrics_new_introduction(s) \ - hs_metrics_update_by_service(HS_METRICS_NUM_INTRODUCTIONS, (s), 0, NULL, 1, \ - 0) + hs_metrics_update_by_service(HS_METRICS_NUM_INTRODUCTIONS, (s), \ + 0, NULL, 1, 0, false)
/** Introducion request rejected. */ #define hs_metrics_reject_intro_req(s, reason) \ hs_metrics_update_by_service(HS_METRICS_NUM_REJECTED_INTRO_REQ, (s), 0, \ - (reason), 1, 0) + (reason), 1, 0, false)
/** Number of bytes written to the application from the service. */ #define hs_metrics_app_write_bytes(i, port, n) \ hs_metrics_update_by_ident(HS_METRICS_APP_WRITE_BYTES, (i), (port), NULL, \ - (n), 0) + (n), 0, false)
/** Number of bytes read from the application to the service. */ #define hs_metrics_app_read_bytes(i, port, n) \ - hs_metrics_update_by_ident(HS_METRICS_APP_READ_BYTES, (i), (port), NULL, \ - (n), 0) + hs_metrics_update_by_ident(HS_METRICS_APP_READ_BYTES, (i), \ + (port), NULL, (n), 0, false)
/** Newly established rendezvous. This is called as soon as the circuit purpose * is REND_JOINED which is when the RENDEZVOUS2 cell is sent. */ #define hs_metrics_new_established_rdv(s) \ - hs_metrics_update_by_service(HS_METRICS_NUM_ESTABLISHED_RDV, (s), 0, NULL, \ - 1, 0) + hs_metrics_update_by_service(HS_METRICS_NUM_ESTABLISHED_RDV, (s), \ + 0, NULL, 1, 0, false)
/** New rendezvous circuit failure. */ #define hs_metrics_failed_rdv(i, reason) \ - hs_metrics_update_by_ident(HS_METRICS_NUM_FAILED_RDV, (i), 0, (reason), 1, 0) + hs_metrics_update_by_ident(HS_METRICS_NUM_FAILED_RDV, (i), \ + 0, (reason), 1, 0, false)
/** Established rendezvous closed. This is called when the circuit in * REND_JOINED state is marked for close. */ #define hs_metrics_close_established_rdv(i) \ - hs_metrics_update_by_ident(HS_METRICS_NUM_ESTABLISHED_RDV, (i), 0, NULL, \ - -1, 0) + hs_metrics_update_by_ident(HS_METRICS_NUM_ESTABLISHED_RDV, (i), \ + 0, NULL, -1, 0, false)
/** New rendezvous circuit being launched. */ #define hs_metrics_new_rdv(i) \ - hs_metrics_update_by_ident(HS_METRICS_NUM_RDV, (i), 0, NULL, 1, 0) + hs_metrics_update_by_ident(HS_METRICS_NUM_RDV, (i), 0, NULL, 1, 0, false) + +/** Update depth of rendezvous pqueue any time new work is enqueued. */ +#define hs_metrics_pow_pqueue_rdv(s, n) \ + hs_metrics_update_by_service(HS_METRICS_POW_NUM_PQUEUE_RDV, (s), 0, \ + NULL, (n), 0, true) + +/** Update the suggested effort we include in proof-of-work state */ +#define hs_metrics_pow_suggested_effort(s, n) \ + hs_metrics_update_by_service(HS_METRICS_POW_SUGGESTED_EFFORT, (s), 0, \ + NULL, (n), 0, true)
/** New introduction circuit has been established. This is called when the * INTRO_ESTABLISHED has been received by the service. */ #define hs_metrics_new_established_intro(s) \ hs_metrics_update_by_service(HS_METRICS_NUM_ESTABLISHED_INTRO, (s), 0, \ - NULL, 1, 0) + NULL, 1, 0, false)
/** Established introduction circuit closes. This is called when * INTRO_ESTABLISHED circuit is marked for close. */ #define hs_metrics_close_established_intro(i) \ hs_metrics_update_by_ident(HS_METRICS_NUM_ESTABLISHED_INTRO, (i), 0, NULL, \ - -1, 0) + -1, 0, false)
/** Record an introduction circuit build time duration. This is called * when the INTRO_ESTABLISHED has been received by the service. */ #define hs_metrics_intro_circ_build_time(s, obs) \ hs_metrics_update_by_service(HS_METRICS_INTRO_CIRC_BUILD_TIME, (s), 0, \ - NULL, 1, obs) + NULL, 1, obs, false)
/** Record a rendezvous circuit build time duration. This is called as soon as * the circuit purpose is REND_JOINED which is when the RENDEZVOUS2 cell is * sent. */ #define hs_metrics_rdv_circ_build_time(s, obs) \ hs_metrics_update_by_service(HS_METRICS_REND_CIRC_BUILD_TIME, (s), 0, NULL, \ - 1, obs) + 1, obs, false)
#endif /* !defined(TOR_FEATURE_HS_HS_METRICS_H) */ diff --git a/src/feature/hs/hs_metrics_entry.c b/src/feature/hs/hs_metrics_entry.c index 3524d72334..2268ba4c59 100644 --- a/src/feature/hs/hs_metrics_entry.c +++ b/src/feature/hs/hs_metrics_entry.c @@ -104,6 +104,18 @@ const hs_metrics_entry_t base_metrics[] = .bucket_count = hs_metrics_circ_build_time_buckets_size, .help = "The rendezvous circuit build time in milliseconds", }, + { + .key = HS_METRICS_POW_NUM_PQUEUE_RDV, + .type = METRICS_TYPE_GAUGE, + .name = METRICS_NAME(hs_rdv_pow_pqueue_count), + .help = "Number of requests waiting in the proof of work priority queue", + }, + { + .key = HS_METRICS_POW_SUGGESTED_EFFORT, + .type = METRICS_TYPE_GAUGE, + .name = METRICS_NAME(hs_pow_suggested_effort), + .help = "Suggested effort for requests with a proof of work client puzzle", + }, };
/** Size of base_metrics array that is number of entries. */ diff --git a/src/feature/hs/hs_metrics_entry.h b/src/feature/hs/hs_metrics_entry.h index 4c9abd06d7..1a1bc701ec 100644 --- a/src/feature/hs/hs_metrics_entry.h +++ b/src/feature/hs/hs_metrics_entry.h @@ -48,11 +48,11 @@ typedef enum { HS_METRICS_APP_WRITE_BYTES = 1, /** Number of bytes read from application to onion service. */ HS_METRICS_APP_READ_BYTES = 2, - /** Number of established rendezsvous. */ + /** Number of established rendezvous. */ HS_METRICS_NUM_ESTABLISHED_RDV = 3, - /** Number of rendezsvous circuits created. */ + /** Number of rendezvous circuits created. */ HS_METRICS_NUM_RDV = 4, - /** Number of failed rendezsvous. */ + /** Number of failed rendezvous. */ HS_METRICS_NUM_FAILED_RDV = 5, /** Number of established introducton points. */ HS_METRICS_NUM_ESTABLISHED_INTRO = 6, @@ -62,6 +62,10 @@ typedef enum { HS_METRICS_INTRO_CIRC_BUILD_TIME = 8, /** Rendezvous circuit build time in milliseconds. */ HS_METRICS_REND_CIRC_BUILD_TIME = 9, + /** Number of requests waiting in the proof of work priority queue. */ + HS_METRICS_POW_NUM_PQUEUE_RDV = 10, + /** Suggested effort for requests with a proof of work client puzzle. */ + HS_METRICS_POW_SUGGESTED_EFFORT = 11, } hs_metrics_key_t;
/** The metadata of an HS metrics. */ diff --git a/src/feature/hs/hs_service.c b/src/feature/hs/hs_service.c index d67fead791..fda0162958 100644 --- a/src/feature/hs/hs_service.c +++ b/src/feature/hs/hs_service.c @@ -2700,6 +2700,8 @@ update_suggested_effort(hs_service_t *service, time_t now) pow_state->suggested_effort = 2*pow_state->suggested_effort/3; }
+ hs_metrics_pow_suggested_effort(service, pow_state->suggested_effort); + log_debug(LD_REND, "Recalculated suggested effort: %u", pow_state->suggested_effort);
diff --git a/src/test/test_hs_metrics.c b/src/test/test_hs_metrics.c index c3c7ef57bc..acb0649434 100644 --- a/src/test/test_hs_metrics.c +++ b/src/test/test_hs_metrics.c @@ -40,7 +40,8 @@ test_metrics(void *arg)
/* Update entry by identifier. */ hs_metrics_update_by_ident(HS_METRICS_NUM_INTRODUCTIONS, - &service->keys.identity_pk, 0, NULL, 42, 0); + &service->keys.identity_pk, 0, NULL, 42, + 0, false);
/* Confirm the entry value. */ const smartlist_t *entries = metrics_store_get_all(service->metrics.store, @@ -53,14 +54,15 @@ test_metrics(void *arg)
/* Update entry by service now. */ hs_metrics_update_by_service(HS_METRICS_NUM_INTRODUCTIONS, - service, 0, NULL, 42, 0); + service, 0, NULL, 42, 0, false); tt_int_op(metrics_store_entry_get_value(entry), OP_EQ, 84);
const char *reason = HS_METRICS_ERR_INTRO_REQ_BAD_AUTH_KEY;
/* Update tor_hs_intro_rejected_intro_req_count */ hs_metrics_update_by_ident(HS_METRICS_NUM_REJECTED_INTRO_REQ, - &service->keys.identity_pk, 0, reason, 112, 0); + &service->keys.identity_pk, 0, + reason, 112, 0, false);
entries = metrics_store_get_all(service->metrics.store, "tor_hs_intro_rejected_intro_req_count"); @@ -75,9 +77,19 @@ test_metrics(void *arg)
/* Update tor_hs_intro_rejected_intro_req_count entry by service now. */ hs_metrics_update_by_service(HS_METRICS_NUM_REJECTED_INTRO_REQ, service, 0, - reason, 10, 0); + reason, 10, 0, false); tt_int_op(metrics_store_entry_get_value(entry), OP_EQ, 122);
+ /* So far these have been relative updates. Test updates with reset */ + hs_metrics_update_by_service(HS_METRICS_NUM_REJECTED_INTRO_REQ, + service, 0, reason, 10, 0, true); + tt_int_op(metrics_store_entry_get_value(entry), OP_EQ, 10); + + hs_metrics_update_by_ident(HS_METRICS_NUM_REJECTED_INTRO_REQ, + &service->keys.identity_pk, 0, reason, + 345, 0, true); + tt_int_op(metrics_store_entry_get_value(entry), OP_EQ, 345); + done: hs_free_all(); }