]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: counters: store a tgroup step for extra_counters to access multiple tgroups
authorWilly Tarreau <w@1wt.eu>
Wed, 25 Feb 2026 08:53:13 +0000 (09:53 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 26 Feb 2026 16:03:53 +0000 (17:03 +0100)
We'll need to permit any user to update its own tgroup's extra counters
instead of the global ones. For this we now store the per-tgroup step
between two consecutive data storages, for when they're stored in a
tgroup array. When shared (e.g. resolvers or listeners), we just store
zero to indicate that it doesn't scale with tgroups. For now only the
registration was handled, it's not used yet.

include/haproxy/counters-t.h
include/haproxy/counters.h
include/haproxy/stats.h
src/proxy.c
src/resolvers.c
src/server.c
src/stats.c

index 9a45609e2740c0df428518030e6c8ba912ab32a0..0dba60e43205cb9d1d1d5e4ff34cc6e57540dc7d 100644 (file)
@@ -199,6 +199,7 @@ enum counters_type {
 struct extra_counters {
        char **datap; /* points to pointer to heap containing counters allocated in a linear fashion */
        size_t size; /* size of allocated data */
+       size_t tgrp_step; /* distance in words between two datap for consecutive tgroups, 0 for single */
        enum counters_type type; /* type of object containing the counters */
 };
 
index f40dd6d844aabd2290b5c3bfbafc8cedc02b4335..1f97d9dfc8f12dc7b64d86b4d89fd852508658bc 100644 (file)
@@ -109,13 +109,14 @@ void counters_be_shared_drop(struct be_counters_shared *counters);
                ((void *)(*(counters)->datap + (mod)->counters_off[(counters)->type])) : \
                (trash_counters))
 
-#define EXTRA_COUNTERS_REGISTER(counters, ctype, alloc_failed_label, storage \
+#define EXTRA_COUNTERS_REGISTER(counters, ctype, alloc_failed_label, storage, step) \
        do {                                                         \
                typeof(*counters) _ctr;                              \
                _ctr = calloc(1, sizeof(*_ctr));                     \
                if (!_ctr)                                           \
                        goto alloc_failed_label;                     \
                _ctr->type = (ctype);                                \
+               _ctr->tgrp_step = (step);                            \
                _ctr->datap = (storage);                             \
                *(counters) = _ctr;                                  \
        } while (0)
index a02bcb6dd6a46d75b6a3d40a87a97cbed35f48e6..fdcc5bebf2927d7898d8f416963b2f1a76564d2c 100644 (file)
@@ -168,7 +168,8 @@ static inline enum stats_domain_px_cap stats_px_get_cap(uint32_t domain)
 }
 
 int stats_allocate_proxy_counters_internal(struct extra_counters **counters,
-                                           int type, int px_cap, char **storage);
+                                           int type, int px_cap,
+                                           char **storage, size_t step);
 int stats_allocate_proxy_counters(struct proxy *px);
 
 void stats_register_module(struct stats_module *m);
index ed6a92c1cc434151da564067cd86f1ab39160e63..70a2e5add8c05ef58cb5dd5cd78bab78eb631996 100644 (file)
@@ -4915,7 +4915,9 @@ static int cli_parse_add_backend(char **args, char *payload, struct appctx *appc
        if (!stats_allocate_proxy_counters_internal(&px->extra_counters_be,
                                                    COUNTERS_BE,
                                                    STATS_PX_CAP_BE,
-                                                   &px->per_tgrp->extra_counters_be_storage)) {
+                                                   &px->per_tgrp->extra_counters_be_storage,
+                                                   &px->per_tgrp[1].extra_counters_be_storage -
+                                                   &px->per_tgrp[0].extra_counters_be_storage)) {
                memprintf(&msg, "failed to allocate extra counters");
                goto err;
        }
