]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: sample: return the number of the current thread group
authorWilly Tarreau <w@1wt.eu>
Tue, 14 Apr 2026 15:02:37 +0000 (17:02 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 14 Apr 2026 15:05:34 +0000 (17:05 +0200)
Just like we have a sample fetch function that returns the number of the
current thread, let's have the same with the thread group number. This
can be useful for troubleshooting, given that certain things are currently
per thread-group (e.g. idle backend connections, certain LB algos etc).

doc/configuration.txt
src/sample.c

index 4288e8881637c05954f725f1f8ae82113331103a..43b6e6b5f01e0fcea316e0f65b196dc081297e41 100644 (file)
@@ -24019,6 +24019,11 @@ term_events : string
   It must only be used for debugging purpose. The exact format is not
   documented because it may evolve depending on developers requirements.
 
+tgroup : integer
+  Returns an integer value corresponding to the position of the thread group
+  calling the function, between 0 and (global.thread-groups - 1). This is
+  useful for logging and debugging purposes.
+
 thread : integer
   Returns an integer value corresponding to the position of the thread calling
   the function, between 0 and (global.nbthread-1). This is useful for logging
index 902db705646f25d92fd996bc81e43beea3349ae9..370c0156a1ca2891044e0c4ec5b945b2e1bfd3a8 100644 (file)
@@ -5080,6 +5080,15 @@ smp_fetch_thread(const struct arg *args, struct sample *smp, const char *kw, voi
        return 1;
 }
 
+/* returns the number of the current thread group (between 0 and nbtgroups-1) */
+static int
+smp_fetch_tgroup(const struct arg *args, struct sample *smp, const char *kw, void *private)
+{
+       smp->data.type = SMP_T_SINT;
+       smp->data.u.sint = tgid - 1; // tgid starts at 1
+       return 1;
+}
+
 /* generate a random 32-bit integer for whatever purpose, with an optional
  * range specified in argument.
  */
@@ -5659,6 +5668,7 @@ static struct sample_fetch_kw_list smp_kws = {ILH, {
        { "proc",         smp_fetch_proc,  0,            NULL, SMP_T_SINT, SMP_USE_CONST },
        { "quic_enabled", smp_fetch_quic_enabled, 0,     NULL, SMP_T_BOOL, SMP_USE_CONST },
        { "thread",       smp_fetch_thread,  0,          NULL, SMP_T_SINT, SMP_USE_CONST },
+       { "tgroup",       smp_fetch_tgroup,  0,          NULL, SMP_T_SINT, SMP_USE_CONST },
        { "rand",         smp_fetch_rand,  ARG1(0,SINT), NULL, SMP_T_SINT, SMP_USE_CONST },
        { "stopping",     smp_fetch_stopping, 0,         NULL, SMP_T_BOOL, SMP_USE_INTRN },
        { "uptime",       smp_fetch_uptime,   0,         NULL, SMP_T_SINT, SMP_USE_CONST },