]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
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>
Tue, 5 Nov 2024 14:36:41 +0000 (15:36 +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.

addons/promex/service-prometheus.c

index 7229930bc4f4b60431e8cd77cfcf19f19c9a01e3..5d26733edd288e9977896869138dbdbab200d070 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));