]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: stktable: add sc[0-2]_key fetches
authorAurelien DARRAGON <adarragon@haproxy.com>
Mon, 30 Dec 2024 18:26:36 +0000 (19:26 +0100)
committerAurelien DARRAGON <adarragon@haproxy.com>
Thu, 9 Jan 2025 09:57:01 +0000 (10:57 +0100)
As discussed in GH #1750, we were lacking a sample fetch to be able to
retrieve the key from the currently tracked counter entry. To do so,
sc_key fetch can now be used. It returns a sample with the correct type
(table key type) corresponding to the tracked counter entry (from previous
track-sc rules).

If no entry is currently tracked, it returns nothing.

It can be used using the standard form "sc_key(<sc_number>)" or the legacy
form: "sc0_key", "sc1_key", "sc2_key"

Documentation was updated.

doc/configuration.txt
src/stick_table.c

index 6478bc8521a1e5312f11b27e9b2d9bd67d42e5fe..36be7e8e60bf2c14a6f7831b887f2b6a51bbb9b8 100644 (file)
@@ -22748,6 +22748,10 @@ sc_kbytes_out(<ctr>[,<table>])                     integer
 sc0_kbytes_out([<table>])                          integer
 sc1_kbytes_out([<table>])                          integer
 sc2_kbytes_out([<table>])                          integer
+sc_key(<ctr>)                                      any
+sc0_key                                            any
+sc1_key                                            any
+sc2_key                                            any
 sc_sess_cnt(<ctr>[,<table>])                       integer
 sc0_sess_cnt([<table>])                            integer
 sc1_sess_cnt([<table>])                            integer
@@ -23560,6 +23564,12 @@ sc2_kbytes_out([<table>]) : integer
   counters, measured in kilobytes. The test is currently performed on 32-bit
   integers, which limits values to 4 terabytes. See also src_kbytes_out.
 
+sc_key(<ctr>) : any
+sc0_key : any
+sc1_key : any
+sc2_key : any
+  Returns the key used to match the currently tracked counter.
+
 sc_sess_cnt(<ctr>[,<table>]) : integer
 sc0_sess_cnt([<table>]) : integer
 sc1_sess_cnt([<table>]) : integer
index 7f788f8f7ddd27e688449d0ddfbeab57d5f6b5c4..eebf3354dd173d3626ef0138a402cda51191bf47 100644 (file)
@@ -5115,6 +5115,32 @@ smp_fetch_sc_kbytes_out(const struct arg *args, struct sample *smp, const char *
        return 1;
 }
 
