From: Aurelien DARRAGON Date: Wed, 12 Mar 2025 19:04:49 +0000 (+0100) Subject: MINOR: stats: add .generic explicit field in stat_col struct X-Git-Tag: v3.2-dev8~20 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3c1b00b127741d8f68755c1a87acc531dbd81305;p=thirdparty%2Fhaproxy.git MINOR: stats: add .generic explicit field in stat_col struct Further extend logic implemented in 65624876 ("MINOR: stats: introduce a more expressive stat definition method") and 4e9e8418 ("MINOR: stats: prepare stats-file support for values other than FN_COUNTER"): we don't rely anymore on the presence of the capability to know if the metric is generic or not. This is because it prevents us from setting a capability on static statistics. Yet it could be useful to set the capability even on static metrics, thus we add a dedicated .generic bit to tell haproxy that the metric is generic and can be handled automatically by the API. Also, ME_NEW_* helpers are not explicitly associated to generic metric definition (as it was already the case before) to avoid ambiguities. It may change in the future as we may need to use the new definition method to define static metrics (without the generic bit set). But for now it isn't the case as this need definition was implemented for generic metrics support in the first place. If we want to define static metrics using the API, we could add a new set of helpers for instance. --- diff --git a/include/haproxy/stats-t.h b/include/haproxy/stats-t.h index c6b639ad4..f16bb3764 100644 --- a/include/haproxy/stats-t.h +++ b/include/haproxy/stats-t.h @@ -349,6 +349,8 @@ struct stat_col { uint32_t type; /* combination of field_nature and field_format */ uint8_t cap; /* mask of stats_domain_px_cap to restrain metrics to an object types subset */ + uint8_t generic; /* bit set if generic */ + /* 2 bytes hole */ /* used only for generic metrics */ struct { diff --git a/include/haproxy/stats.h b/include/haproxy/stats.h index e227f3f96..af9965281 100644 --- a/include/haproxy/stats.h +++ b/include/haproxy/stats.h @@ -79,7 +79,7 @@ int stats_emit_field_tags(struct buffer *out, const struct field *f, /* Returns true if is fully defined, false if only used as name-desc. */ static inline int stcol_is_generic(const struct stat_col *col) { - return !!(col->cap); + return col->generic; } static inline enum field_format stcol_format(const struct stat_col *col) diff --git a/src/stats-proxy.c b/src/stats-proxy.c index d6c3defa2..0c10ae842 100644 --- a/src/stats-proxy.c +++ b/src/stats-proxy.c @@ -19,26 +19,29 @@ #include #include -/* Define a new metric for both frontend and backend sides. */ +/* Define a new generic metric for both frontend and backend sides. */ #define ME_NEW_PX(name_f, nature, format, offset_f, cap_f, desc_f) \ { .name = (name_f), .desc = (desc_f), .type = (nature)|(format), \ .metric.offset[0] = offsetof(struct fe_counters, offset_f), \ .metric.offset[1] = offsetof(struct be_counters, offset_f), \ .cap = (cap_f), \ + .generic = 1, \ } -/* Define a new metric for frontend side only. */ +/* Define a new generic metric for frontend side only. */ #define ME_NEW_FE(name_f, nature, format, offset_f, cap_f, desc_f) \ { .name = (name_f), .desc = (desc_f), .type = (nature)|(format), \ .metric.offset[0] = offsetof(struct fe_counters, offset_f), \ .cap = (cap_f), \ + .generic = 1, \ } -/* Define a new metric for backend side only. */ +/* Define a new generic metric for backend side only. */ #define ME_NEW_BE(name_f, nature, format, offset_f, cap_f, desc_f) \ { .name = (name_f), .desc = (desc_f), .type = (nature)|(format), \ .metric.offset[1] = offsetof(struct be_counters, offset_f), \ .cap = (cap_f), \ + .generic = 1, \ } const struct stat_col stat_cols_px[ST_I_PX_MAX] = {