]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
REORG: stats/counters: move extra_counters to counters not stats
authorWilly Tarreau <w@1wt.eu>
Tue, 24 Feb 2026 17:57:05 +0000 (18:57 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 26 Feb 2026 07:24:03 +0000 (08:24 +0100)
It was always difficult to find extra_counters when the rest of the
counters are now in counters-t.h. Let's move the types to counters-t.h
and the macros to counters.h. Stats include them since they're used
there. But some users could be cleaned from the stats definitions now.

include/haproxy/counters-t.h
include/haproxy/counters.h
include/haproxy/quic_conn.h
include/haproxy/stats-t.h
include/haproxy/stats.h

index fde3930ddafe55a78f5fbb0cf79006062a73f2bf..8c21d9b7088cc361852e1e590bb1865f174e7a6c 100644 (file)
@@ -185,6 +185,27 @@ struct be_counters {
        } p;                                    /* protocol-specific stats */
 };
 
+/* extra counters that are registered at boot by various modules */
+enum counters_type {
+       COUNTERS_FE = 0,
+       COUNTERS_BE,
+       COUNTERS_SV,
+       COUNTERS_LI,
+       COUNTERS_RSLV,
+
+       COUNTERS_OFF_END /* must always be last */
+};
+
+struct extra_counters {
+       char *data; /* heap containing counters allocated in a linear fashion */
+       size_t size; /* size of allocated data */
+       enum counters_type type; /* type of object containing the counters */
+};
+
+
+#define EXTRA_COUNTERS(name) \
+       struct extra_counters *name
+
 #endif /* _HAPROXY_COUNTERS_T_H */
 
 /*
index a6a68623d80850811da6ccd5f7149c267388b47a..a9e6c30ea06e7cd315fcc85c40dbfebd6c7402da 100644 (file)
@@ -27,6 +27,8 @@
 #include <haproxy/counters-t.h>
 #include <haproxy/guid-t.h>
 
+extern THREAD_LOCAL void *trash_counters;
+
 int counters_fe_shared_prepare(struct fe_counters_shared *counters, const struct guid_node *guid, char **errmsg);
 int counters_be_shared_prepare(struct be_counters_shared *counters, const struct guid_node *guid, char **errmsg);
 
@@ -101,4 +103,50 @@ void counters_be_shared_drop(struct be_counters_shared *counters);
        __ret;                                                                \
 })
 
+/* Manipulation of extra_counters, for boot-time registrable modules */
+#define EXTRA_COUNTERS_GET(counters, mod) \
+       (likely(counters) ? \
+               ((void *)((counters)->data + (mod)->counters_off[(counters)->type])) : \
+               (trash_counters))
+
+#define EXTRA_COUNTERS_REGISTER(counters, ctype, alloc_failed_label) \
+       do {                                                         \
+               typeof(*counters) _ctr;                              \
+               _ctr = calloc(1, sizeof(*_ctr));                     \
+               if (!_ctr)                                           \
+                       goto alloc_failed_label;                     \
+               _ctr->type = (ctype);                                \
+               *(counters) = _ctr;                                  \
+       } while (0)
+
+#define EXTRA_COUNTERS_ADD(mod, counters, new_counters, csize) \
+       do {                                                   \
+               typeof(counters) _ctr = (counters);            \
+               (mod)->counters_off[_ctr->type] = _ctr->size;  \
+               _ctr->size += (csize);                         \
+       } while (0)
+
+#define EXTRA_COUNTERS_ALLOC(counters, alloc_failed_label) \
+       do {                                               \
+               typeof(counters) _ctr = (counters);        \
+               _ctr->data = malloc((_ctr)->size);         \
+               if (!_ctr->data)                           \
+                       goto alloc_failed_label;           \
+       } while (0)
+
+#define EXTRA_COUNTERS_INIT(counters, mod, init_counters, init_counters_size) \
+       do {                                                                  \
+               typeof(counters) _ctr = (counters);                           \
+               memcpy(_ctr->data + mod->counters_off[_ctr->type],            \
+                      (init_counters), (init_counters_size));                \
+       } while (0)
+
+#define EXTRA_COUNTERS_FREE(counters)           \
+       do {                                    \
+               if (counters) {                 \
+                       free((counters)->data); \
+                       free(counters);         \
+               }                               \
+       } while (0)
+
 #endif /* _HAPROXY_COUNTERS_H */
