MINOR: stats: Use a dedicated function to check if output is almost full

This simplifies a bit the stats applet. Because the CLI part was not
refactored yet to use the applet's buffers, there are 3 ways to produce
data:

  * the HTX message for the HTTP stats when zero-copy forwarding is not
    used
  * raw data in the opposite endpoint buffer for the HTTP stats when
    zero-copy forwarding is used
  * the channel buffer when the CLI "show stat" command is evaluated

There is already a dedicated function to take care to copy data at the right
place. There is now also a dedicated function to check us the output buffer
is almost full.
This commit is contained in:
Christopher Faulet 2024-02-12 18:38:11 +01:00
parent 3ee3a7937a
commit 1465eb570b

View File

@ -328,6 +328,33 @@ int stats_putchk(struct appctx *appctx, struct buffer *buf, struct htx *htx)
return 1;
}
int stats_is_full(struct appctx *appctx, struct buffer *buf, struct htx *htx)
{
if (htx) {
if (htx_almost_full(htx)) {
appctx->flags |= APPCTX_FL_OUTBLK_FULL;
goto full;
}
}
else if (buf) {
if (buffer_almost_full(buf)) {
goto full;
}
}
else {
struct channel *rep = sc_ic(appctx_sc(appctx));
if (buffer_almost_full(&rep->buf)) {
sc_need_room(appctx_sc(appctx), b_size(&rep->buf) / 2);
goto full;
}
}
return 0;
full:
return 1;
}
static const char *stats_scope_ptr(struct appctx *appctx)
{
struct show_stat_ctx *ctx = appctx->svcctx;
@ -3234,24 +3261,8 @@ int stats_dump_proxy_to_buffer(struct stconn *sc, struct buffer *buf, struct htx
case STAT_PX_ST_LI:
/* obj2 points to listeners list as initialized above */
for (; ctx->obj2 != &px->conf.listeners; ctx->obj2 = l->by_fe.n) {
if (htx) {
if (htx_almost_full(htx)) {
appctx->flags |= APPCTX_FL_OUTBLK_FULL;
goto full;
}
}
else if (buf) {
if (buffer_almost_full(buf))
goto full;
}
else {
struct channel *rep = sc_ic(appctx_sc(appctx));
if (buffer_almost_full(&rep->buf)) {
sc_need_room(sc, b_size(&rep->buf) / 2);
goto full;
}
}
if (stats_is_full(appctx, buf, htx))
goto full;
l = LIST_ELEM(ctx->obj2, struct listener *, by_fe);
if (!l->counters)
@ -3310,24 +3321,8 @@ int stats_dump_proxy_to_buffer(struct stconn *sc, struct buffer *buf, struct htx
sv = ctx->obj2;
srv_take(sv);
if (htx) {
if (htx_almost_full(htx)) {
appctx->flags |= APPCTX_FL_OUTBLK_FULL;
goto full;
}
}
else if (buf) {
if (buffer_almost_full(buf))
goto full;
}
else {
struct channel *rep = sc_ic(appctx_sc(appctx));
if (buffer_almost_full(&rep->buf)) {
sc_need_room(sc, b_size(&rep->buf) / 2);
goto full;
}
}
if (stats_is_full(appctx, buf, htx))
goto full;
if (ctx->flags & STAT_BOUND) {
if (!(ctx->type & (1 << STATS_TYPE_SV))) {
@ -3885,24 +3880,8 @@ static int stats_dump_proxies(struct stconn *sc, struct buffer *buf,
/* dump proxies */
while (ctx->obj1) {
if (htx) {
if (htx_almost_full(htx)) {
appctx->flags |= APPCTX_FL_OUTBLK_FULL;
goto full;
}
}
else if (buf) {
if (buffer_almost_full(buf))
goto full;
}
else {
struct channel *rep = sc_ic(appctx_sc(appctx));
if (buffer_almost_full(&rep->buf)) {
sc_need_room(sc, b_size(&rep->buf) / 2);
goto full;
}
}
if (stats_is_full(appctx, buf, htx))
goto full;
px = ctx->obj1;
/* Skip the global frontend proxies and non-networked ones.