]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: stats: Use a dedicated function to check if output is almost full
authorChristopher Faulet <cfaulet@haproxy.com>
Mon, 12 Feb 2024 17:38:11 +0000 (18:38 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Wed, 14 Feb 2024 13:22:36 +0000 (14:22 +0100)
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.

src/stats.c

index d7ad7e2c5b84d7dd6f348bc18906dbdec30c0ad7..0072c2e1655b290f44ee1a7e1ceaf7974b23fd3b 100644 (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 @@ more:
        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 @@ more:
                        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.