]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: counters: change the fill_stats() API to pass the module and extra_counters
authorWilly Tarreau <w@1wt.eu>
Wed, 25 Feb 2026 10:44:48 +0000 (11:44 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 26 Feb 2026 07:24:03 +0000 (08:24 +0100)
We'll soon need to iterate over thread groups in the fill_stats() functions,
so let's first pass the extra_counters and stats_module pointers to the
fill_stats functions. They now call EXTRA_COUNTERS_GET() themselves with
these elements in order to retrieve the required pointer. Nothing else
changed, and it's getting even a bit more transparent for callers.

This doesn't change anything visible however.

addons/promex/service-prometheus.c
include/haproxy/stats-t.h
src/h3_stats.c
src/mux_h1.c
src/mux_h2.c
src/quic_stats.c
src/resolvers.c
src/ssl_sock.c
src/stats-proxy.c

index d3a1f64428c0c9e9c25562056fd8ae4fbba6c8c4..0cd5a6c0fe20ef13d886e76e323b772f293f5cf4 100644 (file)
@@ -626,8 +626,6 @@ static int promex_dump_front_metrics(struct appctx *appctx, struct htx *htx)
        }
 
        list_for_each_entry_from(mod, &stats_module_list[STATS_DOMAIN_PROXY], list) {
-               void *counters;
-
                if (!(stats_px_get_cap(mod->domain_flags) & STATS_PX_CAP_FE))
                        continue;
 
@@ -664,8 +662,7 @@ static int promex_dump_front_metrics(struct appctx *appctx, struct htx *htx)
                                if ((px->flags & PR_FL_DISABLED) || px->uuid <= 0 || !(px->cap & PR_CAP_FE))
                                        goto next_px2;
 
-                               counters = EXTRA_COUNTERS_GET(px->extra_counters_fe, mod);
-                               if (!mod->fill_stats(counters, stats + ctx->field_num, &ctx->mod_field_num))
+                               if (!mod->fill_stats(mod, px->extra_counters_fe, stats + ctx->field_num, &ctx->mod_field_num))
                                        return -1;
 
                                val = stats[ctx->field_num + ctx->mod_field_num];
@@ -817,8 +814,6 @@ static int promex_dump_listener_metrics(struct appctx *appctx, struct htx *htx)
        }
 
        list_for_each_entry_from(mod, &stats_module_list[STATS_DOMAIN_PROXY], list) {
-               void *counters;
-
                if (!(stats_px_get_cap(mod->domain_flags) & STATS_PX_CAP_LI))
                        continue;
 
@@ -864,8 +859,7 @@ static int promex_dump_listener_metrics(struct appctx *appctx, struct htx *htx)
                                        labels[lb_idx+1].name  = ist("mod");
                                        labels[lb_idx+1].value = ist2(mod->name, strlen(mod->name));
 
-                                       counters = EXTRA_COUNTERS_GET(li->extra_counters, mod);
-                                       if (!mod->fill_stats(counters, stats + ctx->field_num, &ctx->mod_field_num))
+                                       if (!mod->fill_stats(mod, li->extra_counters, stats + ctx->field_num, &ctx->mod_field_num))
                                                return -1;
 
                                        val = stats[ctx->field_num + ctx->mod_field_num];
@@ -1113,8 +1107,6 @@ static int promex_dump_back_metrics(struct appctx *appctx, struct htx *htx)
        }
 
        list_for_each_entry_from(mod, &stats_module_list[STATS_DOMAIN_PROXY], list) {
-               void *counters;
-
                if (!(stats_px_get_cap(mod->domain_flags) & STATS_PX_CAP_BE))
                        continue;
 
@@ -1151,8 +1143,7 @@ static int promex_dump_back_metrics(struct appctx *appctx, struct htx *htx)
                                if ((px->flags & PR_FL_DISABLED) || px->uuid <= 0 || !(px->cap & PR_CAP_BE))
                                        goto next_px2;
 
-                               counters = EXTRA_COUNTERS_GET(px->extra_counters_be, mod);
-                               if (!mod->fill_stats(counters, stats + ctx->field_num, &ctx->mod_field_num))
+                               if (!mod->fill_stats(mod, px->extra_counters_be, stats + ctx->field_num, &ctx->mod_field_num))
                                        return -1;
 
                                val = stats[ctx->field_num + ctx->mod_field_num];
@@ -1420,8 +1411,6 @@ static int promex_dump_srv_metrics(struct appctx *appctx, struct htx *htx)
        }
 
        list_for_each_entry_from(mod, &stats_module_list[STATS_DOMAIN_PROXY], list) {
-               void *counters;
-
                if (!(stats_px_get_cap(mod->domain_flags) & STATS_PX_CAP_SRV))
                        continue;
 
@@ -1471,8 +1460,7 @@ static int promex_dump_srv_metrics(struct appctx *appctx, struct htx *htx)
                                                goto next_sv2;
 
 
-                                       counters = EXTRA_COUNTERS_GET(sv->extra_counters, mod);
-                                       if (!mod->fill_stats(counters, stats + ctx->field_num, &ctx->mod_field_num))
+                                       if (!mod->fill_stats(mod, sv->extra_counters, stats + ctx->field_num, &ctx->mod_field_num))
                                                goto error;
 
                                        val = stats[ctx->field_num + ctx->mod_field_num];
index 8c857a23b4fa9813afc5cc0a538467ec6bba7735..1479c4efd1ad4f0a3a24c70e2bd38c55eee59355 100644 (file)
@@ -521,8 +521,8 @@ struct stats_module {
        struct list list;
        const char *name;
 
-       /* functor used to generate the stats module using counters provided through data parameter */
-       int (*fill_stats)(void *data, struct field *, unsigned int *);
+       /* function used to generate the stats module using counters provided through data parameter */
+       int (*fill_stats)(struct stats_module *, struct extra_counters *, struct field *, unsigned int *);
 
        struct stat_col *stats;  /* statistics provided by the module */
        void *counters;          /* initial values of allocated counters */
index f50f5af0b64a399a6f4c5b9fd0185fd7782b4c1b..c89ce584e38fa68038033557051dbd9f8b91dd35 100644 (file)
@@ -129,9 +129,10 @@ static struct h3_counters {
        long long qpack_decoder_stream_error; /* total number of QPACK_DECODER_STREAM_ERROR errors received */
 } h3_counters;
 
-static int h3_fill_stats(void *data, struct field *stats, unsigned int *selected_field)
+static int h3_fill_stats(struct stats_module *mod, struct extra_counters *ctr,
+                         struct field *stats, unsigned int *selected_field)
 {
-       struct h3_counters *counters = data;
+       struct h3_counters *counters = EXTRA_COUNTERS_GET(ctr, mod);
        unsigned int current_field = (selected_field != NULL ? *selected_field : 0);
 
        for (; current_field < H3_STATS_COUNT; current_field++) {
index 430ff0da1e8a3d01dfafae12372499b9b4df1f6e..fc81636adf2078faf718526943523187787b6643 100644 (file)
@@ -272,9 +272,10 @@ static struct h1_counters {
 #endif
 } h1_counters;
 
-static int h1_fill_stats(void *data, struct field *stats, unsigned int *selected_field)
+static int h1_fill_stats(struct stats_module *mod, struct extra_counters *ctr,
+                         struct field *stats, unsigned int *selected_field)
 {
-       struct h1_counters *counters = data;
+       struct h1_counters *counters = EXTRA_COUNTERS_GET(ctr, mod);
        unsigned int current_field = (selected_field != NULL ? *selected_field : 0);
 
        for (; current_field < H1_STATS_COUNT; current_field++) {
index c6e8c993e2ba2eac60c58e69e01909fd8e1525e5..07ccf85485e0c04c0138b9e376986bf2fc143f1d 100644 (file)
@@ -371,9 +371,10 @@ static struct h2_counters {
        long long total_streams; /* total number of streams */
 } h2_counters;
 
-static int h2_fill_stats(void *data, struct field *stats, unsigned int *selected_field)
+static int h2_fill_stats(struct stats_module *mod, struct extra_counters *ctr,
+                         struct field *stats, unsigned int *selected_field)
 {
-       struct h2_counters *counters = data;
+       struct h2_counters *counters = EXTRA_COUNTERS_GET(ctr, mod);
        unsigned int current_field = (selected_field != NULL ? *selected_field : 0);
 
        for (; current_field < H2_STATS_COUNT; current_field++) {
index daee9456d01bbd2041695d6ea04eee55e9731dc8..3f2b5394165a1467d5d5014ce9fc681d7b45e6e1 100644 (file)
@@ -92,9 +92,10 @@ static struct stat_col quic_stats[] = {
 
 struct quic_counters quic_counters;
 
-static int quic_fill_stats(void *data, struct field *stats, unsigned int *selected_field)
+static int quic_fill_stats(struct stats_module *mod, struct extra_counters *ctr,
+                           struct field *stats, unsigned int *selected_field)
 {
-       struct quic_counters *counters = data;
+       struct quic_counters *counters = EXTRA_COUNTERS_GET(ctr, mod);
        unsigned int current_field = (selected_field != NULL ? *selected_field : 0);
 
        for (; current_field < QUIC_STATS_COUNT; current_field++) {
index 0c1cda0537e92f9a5846ec662a145502a73da3ab..d653482b7d65c3719ce4e9c78ca5fd755e15c377 100644 (file)
@@ -122,9 +122,10 @@ static struct stat_col resolv_stats[] = {
 
 static struct dns_counters dns_counters;
 
-static int resolv_fill_stats(void *d, struct field *stats, unsigned int *selected_field)
+static int resolv_fill_stats(struct stats_module *mod, struct extra_counters *ctr,
+                             struct field *stats, unsigned int *selected_field)
 {
-       struct dns_counters *counters = d;
+       struct dns_counters *counters = EXTRA_COUNTERS_GET(ctr, mod);
        unsigned int current_field = (selected_field != NULL ? *selected_field : 0);
 
        for (; current_field < RSLV_STAT_END; current_field++) {
@@ -2804,9 +2805,7 @@ static int stats_dump_resolv_to_buffer(struct stconn *sc,
        memset(stats, 0, sizeof(struct field) * stats_count);
 
        list_for_each_entry(mod, stat_modules, list) {
-               struct counters_node *counters = EXTRA_COUNTERS_GET(ns->extra_counters, mod);
-
-               if (!mod->fill_stats(counters, stats + idx, NULL))
+               if (!mod->fill_stats(mod, ns->extra_counters, stats + idx, NULL))
                        continue;
                idx += mod->stats_count;
        }
@@ -4080,7 +4079,7 @@ static int rslv_promex_fill_ts(void *unused, void *metric_ctx, unsigned int id,
        labels[1].name  = ist("nameserver");
        labels[1].value = ist(ns->id);
 
-       ret = resolv_fill_stats(ns->counters, stats, &id);
+       ret = resolv_fill_stats(&rslv_stats_module, ns->extra_counters, stats, &id);
        if (ret == 1)
                *field = stats[id];
        return ret;
index eb56179851386c4eb9ec7a880f64c5125f703e50..f841bb11c54c18fa014a064aaa32ec040a098a94 100644 (file)
@@ -194,9 +194,10 @@ static struct stat_col ssl_stats[] = {
 
 static struct ssl_counters ssl_counters;
 
-static int ssl_fill_stats(void *data, struct field *stats, unsigned int *selected_field)
+static int ssl_fill_stats(struct stats_module *mod, struct extra_counters *ctr,
+                          struct field *stats, unsigned int *selected_field)
 {
-       struct ssl_counters *counters = data;
+       struct ssl_counters *counters = EXTRA_COUNTERS_GET(ctr, mod);
        unsigned int current_field = (selected_field != NULL ? *selected_field : 0);
 
        for (; current_field < SSL_ST_STATS_COUNT; current_field++) {
index 8d15d7bdf47be2f7d2188384831aa0823543e4ea..278a4bf9c7694a63d761d37edfc665ccec41272f 100644 (file)
@@ -548,8 +548,6 @@ static int stats_dump_fe_line(struct stconn *sc, struct proxy *px)
                return 0;
 
        list_for_each_entry(mod, &stats_module_list[STATS_DOMAIN_PROXY], list) {
-               void *counters;
-
                if (ctx->flags & STAT_F_FMT_FILE)
                        continue;
 
@@ -558,8 +556,7 @@ static int stats_dump_fe_line(struct stconn *sc, struct proxy *px)
                        continue;
                }
 
-               counters = EXTRA_COUNTERS_GET(px->extra_counters_fe, mod);
-               if (!mod->fill_stats(counters, line + stats_count, NULL))
+               if (!mod->fill_stats(mod, px->extra_counters_fe, line + stats_count, NULL))
                        continue;
                stats_count += mod->stats_count;
        }
@@ -699,8 +696,6 @@ static int stats_dump_li_line(struct stconn *sc, struct proxy *px, struct listen
                return 0;
 
        list_for_each_entry(mod, &stats_module_list[STATS_DOMAIN_PROXY], list) {
-               void *counters;
-
                if (ctx->flags & STAT_F_FMT_FILE)
                        continue;
 
@@ -709,8 +704,7 @@ static int stats_dump_li_line(struct stconn *sc, struct proxy *px, struct listen
                        continue;
                }
 
-               counters = EXTRA_COUNTERS_GET(l->extra_counters, mod);
-               if (!mod->fill_stats(counters, line + stats_count, NULL))
+               if (!mod->fill_stats(mod, l->extra_counters, line + stats_count, NULL))
                        continue;
                stats_count += mod->stats_count;
        }
@@ -1137,8 +1131,6 @@ static int stats_dump_sv_line(struct stconn *sc, struct proxy *px, struct server
                return 0;
 
        list_for_each_entry(mod, &stats_module_list[STATS_DOMAIN_PROXY], list) {
-               void *counters;
-
                if (ctx->flags & STAT_F_FMT_FILE)
                        continue;
 
@@ -1150,8 +1142,7 @@ static int stats_dump_sv_line(struct stconn *sc, struct proxy *px, struct server
                        continue;
                }
 
-               counters = EXTRA_COUNTERS_GET(sv->extra_counters, mod);
-               if (!mod->fill_stats(counters, line + stats_count, NULL))
+               if (!mod->fill_stats(mod, sv->extra_counters, line + stats_count, NULL))
                        continue;
                stats_count += mod->stats_count;
        }
@@ -1378,8 +1369,6 @@ static int stats_dump_be_line(struct stconn *sc, struct proxy *px)
                return 0;
 
        list_for_each_entry(mod, &stats_module_list[STATS_DOMAIN_PROXY], list) {
-               struct extra_counters *counters;
-
                if (ctx->flags & STAT_F_FMT_FILE)
                        continue;
 
@@ -1391,8 +1380,7 @@ static int stats_dump_be_line(struct stconn *sc, struct proxy *px)
                        continue;
                }
 
-               counters = EXTRA_COUNTERS_GET(px->extra_counters_be, mod);
-               if (!mod->fill_stats(counters, line + stats_count, NULL))
+               if (!mod->fill_stats(mod, px->extra_counters_be, line + stats_count, NULL))
                        continue;
                stats_count += mod->stats_count;
        }