From 00f714b37408381206af02951758b2505aabee1f Mon Sep 17 00:00:00 2001 From: David Goulet Date: Thu, 13 Oct 2022 10:50:18 -0400 Subject: [PATCH] relay: Add CC RTT reset stats to MetricsPort Related to #40194 Signed-off-by: David Goulet --- src/core/or/congestion_control_common.c | 11 +++++++++++ src/core/or/congestion_control_common.h | 2 ++ src/feature/relay/relay_metrics.c | 24 ++++++++++++++++++++++++ src/feature/relay/relay_metrics.h | 2 ++ 4 files changed, 39 insertions(+) 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/feature/relay/relay_metrics.c b/src/feature/relay/relay_metrics.c index e48e211ba7..77ccaac722 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 /** 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); @@ -104,6 +106,13 @@ static const relay_metrics_entry_t base_metrics[] = .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); @@ -130,6 +139,21 @@ 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) diff --git a/src/feature/relay/relay_metrics.h b/src/feature/relay/relay_metrics.h index 17f9c9f195..a594726668 100644 --- a/src/feature/relay/relay_metrics.h +++ b/src/feature/relay/relay_metrics.h @@ -33,6 +33,8 @@ typedef enum { 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. */