]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: stream: add "txn.redispatch" fetch
authorAurelien DARRAGON <adarragon@haproxy.com>
Tue, 30 Jan 2024 11:03:28 +0000 (12:03 +0100)
committerAurelien DARRAGON <adarragon@haproxy.com>
Mon, 5 Feb 2024 13:54:37 +0000 (14:54 +0100)
Fetch will return true if the stream underwent a redispatch according to
"option redispatch" setting upon retries.

Documentation was added, and the "%rc" logformat alternative now mentions
the new fetch to properly emulate the logformat behavior.

doc/configuration.txt
src/stream.c

index d5df30bfe0b2d6810fa7f4301ac63e547bddfe96..52eafa9bfbea582e5b52b1b72ea975bdbde34830 100644 (file)
@@ -20516,6 +20516,7 @@ table_cnt([<table>])                               integer
 thread                                             integer
 txn.conn_retries                                   integer
 txn.id32                                           integer
+txn.redispatch                                     boolean
 txn.sess_term_state                                string
 uuid([<version>])                                  string
 var(<var-name>[,<default>])                        undefined
@@ -20978,6 +20979,12 @@ txn.id32 : integer
   depends on the request rate. In practice, it should not be an issue. For a
   true unique ID, see "unique-id-format" directive.
 
+txn.redispatch : boolean
+  Returns true if the connection has experienced redispatch upon retry according
+  to "option redispatch" configuration. 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
   Returns the TCP or HTTP stream termination state, as reported in the log. It
   is a 2-characters string, The final stream state followed by the event which
@@ -25428,7 +25435,7 @@ Please refer to the table below for currently defined variables :
   | H | %r   | http_request                                         | string  |
   +---+------+------------------------------------------------------+---------+
   |   | %rc  | retries                                              | numeric |
-  |   |      | %[txn.conn_retries]                                  |         |
+  |   |      | %[txn.redispatch,iif(+,)]%[txn.conn_retries]         |         |
   +---+------+------------------------------------------------------+---------+
   |   | %rt  | request_counter (HTTP req or TCP session)            | numeric |
   |   |      | %[txn.id32]                                          |         |
index a3c0c93d225f38a2c0c7417aa5865cc67c207d6c..39b374639842f80c88a3622c61dd3fb4c9b2c205 100644 (file)
@@ -4020,6 +4020,19 @@ static int smp_fetch_id32(const struct arg *args, struct sample *smp, const char
        return 1;
 }
 
+static int smp_fetch_redispatch(const struct arg *args, struct sample *smp, const char *km, void *private)
+{
+       smp->flags = SMP_F_VOL_TXN;
+       smp->data.type = SMP_T_BOOL;
+       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->flags & SF_REDISP);
+       return 1;
+}
+
 /* Note: must not be declared <const> as its list will be overwritten.
  * Please take care of keeping this list alphabetically sorted.
  */
@@ -4031,6 +4044,7 @@ static struct sample_fetch_kw_list smp_kws = {ILH, {
        { "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.id32",           smp_fetch_id32,               0, NULL, SMP_T_SINT, SMP_USE_INTRN, },
+       { "txn.redispatch",     smp_fetch_redispatch,         0, NULL, SMP_T_BOOL, 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 },
 }};