From: Aurelien DARRAGON Date: Thu, 2 Feb 2023 16:27:27 +0000 (+0100) Subject: BUG/MEDIUM: stats: fix resolvers dump X-Git-Tag: v2.8-dev4~40 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e5958d0292222c6cc122b1b19b79c959ec27370b;p=thirdparty%2Fhaproxy.git BUG/MEDIUM: stats: fix resolvers dump In ("BUG/MEDIUM: stats: Rely on a local trash buffer to dump the stats"), we forgot to apply the patch in resolvers.c which provides the stats_dump_resolvers() function that is involved when dumping with "resolvers" domain. As a consequence, resolvers dump was broken because stats_dump_one_line(), which is used in stats_dump_resolv_to_buffer(), implicitely uses trash_chunk from stats.c to prepare the dump, and stats_putchk() is then called with global trash (currently empty) as output data. Given that trash_dump variable is static and thus only available within stats.c we change stats_putchk() function prototype so that the function does not take the output buffer as an argument. Instead, stats_putchk() will implicitly use the local trash_dump variable declared in stats.c. It will also prevent further mixups between stats_dump_* functions and stats_putchk(). This needs to be backported with ("BUG/MEDIUM: stats: Rely on a local trash buffer to dump the stats") --- diff --git a/include/haproxy/stats.h b/include/haproxy/stats.h index a8ffbc7047..90a4f51ef8 100644 --- a/include/haproxy/stats.h +++ b/include/haproxy/stats.h @@ -45,7 +45,7 @@ extern THREAD_LOCAL struct field info[]; extern THREAD_LOCAL struct field *stat_l[]; struct htx; -int stats_putchk(struct channel *chn, struct htx *htx, struct buffer *chk); +int stats_putchk(struct channel *chn, struct htx *htx); int stats_dump_one_line(const struct field *stats, size_t stats_count, struct appctx *appctx); diff --git a/src/resolvers.c b/src/resolvers.c index 60873b567d..0524c6329f 100644 --- a/src/resolvers.c +++ b/src/resolvers.c @@ -2640,7 +2640,7 @@ static int stats_dump_resolv_to_buffer(struct stconn *sc, if (!stats_dump_one_line(stats, idx, appctx)) return 0; - if (!stats_putchk(rep, NULL, &trash)) + if (!stats_putchk(rep, NULL)) goto full; return 1; diff --git a/src/stats.c b/src/stats.c index 2fdaaefb12..eea5d7c923 100644 --- a/src/stats.c +++ b/src/stats.c @@ -305,8 +305,10 @@ static inline enum stats_domain_px_cap stats_px_get_cap(uint32_t domain) static void stats_dump_json_schema(struct buffer *out); -int stats_putchk(struct channel *chn, struct htx *htx, struct buffer *chk) +int stats_putchk(struct channel *chn, struct htx *htx) { + struct buffer *chk = &trash_chunk; + if (htx) { if (chk->data >= channel_htx_recv_max(chn, htx)) return 0; @@ -3195,7 +3197,7 @@ more: case STAT_PX_ST_TH: if (ctx->flags & STAT_FMT_HTML) { stats_dump_html_px_hdr(sc, px); - if (!stats_putchk(rep, htx, &trash_chunk)) + if (!stats_putchk(rep, htx)) goto full; } @@ -3205,7 +3207,7 @@ more: case STAT_PX_ST_FE: /* print the frontend */ if (stats_dump_fe_stats(sc, px)) { - if (!stats_putchk(rep, htx, &trash_chunk)) + if (!stats_putchk(rep, htx)) goto full; if (ctx->field) goto more; @@ -3242,7 +3244,7 @@ more: /* print the frontend */ if (stats_dump_li_stats(sc, px, l)) { - if (!stats_putchk(rep, htx, &trash_chunk)) + if (!stats_putchk(rep, htx)) goto full; if (ctx->field) goto more; @@ -3307,7 +3309,7 @@ more: } if (stats_dump_sv_stats(sc, px, sv)) { - if (!stats_putchk(rep, htx, &trash_chunk)) + if (!stats_putchk(rep, htx)) goto full; } } /* for sv */ @@ -3318,7 +3320,7 @@ more: case STAT_PX_ST_BE: /* print the backend */ if (stats_dump_be_stats(sc, px)) { - if (!stats_putchk(rep, htx, &trash_chunk)) + if (!stats_putchk(rep, htx)) goto full; if (ctx->field) goto more; @@ -3331,7 +3333,7 @@ more: case STAT_PX_ST_END: if (ctx->flags & STAT_FMT_HTML) { stats_dump_html_px_end(sc, px); - if (!stats_putchk(rep, htx, &trash_chunk)) + if (!stats_putchk(rep, htx)) goto full; } @@ -3886,7 +3888,7 @@ static int stats_dump_stat_to_buffer(struct stconn *sc, struct htx *htx, else if (!(ctx->flags & STAT_FMT_TYPED)) stats_dump_csv_header(ctx->domain); - if (!stats_putchk(rep, htx, &trash_chunk)) + if (!stats_putchk(rep, htx)) goto full; if (ctx->flags & STAT_JSON_SCHM) { @@ -3899,7 +3901,7 @@ static int stats_dump_stat_to_buffer(struct stconn *sc, struct htx *htx, case STAT_STATE_INFO: if (ctx->flags & STAT_FMT_HTML) { stats_dump_html_info(sc, uri); - if (!stats_putchk(rep, htx, &trash_chunk)) + if (!stats_putchk(rep, htx)) goto full; } @@ -3938,7 +3940,7 @@ static int stats_dump_stat_to_buffer(struct stconn *sc, struct htx *htx, stats_dump_html_end(); else stats_dump_json_end(); - if (!stats_putchk(rep, htx, &trash_chunk)) + if (!stats_putchk(rep, htx)) goto full; }