MINOR: stream: add a sample fetch to get the number of connection retries
authorChristopher Faulet <cfaulet@haproxy.com>
Tue, 28 Nov 2023 12:59:59 +0000 (13:59 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Wed, 29 Nov 2023 10:11:12 +0000 (11:11 +0100)
"txn.conn_retries" can now be used to get the number of connection
retries. This value is only stable once the connection is fully
established. For HTTP sessions, L7-retries must also be passed.

doc/configuration.txt
src/stream.c

index 09dec9b..1c20f42 100644 (file)
@@ -20103,6 +20103,12 @@ thread : integer
   the function, between 0 and (global.nbthread-1). This is useful for logging
   and debugging purposes.
 
+txn.conn_retries : integer
+  Returns the the number of connection retries experienced by this session when
+  trying to connect to the server. This value is subject to change while the
+  connection is not fully established. For HTTP connections, the value may be
+  affected by L7 retries.
+
 txn.sess_term_state : string
   Retruns the TCP or HTTP session termination state, as reported in the log. It
   is a 2-characters string, The final session state followed by the event which
@@ -24040,6 +24046,7 @@ Please refer to the table below for currently defined variables :
   | H | %r   | http_request                                         | string  |
   +---+------+------------------------------------------------------+---------+
   |   | %rc  | retries                                              | numeric |
+  |   |      | %[txn.conn_retries]                                  |         |
   +---+------+------------------------------------------------------+---------+
   |   | %rt  | request_counter (HTTP req or TCP session)            | numeric |
   +---+------+------------------------------------------------------+---------+
index 9c4e9ad..e6eccbd 100644 (file)
@@ -3989,6 +3989,19 @@ static int smp_fetch_sess_term_state(const struct arg *args, struct sample *smp,
        return 1;
 }
 
+static int smp_fetch_conn_retries(const struct arg *args, struct sample *smp, const char *km, void *private)
+{
+       smp->flags = SMP_F_VOL_TXN;
+       smp->data.type = SMP_T_SINT;
+       if (!smp->strm)
+               return 0;
+
+       if (!sc_state_in(smp->strm->scb->state, SC_SB_DIS|SC_SB_CLO))
+               smp->flags |= SMP_F_VOL_TEST;
+       smp->data.u.sint = smp->strm->conn_retries;
+       return 1;
+}
+
 /* Note: must not be declared <const> as its list will be overwritten.
  * Please take care of keeping this list alphabetically sorted.
  */
@@ -3998,6 +4011,7 @@ static struct sample_fetch_kw_list smp_kws = {ILH, {
        { "cur_tunnel_timeout", smp_fetch_cur_tunnel_timeout, 0, NULL, SMP_T_SINT, SMP_USE_BKEND, },
        { "last_rule_file",     smp_fetch_last_rule_file,     0, NULL, SMP_T_STR,  SMP_USE_INTRN, },
        { "last_rule_line",     smp_fetch_last_rule_line,     0, NULL, SMP_T_SINT, SMP_USE_INTRN, },
+       { "txn.conn_retries",   smp_fetch_conn_retries,       0, NULL, SMP_T_SINT, SMP_USE_L4SRV, },
        { "txn.sess_term_state",smp_fetch_sess_term_state,    0, NULL, SMP_T_STR,  SMP_USE_INTRN, },
        { NULL, NULL, 0, 0, 0 },
 }};