Merge branch 'maint-0.4.7'

This commit is contained in:
David Goulet 2022-10-27 10:46:54 -04:00
commit fff2b92682
9 changed files with 140 additions and 3 deletions

View File

@ -91,6 +91,9 @@ static bool congestion_control_update_circuit_bdp(congestion_control_t *,
/* For unit tests */ /* For unit tests */
void congestion_control_set_cc_enabled(void); 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. */ /* Consensus parameters cached. The non static ones are extern. */
static uint32_t cwnd_max = CWND_MAX_DFLT; static uint32_t cwnd_max = CWND_MAX_DFLT;
int32_t cell_queue_high = CELL_QUEUE_HIGH_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; 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, * Update global congestion control related consensus parameter values,
* every consensus update. * 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/1000, new_rtt/1000);
cc->min_rtt_usec = new_rtt; cc->min_rtt_usec = new_rtt;
num_rtt_reset++; /* Accounting */
} else if (cc->ewma_rtt_usec < cc->min_rtt_usec) { } else if (cc->ewma_rtt_usec < cc->min_rtt_usec) {
// Using the EWMA for min instead of current RTT helps average out // Using the EWMA for min instead of current RTT helps average out
// effects from other conns // effects from other conns

View File

@ -82,6 +82,8 @@ int congestion_control_parse_ext_response(const uint8_t *msg,
bool congestion_control_validate_sendme_increment(uint8_t sendme_inc); bool congestion_control_validate_sendme_increment(uint8_t sendme_inc);
char *congestion_control_get_control_port_fields(const origin_circuit_t *); 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 /* Ugh, C.. these are private. Use the getter instead, when
* external to the congestion control code. */ * external to the congestion control code. */
extern uint32_t or_conn_highwater; extern uint32_t or_conn_highwater;

View File

@ -4119,6 +4119,9 @@ connection_exit_begin_resolve(cell_t *cell, or_circuit_t *circ)
if (rh.length > RELAY_PAYLOAD_SIZE) if (rh.length > RELAY_PAYLOAD_SIZE)
return -1; 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 /* This 'dummy_conn' only exists to remember the stream ID
* associated with the resolve request; and to make the * associated with the resolve request; and to make the
* implementation of dns.c more uniform. (We really only need to * implementation of dns.c more uniform. (We really only need to
@ -4241,6 +4244,10 @@ connection_exit_connect(edge_connection_t *edge_conn)
return; 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 #ifdef HAVE_SYS_UN_H
if (conn->socket_family != AF_UNIX) { if (conn->socket_family != AF_UNIX) {
#else #else
@ -4336,6 +4343,9 @@ connection_exit_connect_dir(edge_connection_t *exitconn)
log_info(LD_EXIT, "Opening local connection for anonymized directory exit"); 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; exitconn->base_.state = EXIT_CONN_STATE_OPEN;
dirconn = dir_connection_new(tor_addr_family(&exitconn->base_.addr)); dirconn = dir_connection_new(tor_addr_family(&exitconn->base_.addr));

View File

@ -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. */ /** Convert the relay <b>command</b> into a human-readable string. */
static const char * const char *
relay_command_to_string(uint8_t command) relay_command_to_string(uint8_t command)
{ {
static char buf[64]; static char buf[64];

View File

@ -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_relay_cells_delivered;
extern uint64_t stats_n_circ_max_cell_reached; 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); void relay_consensus_has_changed(const networkstatus_t *ns);
uint32_t relay_get_param_max_circuit_cell_queue_size( uint32_t relay_get_param_max_circuit_cell_queue_size(
const networkstatus_t *ns); const networkstatus_t *ns);

View File

@ -12,6 +12,7 @@
#include "core/or/or.h" #include "core/or/or.h"
#include "core/mainloop/connection.h" #include "core/mainloop/connection.h"
#include "core/or/congestion_control_common.h"
#include "core/or/relay.h" #include "core/or/relay.h"
#include "lib/malloc/malloc.h" #include "lib/malloc/malloc.h"
@ -25,6 +26,7 @@
#include <event2/dns.h> #include <event2/dns.h>
/** Declarations of each fill function for metrics defined in base_metrics. */ /** 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_connections_values(void);
static void fill_dns_error_values(void); static void fill_dns_error_values(void);
static void fill_dns_query_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_socket_values(void);
static void fill_onionskins_values(void); static void fill_onionskins_values(void);
static void fill_oom_values(void); static void fill_oom_values(void);
static void fill_streams_values(void);
static void fill_tcp_exhaustion_values(void); static void fill_tcp_exhaustion_values(void);
/** The base metrics that is a static array of metrics added to the metrics /** 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, .key = RELAY_METRICS_NUM_CONNECTIONS,
.type = METRICS_TYPE_COUNTER, .type = METRICS_TYPE_COUNTER,
.name = METRICS_NAME(relay_connections), .name = METRICS_NAME(relay_connections_total),
.help = "Connections metrics of this relay", .help = "Total number of connections",
.fill_fn = fill_connections_values, .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); 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. */ /** Helper: Fill in single connection metrics output. */
static void static void
fill_single_connection_value(metrics_store_entry_t *sentry, fill_single_connection_value(metrics_store_entry_t *sentry,

View File

@ -31,6 +31,10 @@ typedef enum {
RELAY_METRICS_NUM_TCP_EXHAUSTION = 6, RELAY_METRICS_NUM_TCP_EXHAUSTION = 6,
/** Number of connections. */ /** Number of connections. */
RELAY_METRICS_NUM_CONNECTIONS = 7, 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; } relay_metrics_key_t;
/** The metadata of a relay metric. */ /** The metadata of a relay metric. */

View File

@ -1639,6 +1639,51 @@ rep_hist_note_exit_stream_opened(uint16_t port)
log_debug(LD_HIST, "Opened exit stream to port %d", 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 *******/ /******* Connections statistics *******/
#define CONN_DIRECTION_INITIATED 0 #define CONN_DIRECTION_INITIATED 0

View File

@ -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_opened(bool initiated, unsigned int type);
uint64_t rep_hist_get_conn_rejected(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_init(time_t now);
void rep_hist_buffer_stats_add_circ(circuit_t *circ, void rep_hist_buffer_stats_add_circ(circuit_t *circ,
time_t end_of_interval); time_t end_of_interval);