]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: stats: add .generic explicit field in stat_col struct
authorAurelien DARRAGON <adarragon@haproxy.com>
Wed, 12 Mar 2025 19:04:49 +0000 (20:04 +0100)
committerAurelien DARRAGON <adarragon@haproxy.com>
Thu, 20 Mar 2025 10:37:21 +0000 (11:37 +0100)
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.

include/haproxy/stats-t.h
include/haproxy/stats.h
src/stats-proxy.c

index c6b639ad43961668654603ad892fced597457aa2..f16bb376400592d4c2567c7dee87c805bb8c2630 100644 (file)
@@ -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 {
index e227f3f96375728689ecb70c65485f00c789112e..af9965281971e725273fea0502a60dd1f73a0417 100644 (file)
@@ -79,7 +79,7 @@ int stats_emit_field_tags(struct buffer *out, const struct field *f,
 /* Returns true if <col> 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)
index d6c3defa2e870e660aa3b564f4ca36a4c9755801..0c10ae8425c278f7076d4792f1b64cd8adffc57e 100644 (file)
 #include <haproxy/time.h>
 #include <haproxy/tools.h>
 
-/* 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] = {