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")
This commit is contained in:
Aurelien DARRAGON 2023-02-02 17:27:27 +01:00 committed by Christopher Faulet
parent 14656844cc
commit e5958d0292
3 changed files with 14 additions and 12 deletions

View File

@ -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);

View File

@ -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;

View File

@ -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;
}