+/* set <smp> to the key associated to the stream's tracked entry.
+ * Supports being called as "sc[0-9]_key" or "sc_key" only.
+ */
+static int
+smp_fetch_sc_key(const struct arg *args, struct sample *smp, const char *kw, void *private)
+{
+       struct stkctr tmpstkctr;
+       struct stkctr *stkctr;
+       struct stksess *entry;
+
+       stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr);
+       if (!stkctr)
+               return 0;
+
+       entry = stkctr_entry(stkctr);
+       if (entry != NULL) {
+               int ret = stkey_to_smp(smp, stksess_getkey(stkctr->table, entry), stkctr->table->type);
+
+               if (stkctr == &tmpstkctr)
+                       stktable_release(stkctr->table, entry);
+
+               return !!ret;
+       }
+       return 0; /* nothing currently tracked */
+}
+
 /* set <smp> to the data rate sent to clients in bytes/s, as found in the
  * stream's tracked frontend counters. Supports being called as
  * "sc[0-9]_bytes_out_rate" or "src_bytes_out_rate" only.
@@ -6049,6 +6075,7 @@ static struct sample_fetch_kw_list smp_fetch_keywords = {ILH, {
        { "sc_inc_gpc1",        smp_fetch_sc_inc_gpc1,       ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
        { "sc_kbytes_in",       smp_fetch_sc_kbytes_in,      ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
        { "sc_kbytes_out",      smp_fetch_sc_kbytes_out,     ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
+       { "sc_key",             smp_fetch_sc_key,            ARG1(1,SINT),     NULL, SMP_T_ANY,  SMP_USE_INTRN, },
        { "sc_sess_cnt",        smp_fetch_sc_sess_cnt,       ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
        { "sc_sess_rate",       smp_fetch_sc_sess_rate,      ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
        { "sc_tracked",         smp_fetch_sc_tracked,        ARG2(1,SINT,TAB), NULL, SMP_T_BOOL, SMP_USE_INTRN, },
@@ -6077,6 +6104,7 @@ static struct sample_fetch_kw_list smp_fetch_keywords = {ILH, {
        { "sc0_inc_gpc1",       smp_fetch_sc_inc_gpc1,       ARG1(0,TAB),      NULL, SMP_T_SINT, SMP_USE_INTRN, },
        { "sc0_kbytes_in",      smp_fetch_sc_kbytes_in,      ARG1(0,TAB),      NULL, SMP_T_SINT, SMP_USE_L4CLI, },
        { "sc0_kbytes_out",     smp_fetch_sc_kbytes_out,     ARG1(0,TAB),      NULL, SMP_T_SINT, SMP_USE_L4CLI, },
+       { "sc0_key",            smp_fetch_sc_key,            0,                NULL, SMP_T_ANY,  SMP_USE_INTRN, },
        { "sc0_sess_cnt",       smp_fetch_sc_sess_cnt,       ARG1(0,TAB),      NULL, SMP_T_SINT, SMP_USE_INTRN, },
        { "sc0_sess_rate",      smp_fetch_sc_sess_rate,      ARG1(0,TAB),      NULL, SMP_T_SINT, SMP_USE_INTRN, },
        { "sc0_tracked",        smp_fetch_sc_tracked,        ARG1(0,TAB),      NULL, SMP_T_BOOL, SMP_USE_INTRN, },
@@ -6106,6 +6134,7 @@ static struct sample_fetch_kw_list smp_fetch_keywords = {ILH, {
        { "sc1_inc_gpc1",       smp_fetch_sc_inc_gpc1,       ARG1(0,TAB),      NULL, SMP_T_SINT, SMP_USE_INTRN, },
        { "sc1_kbytes_in",      smp_fetch_sc_kbytes_in,      ARG1(0,TAB),      NULL, SMP_T_SINT, SMP_USE_L4CLI, },
        { "sc1_kbytes_out",     smp_fetch_sc_kbytes_out,     ARG1(0,TAB),      NULL, SMP_T_SINT, SMP_USE_L4CLI, },
+       { "sc1_key",            smp_fetch_sc_key,            0,                NULL, SMP_T_ANY,  SMP_USE_INTRN, },
        { "sc1_sess_cnt",       smp_fetch_sc_sess_cnt,       ARG1(0,TAB),      NULL, SMP_T_SINT, SMP_USE_INTRN, },
        { "sc1_sess_rate",      smp_fetch_sc_sess_rate,      ARG1(0,TAB),      NULL, SMP_T_SINT, SMP_USE_INTRN, },
        { "sc1_tracked",        smp_fetch_sc_tracked,        ARG1(0,TAB),      NULL, SMP_T_BOOL, SMP_USE_INTRN, },
@@ -6134,6 +6163,7 @@ static struct sample_fetch_kw_list smp_fetch_keywords = {ILH, {
        { "sc2_inc_gpc1",       smp_fetch_sc_inc_gpc1,       ARG1(0,TAB),      NULL, SMP_T_SINT, SMP_USE_INTRN, },
        { "sc2_kbytes_in",      smp_fetch_sc_kbytes_in,      ARG1(0,TAB),      NULL, SMP_T_SINT, SMP_USE_L4CLI, },
        { "sc2_kbytes_out",     smp_fetch_sc_kbytes_out,     ARG1(0,TAB),      NULL, SMP_T_SINT, SMP_USE_L4CLI, },
+       { "sc2_key",            smp_fetch_sc_key,            0,                NULL, SMP_T_ANY,  SMP_USE_INTRN, },
        { "sc2_sess_cnt",       smp_fetch_sc_sess_cnt,       ARG1(0,TAB),      NULL, SMP_T_SINT, SMP_USE_INTRN, },
        { "sc2_sess_rate",      smp_fetch_sc_sess_rate,      ARG1(0,TAB),      NULL, SMP_T_SINT, SMP_USE_INTRN, },
        { "sc2_tracked",        smp_fetch_sc_tracked,        ARG1(0,TAB),      NULL, SMP_T_BOOL, SMP_USE_INTRN, },