diff options
author | David Goulet <dgoulet@torproject.org> | 2022-10-27 10:46:54 -0400 |
---|---|---|
committer | David Goulet <dgoulet@torproject.org> | 2022-10-27 10:46:54 -0400 |
commit | fff2b92682222c960e2cd4455e8264bcd5d406fb (patch) | |
tree | 1156ee5377c1a4a5c78b42cf5fdd7c6dea8a7cce | |
parent | 5f548f05d2c5e18833358ae05b78ad3c3c673636 (diff) | |
parent | a1c40c8511b841db773e82bd8024ef3581262900 (diff) | |
download | tor-fff2b92682222c960e2cd4455e8264bcd5d406fb.tar.gz tor-fff2b92682222c960e2cd4455e8264bcd5d406fb.zip |
Merge branch 'maint-0.4.7'
-rw-r--r-- | src/core/or/congestion_control_common.c | 11 | ||||
-rw-r--r-- | src/core/or/congestion_control_common.h | 2 | ||||
-rw-r--r-- | src/core/or/connection_edge.c | 10 | ||||
-rw-r--r-- | src/core/or/relay.c | 2 | ||||
-rw-r--r-- | src/core/or/relay.h | 2 | ||||
-rw-r--r-- | src/feature/relay/relay_metrics.c | 64 | ||||
-rw-r--r-- | src/feature/relay/relay_metrics.h | 4 | ||||
-rw-r--r-- | src/feature/stats/rephist.c | 45 | ||||
-rw-r--r-- | src/feature/stats/rephist.h | 3 |
9 files changed, 140 insertions, 3 deletions
diff --git a/src/core/or/congestion_control_common.c b/src/core/or/congestion_control_common.c index 55be5d733b..09d1d501da 100644 --- a/src/core/or/congestion_control_common.c +++ b/src/core/or/congestion_control_common.c @@ -91,6 +91,9 @@ static bool congestion_control_update_circuit_bdp(congestion_control_t *, /* For unit tests */ void congestion_control_set_cc_enabled(void); +/* Number of times the RTT value was reset. For MetricsPort. */ +static uint64_t num_rtt_reset; + /* Consensus parameters cached. The non static ones are extern. */ static uint32_t cwnd_max = CWND_MAX_DFLT; int32_t cell_queue_high = CELL_QUEUE_HIGH_DFLT; @@ -126,6 +129,13 @@ static uint8_t bwe_sendme_min; */ static uint8_t rtt_reset_pct; +/** Return the number of RTT reset that have been done. */ +uint64_t +congestion_control_get_num_rtt_reset(void) +{ + return num_rtt_reset; +} + /** * Update global congestion control related consensus parameter values, * every consensus update. @@ -888,6 +898,7 @@ congestion_control_update_circuit_rtt(congestion_control_t *cc, cc->min_rtt_usec/1000, new_rtt/1000); cc->min_rtt_usec = new_rtt; + num_rtt_reset++; /* Accounting */ } else if (cc->ewma_rtt_usec < cc->min_rtt_usec) { // Using the EWMA for min instead of current RTT helps average out // effects from other conns diff --git a/src/core/or/congestion_control_common.h b/src/core/or/congestion_control_common.h index 50af945d62..e62775ecce 100644 --- a/src/core/or/congestion_control_common.h +++ b/src/core/or/congestion_control_common.h @@ -82,6 +82,8 @@ int congestion_control_parse_ext_response(const uint8_t *msg, bool congestion_control_validate_sendme_increment(uint8_t sendme_inc); char *congestion_control_get_control_port_fields(const origin_circuit_t *); +uint64_t congestion_control_get_num_rtt_reset(void); + /* Ugh, C.. these are private. Use the getter instead, when * external to the congestion control code. */ extern uint32_t or_conn_highwater; diff --git a/src/core/or/connection_edge.c b/src/core/or/connection_edge.c index 7ba7ecc4c5..5ef7a0982b 100644 --- a/src/core/or/connection_edge.c +++ b/src/core/or/connection_edge.c @@ -4119,6 +4119,9 @@ connection_exit_begin_resolve(cell_t *cell, or_circuit_t *circ) if (rh.length > RELAY_PAYLOAD_SIZE) return -1; + /* Note the RESOLVE stream as seen. */ + rep_hist_note_exit_stream(RELAY_COMMAND_RESOLVE); + /* This 'dummy_conn' only exists to remember the stream ID * associated with the resolve request; and to make the * implementation of dns.c more uniform. (We really only need to @@ -4241,6 +4244,10 @@ connection_exit_connect(edge_connection_t *edge_conn) return; } + /* Note the BEGIN stream as seen. We do this after the Exit policy check in + * order to only account for valid streams. */ + rep_hist_note_exit_stream(RELAY_COMMAND_BEGIN); + #ifdef HAVE_SYS_UN_H if (conn->socket_family != AF_UNIX) { #else @@ -4336,6 +4343,9 @@ connection_exit_connect_dir(edge_connection_t *exitconn) log_info(LD_EXIT, "Opening local connection for anonymized directory exit"); + /* Note the BEGIN_DIR stream as seen. */ + rep_hist_note_exit_stream(RELAY_COMMAND_BEGIN_DIR); + exitconn->base_.state = EXIT_CONN_STATE_OPEN; dirconn = dir_connection_new(tor_addr_family(&exitconn->base_.addr)); diff --git a/src/core/or/relay.c b/src/core/or/relay.c index f382e3b46c..5489332309 100644 --- a/src/core/or/relay.c +++ b/src/core/or/relay.c @@ -502,7 +502,7 @@ relay_header_unpack(relay_header_t *dest, const uint8_t *src) } /** Convert the relay <b>command</b> into a human-readable string. */ -static const char * +const char * relay_command_to_string(uint8_t command) { static char buf[64]; diff --git a/src/core/or/relay.h b/src/core/or/relay.h index 71e07562cd..24466bccd0 100644 --- a/src/core/or/relay.h +++ b/src/core/or/relay.h @@ -16,6 +16,8 @@ extern uint64_t stats_n_relay_cells_relayed; extern uint64_t stats_n_relay_cells_delivered; extern uint64_t stats_n_circ_max_cell_reached; +const char *relay_command_to_string(uint8_t command); + void relay_consensus_has_changed(const networkstatus_t *ns); uint32_t relay_get_param_max_circuit_cell_queue_size( const networkstatus_t *ns); diff --git a/src/feature/relay/relay_metrics.c b/src/feature/relay/relay_metrics.c index 8d0fef86b3..814afa6006 100644 --- a/src/feature/relay/relay_metrics.c +++ b/src/feature/relay/relay_metrics.c @@ -12,6 +12,7 @@ #include "core/or/or.h" #include "core/mainloop/connection.h" +#include "core/or/congestion_control_common.h" #include "core/or/relay.h" #include "lib/malloc/malloc.h" @@ -25,6 +26,7 @@ #include <event2/dns.h> /** Declarations of each fill function for metrics defined in base_metrics. */ +static void fill_cc_values(void); static void fill_connections_values(void); static void fill_dns_error_values(void); static void fill_dns_query_values(void); @@ -32,6 +34,7 @@ static void fill_global_bw_limit_values(void); static void fill_socket_values(void); static void fill_onionskins_values(void); static void fill_oom_values(void); +static void fill_streams_values(void); static void fill_tcp_exhaustion_values(void); /** The base metrics that is a static array of metrics added to the metrics @@ -92,10 +95,24 @@ static const relay_metrics_entry_t base_metrics[] = { .key = RELAY_METRICS_NUM_CONNECTIONS, .type = METRICS_TYPE_COUNTER, - .name = METRICS_NAME(relay_connections), - .help = "Connections metrics of this relay", + .name = METRICS_NAME(relay_connections_total), + .help = "Total number of connections", .fill_fn = fill_connections_values, }, + { + .key = RELAY_METRICS_NUM_STREAMS, + .type = METRICS_TYPE_COUNTER, + .name = METRICS_NAME(relay_streams_total), + .help = "Total number of streams", + .fill_fn = fill_streams_values, + }, + { + .key = RELAY_METRICS_NUM_CC, + .type = METRICS_TYPE_COUNTER, + .name = METRICS_NAME(relay_congestion_control_total), + .help = "Congestion control related counters", + .fill_fn = fill_cc_values, + }, }; static const size_t num_base_metrics = ARRAY_LENGTH(base_metrics); @@ -122,6 +139,49 @@ handshake_type_to_str(const uint16_t type) } } +/** Fill function for the RELAY_METRICS_NUM_CC metric. */ +static void +fill_cc_values(void) +{ + const relay_metrics_entry_t *rentry = &base_metrics[RELAY_METRICS_NUM_CC]; + metrics_store_entry_t *sentry = + metrics_store_add(the_store, rentry->type, rentry->name, rentry->help); + + metrics_store_entry_add_label(sentry, + metrics_format_label("state", "starvation")); + metrics_store_entry_add_label(sentry, + metrics_format_label("action", "rtt_reset")); + metrics_store_entry_update(sentry, congestion_control_get_num_rtt_reset()); +} + +/** Helper: Fill in single stream metrics output. */ +static void +fill_single_stream_value(metrics_store_entry_t *sentry, uint8_t cmd) +{ + metrics_store_entry_add_label(sentry, + metrics_format_label("type", relay_command_to_string(cmd))); + metrics_store_entry_update(sentry, rep_hist_get_exit_stream_seen(cmd)); +} + +/** Fill function for the RELAY_METRICS_NUM_STREAMS metric. */ +static void +fill_streams_values(void) +{ + const relay_metrics_entry_t *rentry = + &base_metrics[RELAY_METRICS_NUM_STREAMS]; + metrics_store_entry_t *sentry = + metrics_store_add(the_store, rentry->type, rentry->name, rentry->help); + fill_single_stream_value(sentry, RELAY_COMMAND_BEGIN); + + sentry = metrics_store_add(the_store, rentry->type, rentry->name, + rentry->help); + fill_single_stream_value(sentry, RELAY_COMMAND_BEGIN_DIR); + + sentry = metrics_store_add(the_store, rentry->type, rentry->name, + rentry->help); + fill_single_stream_value(sentry, RELAY_COMMAND_RESOLVE); +} + /** Helper: Fill in single connection metrics output. */ static void fill_single_connection_value(metrics_store_entry_t *sentry, diff --git a/src/feature/relay/relay_metrics.h b/src/feature/relay/relay_metrics.h index 02b92cd043..a594726668 100644 --- a/src/feature/relay/relay_metrics.h +++ b/src/feature/relay/relay_metrics.h @@ -31,6 +31,10 @@ typedef enum { RELAY_METRICS_NUM_TCP_EXHAUSTION = 6, /** Number of connections. */ RELAY_METRICS_NUM_CONNECTIONS = 7, + /** Number of streams. */ + RELAY_METRICS_NUM_STREAMS = 8, + /** Congestion control counters. */ + RELAY_METRICS_NUM_CC = 9, } relay_metrics_key_t; /** The metadata of a relay metric. */ diff --git a/src/feature/stats/rephist.c b/src/feature/stats/rephist.c index 553a7f953e..3dcc53fd07 100644 --- a/src/feature/stats/rephist.c +++ b/src/feature/stats/rephist.c @@ -1639,6 +1639,51 @@ rep_hist_note_exit_stream_opened(uint16_t port) log_debug(LD_HIST, "Opened exit stream to port %d", port); } +/*** Exit streams statistics ***/ + +/** Number of BEGIN streams seen. */ +static uint64_t streams_begin_seen; +/** Number of BEGIN_DIR streams seen. */ +static uint64_t streams_begindir_seen; +/** Number of RESOLVE streams seen. */ +static uint64_t streams_resolve_seen; + +/** Note a stream as seen for the given relay command. */ +void +rep_hist_note_exit_stream(unsigned int cmd) +{ + switch (cmd) { + case RELAY_COMMAND_BEGIN: + streams_begin_seen++; + break; + case RELAY_COMMAND_BEGIN_DIR: + streams_begindir_seen++; + break; + case RELAY_COMMAND_RESOLVE: + streams_resolve_seen++; + break; + default: + tor_assert_nonfatal_unreached_once(); + break; + } +} + +/** Return number of stream seen for the given command. */ +uint64_t +rep_hist_get_exit_stream_seen(unsigned int cmd) +{ + switch (cmd) { + case RELAY_COMMAND_BEGIN: + return streams_begin_seen; + case RELAY_COMMAND_BEGIN_DIR: + return streams_begindir_seen; + case RELAY_COMMAND_RESOLVE: + return streams_resolve_seen; + default: + return 0; + } +} + /******* Connections statistics *******/ #define CONN_DIRECTION_INITIATED 0 diff --git a/src/feature/stats/rephist.h b/src/feature/stats/rephist.h index 2a83dd185e..02d23a4c1b 100644 --- a/src/feature/stats/rephist.h +++ b/src/feature/stats/rephist.h @@ -48,6 +48,9 @@ uint64_t rep_hist_get_conn_created(bool initiated, unsigned int type); uint64_t rep_hist_get_conn_opened(bool initiated, unsigned int type); uint64_t rep_hist_get_conn_rejected(unsigned int type); +void rep_hist_note_exit_stream(unsigned int cmd); +uint64_t rep_hist_get_exit_stream_seen(unsigned int cmd); + void rep_hist_buffer_stats_init(time_t now); void rep_hist_buffer_stats_add_circ(circuit_t *circ, time_t end_of_interval); |