BUG/MEDIUM: promex: Fix dump of extra counters
authorChristopher Faulet <cfaulet@haproxy.com>
Tue, 5 Nov 2024 14:30:56 +0000 (15:30 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Wed, 6 Nov 2024 14:51:56 +0000 (15:51 +0100)
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.

(cherry picked from commit d1adfd9fe41b0f9f67944eec07348213a7debbf3)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>

addons/promex/service-prometheus.c

index 7229930..5d26733 100644 (file)
@@ -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));