From: Christopher Faulet Date: Tue, 28 Nov 2023 20:01:18 +0000 (+0100) Subject: MINOR: stream: Expose the stream's uniq_id via a new sample fetch X-Git-Tag: v2.9-dev12~25 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0b8e7d666e49ccdbad76816fb94abe3229d8e080;p=thirdparty%2Fhaproxy.git MINOR: stream: Expose the stream's uniq_id via a new sample fetch "txn.id32" may now be used to get the stream's uniq_id. It is equivalent to %rt in logs. --- diff --git a/doc/configuration.txt b/doc/configuration.txt index 1c20f42c76..1f47d1ebc1 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.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 | +---+------+------------------------------------------------------+---------+ diff --git a/src/stream.c b/src/stream.c index e6eccbd8b5..819564c0af 100644 --- a/src/stream.c +++ b/src/stream.c @@ -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 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 }, }};