]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
relay: Add CC RTT reset stats to MetricsPort
authorDavid Goulet <dgoulet@torproject.org>
Thu, 13 Oct 2022 14:50:18 +0000 (10:50 -0400)
committerDavid Goulet <dgoulet@torproject.org>
Wed, 26 Oct 2022 19:16:48 +0000 (15:16 -0400)
Related to #40194

Signed-off-by: David Goulet <dgoulet@torproject.org>
src/core/or/congestion_control_common.c
src/core/or/congestion_control_common.h
src/feature/relay/relay_metrics.c
src/feature/relay/relay_metrics.h

index 55be5d733b0945b4fa4bc2df534159cb3316083c..09d1d501dac7569040cc6d3fd538f5989e48a349 100644 (file)
@@ -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
index 50af945d62a9bb018ceda76c28f4fcd68d639674..e62775eccee8f9ad1864cfb23ed5bc99140f6e25 100644 (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);
 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;
index e48e211ba7f825a74a0fafe10465a37cbfb46947..77ccaac722750c45e8898f80ad4b161c5b84f6f9 100644 (file)
@@ -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);
@@ -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)
index 17f9c9f195c0043523dee686495670cb85a78ae6..a594726668d496ce89999b5f25b93c388787730d 100644 (file)
@@ -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. */