index 4a62427ac68dc89c85793ff872b0179e0deef99f..abbe54aca5ecb99368a815e9db41a8024e0ecac7 100644 (file)
@@ -2906,7 +2906,7 @@ int resolv_allocate_counters(struct list *stat_modules)
        list_for_each_entry(resolvers, &sec_resolvers, list) {
                list_for_each_entry(ns, &resolvers->nameservers, list) {
                        EXTRA_COUNTERS_REGISTER(&ns->extra_counters, COUNTERS_RSLV,
-                                               alloc_failed, &ns->extra_counters_storage);
+                                               alloc_failed, &ns->extra_counters_storage, 0);
 
                        list_for_each_entry(mod, stat_modules, list) {
                                EXTRA_COUNTERS_ADD(mod,
index 536f96a36419746eb63289ca41b8ce0576bfc045..851e0e55e9c5df5128c557b65023dafccff416a6 100644 (file)
@@ -6286,7 +6286,9 @@ static int cli_parse_add_server(char **args, char *payload, struct appctx *appct
        if (!stats_allocate_proxy_counters_internal(&srv->extra_counters,
                                                    COUNTERS_SV,
                                                    STATS_PX_CAP_SRV,
-                                                   &srv->per_tgrp->extra_counters_storage)) {
+                                                   &srv->per_tgrp->extra_counters_storage,
+                                                   &srv->per_tgrp[1].extra_counters_storage -
+                                                   &srv->per_tgrp[0].extra_counters_storage)) {
                ha_alert("failed to allocate extra counters for server.\n");
                goto out;
        }
index c8347bf676608115aacd294ac88a13aef5bdde17..08e8c6fdf2f2bfb9512739ef762e68a760ca2ff4 100644 (file)
@@ -1094,11 +1094,12 @@ static void cli_io_handler_release_dump_stat_file(struct appctx *appctx)
 }
 
 int stats_allocate_proxy_counters_internal(struct extra_counters **counters,
-                                           int type, int px_cap, char **storage)
+                                           int type, int px_cap,
+                                           char **storage, size_t step)
 {
        struct stats_module *mod;
 
-       EXTRA_COUNTERS_REGISTER(counters, type, alloc_failed, storage);
+       EXTRA_COUNTERS_REGISTER(counters, type, alloc_failed, storage, step);
 
        list_for_each_entry(mod, &stats_module_list[STATS_DOMAIN_PROXY], list) {
                if (!(stats_px_get_cap(mod->domain_flags) & px_cap))
@@ -1134,7 +1135,9 @@ int stats_allocate_proxy_counters(struct proxy *px)
                if (!stats_allocate_proxy_counters_internal(&px->extra_counters_fe,
                                                            COUNTERS_FE,
                                                            STATS_PX_CAP_FE,
-                                                           &px->per_tgrp->extra_counters_fe_storage)) {
+                                                           &px->per_tgrp->extra_counters_fe_storage,
+                                                           &px->per_tgrp[1].extra_counters_fe_storage -
+                                                           &px->per_tgrp[0].extra_counters_fe_storage)) {
                        return 0;
                }
        }
@@ -1143,7 +1146,9 @@ int stats_allocate_proxy_counters(struct proxy *px)
                if (!stats_allocate_proxy_counters_internal(&px->extra_counters_be,
                                                            COUNTERS_BE,
                                                            STATS_PX_CAP_BE,
-                                                           &px->per_tgrp->extra_counters_be_storage)) {
+                                                           &px->per_tgrp->extra_counters_be_storage,
+                                                           &px->per_tgrp[1].extra_counters_be_storage -
+                                                           &px->per_tgrp[0].extra_counters_be_storage)) {
                        return 0;
                }
        }
@@ -1152,7 +1157,9 @@ int stats_allocate_proxy_counters(struct proxy *px)
                if (!stats_allocate_proxy_counters_internal(&sv->extra_counters,
                                                            COUNTERS_SV,
                                                            STATS_PX_CAP_SRV,
-                                                           &sv->per_tgrp->extra_counters_storage)) {
+                                                           &sv->per_tgrp->extra_counters_storage,
+                                                           &sv->per_tgrp[1].extra_counters_storage -
+                                                           &sv->per_tgrp[0].extra_counters_storage)) {
                        return 0;
                }
        }
@@ -1161,7 +1168,7 @@ int stats_allocate_proxy_counters(struct proxy *px)
                if (!stats_allocate_proxy_counters_internal(&li->extra_counters,
                                                            COUNTERS_LI,
                                                            STATS_PX_CAP_LI,
-                                                           &li->extra_counters_storage)) {
+                                                           &li->extra_counters_storage, 0)) {
                        return 0;
                }
        }