]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: stats: make stats_dump_fields_json() directly take flags
authorWilly Tarreau <w@1wt.eu>
Wed, 9 Oct 2019 09:19:29 +0000 (11:19 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 10 Oct 2019 09:30:07 +0000 (11:30 +0200)
It used to take an inverted flag for STAT_STARTED, let's make it take
the raw flags instead.

src/stats.c

index d464bd582203f326a996a257598fcb4ed5bcb525..719711264e66d0ad5d4973a54c6c748e798435cb 100644 (file)
@@ -603,12 +603,12 @@ err:
 /* Dump all fields from <stats> into <out> using a typed "field:desc:type:value" format */
 static int stats_dump_fields_json(struct buffer *out,
                                  const struct field *stats,
-                                 int first_stat)
+                                 unsigned int flags)
 {
        int field;
        int started = 0;
 
-       if (!first_stat && !chunk_strcat(out, ","))
+       if ((flags & STAT_STARTED) && !chunk_strcat(out, ","))
                return 0;
        if (!chunk_strcat(out, "["))
                return 0;
@@ -663,8 +663,8 @@ static int stats_dump_fields_json(struct buffer *out,
 
 err:
        chunk_reset(out);
-       if (!first_stat)
-           chunk_strcat(out, ",");
+       if (flags & STAT_STARTED)
+               chunk_strcat(out, ",");
        chunk_appendf(out, "{\"errorStr\":\"output buffer too short\"}");
        return 0;
 }
@@ -1362,9 +1362,7 @@ int stats_dump_one_line(const struct field *stats, unsigned int flags, struct pr
        else if (appctx->ctx.stats.flags & STAT_FMT_TYPED)
                ret = stats_dump_fields_typed(&trash, stats);
        else if (appctx->ctx.stats.flags & STAT_FMT_JSON)
-               ret = stats_dump_fields_json(&trash, stats,
-                                            !(appctx->ctx.stats.flags &
-                                              STAT_STARTED));
+               ret = stats_dump_fields_json(&trash, stats, appctx->ctx.stats.flags);
        else
                ret = stats_dump_fields_csv(&trash, stats);