mirror of
https://github.com/haproxy/haproxy.git
synced 2026-02-27 20:01:15 -05:00
MINOR: counters: store a tgroup step for extra_counters to access multiple tgroups
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.
This commit is contained in:
parent
04a9f86a85
commit
7ac47910a2
7 changed files with 25 additions and 11 deletions
|
|
@ -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 */
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
19
src/stats.c
19
src/stats.c
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue