]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP: stats/cli: stop using appctx->st2
authorWilly Tarreau <w@1wt.eu>
Tue, 3 May 2022 16:39:27 +0000 (18:39 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 6 May 2022 16:13:35 +0000 (18:13 +0200)
Instead, let's have the state as an enum inside the context. It's much
cleaner and safer as we know nobody else touches it.

include/haproxy/stats-t.h
src/http_ana.c
src/stats.c

index f512419f2a83eccdbf31d84fa11b9cd6091fb2c3..6fbe28b40e43e2debcb2f3b48f448f8d6b7d3436 100644 (file)
@@ -122,7 +122,7 @@ enum {
 
 
 /* data transmission states for the stats responses */
-enum {
+enum stat_state {
        STAT_ST_INIT = 0,
        STAT_ST_HEAD,
        STAT_ST_INFO,
@@ -529,6 +529,7 @@ struct show_stat_ctx {
        unsigned int flags;     /* STAT_* from stats-t.h */
        int iid, type, sid;     /* proxy id, type and service id if bounding of stats is enabled */
        int st_code;            /* the status code returned by an action */
+       enum stat_state state;  /* phase of output production */
 };
 
 extern THREAD_LOCAL void *trash_counters;
index 1968f848c45b799a11fb38445f1b8ef0ba08acea..d2da6282ba703bd31adc3a08aa42ed88a24ff06e 100644 (file)
@@ -3927,7 +3927,8 @@ static int http_handle_stats(struct stream *s, struct channel *req)
        struct htx *htx;
        struct htx_sl *sl;
 
-       appctx->st1 = appctx->st2 = 0;
+       appctx->st1 = 0;
+       ctx->state = STAT_ST_INIT;
        ctx->st_code = STAT_STATUS_INIT;
        ctx->flags |= uri_auth->flags;
        ctx->flags |= STAT_FMT_HTML; /* assume HTML mode by default */
index ea43275be1e29501729e3b23f692e61cef88a690..19c96cdfcaf80bccb130fb0ebbd4287fd150a9b5 100644 (file)
@@ -3732,9 +3732,9 @@ static int stats_dump_stat_to_buffer(struct conn_stream *cs, struct htx *htx,
 
        chunk_reset(&trash);
 
-       switch (appctx->st2) {
+       switch (ctx->state) {
        case STAT_ST_INIT:
-               appctx->st2 = STAT_ST_HEAD; /* let's start producing data */
+               ctx->state = STAT_ST_HEAD; /* let's start producing data */
                /* fall through */
 
        case STAT_ST_HEAD:
@@ -3751,10 +3751,10 @@ static int stats_dump_stat_to_buffer(struct conn_stream *cs, struct htx *htx,
                        goto full;
 
                if (ctx->flags & STAT_JSON_SCHM) {
-                       appctx->st2 = STAT_ST_FIN;
+                       ctx->state = STAT_ST_FIN;
                        return 1;
                }
-               appctx->st2 = STAT_ST_INFO;
+               ctx->state = STAT_ST_INFO;
                /* fall through */
 
        case STAT_ST_INFO:
@@ -3768,7 +3768,7 @@ static int stats_dump_stat_to_buffer(struct conn_stream *cs, struct htx *htx,
                        ctx->obj1 = proxies_list;
 
                ctx->px_st = STAT_PX_ST_INIT;
-               appctx->st2 = STAT_ST_LIST;
+               ctx->state = STAT_ST_LIST;
                /* fall through */
 
        case STAT_ST_LIST:
@@ -3789,7 +3789,7 @@ static int stats_dump_stat_to_buffer(struct conn_stream *cs, struct htx *htx,
                        break;
                }
 
-               appctx->st2 = STAT_ST_END;
+               ctx->state = STAT_ST_END;
                /* fall through */
 
        case STAT_ST_END:
@@ -3802,7 +3802,7 @@ static int stats_dump_stat_to_buffer(struct conn_stream *cs, struct htx *htx,
                                goto full;
                }
 
-               appctx->st2 = STAT_ST_FIN;
+               ctx->state = STAT_ST_FIN;
                /* fall through */
 
        case STAT_ST_FIN:
@@ -3810,7 +3810,7 @@ static int stats_dump_stat_to_buffer(struct conn_stream *cs, struct htx *htx,
 
        default:
                /* unknown state ! */
-               appctx->st2 = STAT_ST_FIN;
+               ctx->state = STAT_ST_FIN;
                return -1;
        }