From b1eb3bc9a2240e20d33cf9e80038302b62502711 Mon Sep 17 00:00:00 2001 From: Christopher Faulet Date: Tue, 28 Nov 2023 13:59:59 +0100 Subject: [PATCH] MINOR: stream: add a sample fetch to get the number of connection retries "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 | 7 +++++++ src/stream.c | 14 ++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/doc/configuration.txt b/doc/configuration.txt index 09dec9b..1c20f42 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -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 | +---+------+------------------------------------------------------+---------+ diff --git a/src/stream.c b/src/stream.c index 9c4e9ad..e6eccbd 100644 --- a/src/stream.c +++ b/src/stream.c @@ -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 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 }, }}; -- 1.7.10.4