From: Christopher Faulet Date: Tue, 5 Nov 2024 14:30:56 +0000 (+0100) Subject: BUG/MEDIUM: promex: Fix dump of extra counters X-Git-Tag: v3.1-dev12~40 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d1adfd9fe41b0f9f67944eec07348213a7debbf3;p=thirdparty%2Fhaproxy.git BUG/MEDIUM: promex: Fix dump of extra counters When extra counters are dumped for an entity (frontend, backend, server or listener), there is a filter on capabilities. Some extra counters are not available for all entities and must be ignored. However, when this was performed, the field number, used as an index to dump the metric value, was still incremented while it should not and leads to an overflow or a stats mix-up. This patch must be backported to 3.0. --- diff --git a/addons/promex/service-prometheus.c b/addons/promex/service-prometheus.c index 7229930bc4..5d26733edd 100644 --- a/addons/promex/service-prometheus.c +++ b/addons/promex/service-prometheus.c @@ -726,11 +726,8 @@ 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)) { - ctx->field_num += mod->stats_count; - ctx->mod_field_num = 0; + if (!(stats_px_get_cap(mod->domain_flags) & STATS_PX_CAP_FE)) continue; - } for (;ctx->mod_field_num < mod->stats_count; ctx->mod_field_num++) { name = ist2(mod->stats[ctx->mod_field_num].name, strlen(mod->stats[ctx->mod_field_num].name)); @@ -898,11 +895,8 @@ 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)) { - ctx->field_num += mod->stats_count; - ctx->mod_field_num = 0; + if (!(stats_px_get_cap(mod->domain_flags) & STATS_PX_CAP_LI)) continue; - } for (;ctx->mod_field_num < mod->stats_count; ctx->mod_field_num++) { name = ist2(mod->stats[ctx->mod_field_num].name, strlen(mod->stats[ctx->mod_field_num].name)); @@ -1179,11 +1173,8 @@ 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)) { - ctx->field_num += mod->stats_count; - ctx->mod_field_num = 0; + if (!(stats_px_get_cap(mod->domain_flags) & STATS_PX_CAP_BE)) continue; - } for (;ctx->mod_field_num < mod->stats_count; ctx->mod_field_num++) { name = ist2(mod->stats[ctx->mod_field_num].name, strlen(mod->stats[ctx->mod_field_num].name)); @@ -1437,11 +1428,8 @@ 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)) { - ctx->field_num += mod->stats_count; - ctx->mod_field_num = 0; + if (!(stats_px_get_cap(mod->domain_flags) & STATS_PX_CAP_SRV)) continue; - } for (;ctx->mod_field_num < mod->stats_count; ctx->mod_field_num++) { name = ist2(mod->stats[ctx->mod_field_num].name, strlen(mod->stats[ctx->mod_field_num].name));