]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: stream: Expose the stream's uniq_id via a new sample fetch
authorChristopher Faulet <cfaulet@haproxy.com>
Tue, 28 Nov 2023 20:01:18 +0000 (21:01 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Wed, 29 Nov 2023 10:11:12 +0000 (11:11 +0100)
"txn.id32" may now be used to get the stream's uniq_id. It is equivalent to
%rt in logs.

doc/configuration.txt
src/stream.c

index 1c20f42c764efe91737cf7ed2d6293e78a9609b1..1f47d1ebc19151734e5ec2e69b2b15ea45a9cbf0 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.id32 : integer
+  Returns the internal transaction ID. It is a 32bits integer. So, in absolute,
+  its value is not unique, transaction IDs may wrap. The wrapping period
+  depends on the request rate. In practice, it should not be an issue. For a
+  true unique ID, see "unique-id-format" directive.
+
 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
@@ -24049,6 +24055,7 @@ Please refer to the table below for currently defined variables :
   |   |      | %[txn.conn_retries]                                  |         |
   +---+------+------------------------------------------------------+---------+
   |   | %rt  | request_counter (HTTP req or TCP session)            | numeric |
+  |   |      | %[txn.id32]                                          |         |
   +---+------+------------------------------------------------------+---------+
   |   | %s   | server_name                                          | string  |
   +---+------+------------------------------------------------------+---------+
index e6eccbd8b52ab508c54bed6c0015bc028de63974..819564c0af118988e87df4a7171565c961f7ae58 100644 (file)
@@ -4002,6 +4002,16 @@ static int smp_fetch_conn_retries(const struct arg *args, struct sample *smp, co
        return 1;
 }
 
+static int smp_fetch_id32(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;
+       smp->data.u.sint = smp->strm->uniq_id;
+       return 1;
+}
+
 /* Note: must not be declared <const> as its list will be overwritten.
  * Please take care of keeping this list alphabetically sorted.
  */
@@ -4012,6 +4022,7 @@ static struct sample_fetch_kw_list smp_kws = {ILH, {
        { "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.id32",           smp_fetch_id32,               0, NULL, SMP_T_SINT, SMP_USE_INTRN, },
        { "txn.sess_term_state",smp_fetch_sess_term_state,    0, NULL, SMP_T_STR,  SMP_USE_INTRN, },
        { NULL, NULL, 0, 0, 0 },
 }};