]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MEDIUM: stats: fix resolvers dump
authorAurelien DARRAGON <adarragon@haproxy.com>
Thu, 2 Feb 2023 16:27:27 +0000 (17:27 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Mon, 6 Feb 2023 06:53:03 +0000 (07:53 +0100)
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")

include/haproxy/stats.h
src/resolvers.c
src/stats.c

index a8ffbc70478b505f0a3c04ab9d8b744a84530221..90a4f51ef8008843041d4863ba0a0cf40db3d80a 100644 (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);
 
index 60873b567d46d7fdfb58f73470e6e8fc13f6b52b..0524c6329fe94dc362929ac059bec0e75f0453e4 100644 (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;
index 2fdaaefb125e1634e0b775124051aff46222b000..eea5d7c9232b2a0e99f7555dcee0563a5af23946 100644 (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;
                }