index 5eb9f92c3ebb763c105e9f639ba9199bf12e54fa..92e6c1c74033e28f8ffda538df1f95af598dc499 100644 (file)
@@ -30,6 +30,7 @@
 #include <import/eb64tree.h>
 #include <import/ebmbtree.h>
 
+#include <haproxy/counters.h>
 #include <haproxy/chunk.h>
 #include <haproxy/dynbuf.h>
 #include <haproxy/ncbmbuf.h>
index 1ca0621da3dedbccdd7e358110b5c6c47b444a2f..8c857a23b4fa9813afc5cc0a538467ec6bba7735 100644 (file)
@@ -25,6 +25,7 @@
 #include <import/ebtree-t.h>
 #include <haproxy/api-t.h>
 #include <haproxy/buf-t.h>
+#include <haproxy/counters-t.h>
 
 /* Flags for applet.ctx.stats.flags */
 #define STAT_F_FMT_HTML   0x00000001    /* dump the stats in HTML format */
@@ -515,16 +516,6 @@ struct field {
        } u;
 };
 
-enum counters_type {
-       COUNTERS_FE = 0,
-       COUNTERS_BE,
-       COUNTERS_SV,
-       COUNTERS_LI,
-       COUNTERS_RSLV,
-
-       COUNTERS_OFF_END
-};
-
 /* Entity used to generate statistics on an HAProxy component */
 struct stats_module {
        struct list list;
@@ -543,12 +534,6 @@ struct stats_module {
        char clearable;          /* reset on a clear counters */
 };
 
-struct extra_counters {
-       char *data; /* heap containing counters allocated in a linear fashion */
-       size_t size; /* size of allocated data */
-       enum counters_type type; /* type of object containing the counters */
-};
-
 /* stats_domain is used in a flag as a 1 byte field */
 enum stats_domain {
        STATS_DOMAIN_PROXY = 0,
@@ -597,54 +582,4 @@ struct show_stat_ctx {
        enum stat_state state;  /* phase of output production */
 };
 
-extern THREAD_LOCAL void *trash_counters;
-
-#define EXTRA_COUNTERS(name) \
-       struct extra_counters *name
-
-#define EXTRA_COUNTERS_GET(counters, mod) \
-       (likely(counters) ? \
-               ((void *)((counters)->data + (mod)->counters_off[(counters)->type])) : \
-               (trash_counters))
-
-#define EXTRA_COUNTERS_REGISTER(counters, ctype, alloc_failed_label) \
-       do {                                                         \
-               typeof(*counters) _ctr;                              \
-               _ctr = calloc(1, sizeof(*_ctr));                     \
-               if (!_ctr)                                           \
-                       goto alloc_failed_label;                     \
-               _ctr->type = (ctype);                                \
-               *(counters) = _ctr;                                  \
-       } while (0)
-
-#define EXTRA_COUNTERS_ADD(mod, counters, new_counters, csize) \
-       do {                                                   \
-               typeof(counters) _ctr = (counters);            \
-               (mod)->counters_off[_ctr->type] = _ctr->size;  \
-               _ctr->size += (csize);                         \
-       } while (0)
-
-#define EXTRA_COUNTERS_ALLOC(counters, alloc_failed_label) \
-       do {                                               \
-               typeof(counters) _ctr = (counters);        \
-               _ctr->data = malloc((_ctr)->size);         \
-               if (!_ctr->data)                           \
-                       goto alloc_failed_label;           \
-       } while (0)
-
-#define EXTRA_COUNTERS_INIT(counters, mod, init_counters, init_counters_size) \
-       do {                                                                  \
-               typeof(counters) _ctr = (counters);                           \
-               memcpy(_ctr->data + mod->counters_off[_ctr->type],            \
-                      (init_counters), (init_counters_size));                \
-       } while (0)
-
-#define EXTRA_COUNTERS_FREE(counters)           \
-       do {                                    \
-               if (counters) {                 \
-                       free((counters)->data); \
-                       free(counters);         \
-               }                               \
-       } while (0)
-
 #endif /* _HAPROXY_STATS_T_H */
index ca77513ee3b3bfae3c8f329490afa4de5c8bd081..acebd27b89cf0f6ea6f8bf07bbbc3d8f9971fa31 100644 (file)
@@ -24,6 +24,7 @@
 #define _HAPROXY_STATS_H
 
 #include <haproxy/api.h>
+#include <haproxy/counters.h>
 #include <haproxy/listener-t.h>
 #include <haproxy/stats-t.h>
 #include <haproxy/tools-t.h>