]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: stats: replace the ST_* uri_auth flags with STAT_*
authorWilly Tarreau <w@1wt.eu>
Wed, 9 Oct 2019 08:19:16 +0000 (10:19 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 10 Oct 2019 09:30:07 +0000 (11:30 +0200)
We used to rely on some config flags defined in uri_auth.h set during
parsing, and another set of STAT_* flags defined in stats.h set at run
time, with a somewhat gray area between the two sets. This is confusing
in the stats code as both are called "flags" in various functions and
it's quite hard to know which one describes what.

This patch cleans this up by replacing all ST_* by a newly assigned
value from the STAT_* set so that we can now use unified flags to
describe both the configuration and the current state. There is no
functional change at all.

include/common/uri_auth.h
include/types/stats.h
src/cfgparse-listen.c
src/hlua_fcn.c
src/stats.c
src/uri_auth.c

index 46f1bc653d88e0cf86d4e0615d7ccc81916a9bb0..8223dc1030d3b40bc8d2e19ec6bc071e56829a3a 100644 (file)
@@ -26,13 +26,6 @@ struct stat_scope {
        char *px_id;                    /* proxy id */
 };
 
-#define        ST_HIDEVER      0x00000001      /* do not report the version and reldate */
-#define        ST_SHNODE       0x00000002      /* show node name */
-#define        ST_SHDESC       0x00000004      /* show description */
-#define        ST_SHLGNDS      0x00000008      /* show legends */
-/* unused:              0x00000010 */
-#define        ST_SHOWADMIN    0x00000020      /* show the admin column */
-
 /* later we may link them to support multiple URI matching */
 struct uri_auth {
        int uri_len;                    /* the prefix length */
@@ -40,7 +33,7 @@ struct uri_auth {
        char *auth_realm;               /* the realm reported to the client */
        char *node, *desc;              /* node name & description reported in this stats */
        int refresh;                    /* refresh interval for the browser (in seconds) */
-       int flags;                      /* some flags describing the statistics page */
+       unsigned int flags;             /* STAT_* flags from stats.h and for applet.ctx.stats.flags */
        struct stat_scope *scope;       /* linked list of authorized proxies */
        struct userlist *userlist;      /* private userlist to emulate legacy "stats auth user:password" */
        struct list http_req_rules;     /* stats http-request rules : allow/deny/auth */
index b3a69c61d6346f40bee3bff0cb6678a44ca17ab3..ee16ac7509727ec581a1feb86aa6ac70ac165aaf 100644 (file)
 #define STAT_ADMIN      0x00000020     /* indicate a stats admin level */
 #define STAT_CHUNKED    0x00000040      /* use chunked encoding (HTTP/1.1) */
 #define STAT_JSON_SCHM  0x00000080      /* dump the json schema */
+
+#define STAT_HIDEVER    0x00000100      /* conf: do not report the version and reldate */
+#define STAT_SHNODE     0x00000200      /* conf: show node name */
+#define STAT_SHDESC     0x00000400      /* conf: show description */
+#define STAT_SHLGNDS    0x00000800      /* conf: show legends */
+#define STAT_SHOWADMIN  0x00001000      /* conf: show the admin column */
+
 #define STAT_BOUND      0x00800000     /* bound statistics to selected proxies/types/services */
 #define STAT_STARTED    0x01000000     /* some output has occurred */
 
index a5d46f593c8ca1fdfb62e446203bfeac7754cbc5..6bece743d645e628c8224ed6f5e3e2e7682e7367 100644 (file)
@@ -16,6 +16,7 @@
 
 #include <types/capture.h>
 #include <types/compression.h>
+#include <types/stats.h>
 
 #include <proto/acl.h>
 #include <proto/checks.h>
@@ -1874,13 +1875,13 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
                                goto out;
                        }
                } else if (!strcmp(args[1], "hide-version")) {
-                       if (!stats_set_flag(&curproxy->uri_auth, ST_HIDEVER)) {
+                       if (!stats_set_flag(&curproxy->uri_auth, STAT_HIDEVER)) {
                                ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
                                err_code |= ERR_ALERT | ERR_ABORT;
                                goto out;
                        }
                } else if (!strcmp(args[1], "show-legends")) {
-                       if (!stats_set_flag(&curproxy->uri_auth, ST_SHLGNDS)) {
+                       if (!stats_set_flag(&curproxy->uri_auth, STAT_SHLGNDS)) {
                                ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
                                err_code |= ERR_ALERT | ERR_ABORT;
                                goto out;
index 3b71ce1bd10ce12671d12a31fc4777f7fa08a9e9..28261fdcdde8fee28eaf0ac0106eb78b6f5e239c 100644 (file)
@@ -858,7 +858,7 @@ int hlua_listener_get_stats(lua_State *L)
                return 1;
        }
 
-       stats_fill_li_stats(li->bind_conf->frontend, li, ST_SHLGNDS, stats, STATS_LEN);
+       stats_fill_li_stats(li->bind_conf->frontend, li, STAT_SHLGNDS, stats, STATS_LEN);
 
        lua_newtable(L);
        for (i=0; i<ST_F_TOTAL_FIELDS; i++) {
@@ -914,7 +914,7 @@ int hlua_server_get_stats(lua_State *L)
                return 1;
        }
 
-       stats_fill_sv_stats(srv->proxy, srv, ST_SHLGNDS, stats, STATS_LEN);
+       stats_fill_sv_stats(srv->proxy, srv, STAT_SHLGNDS, stats, STATS_LEN);
 
        lua_newtable(L);
        for (i=0; i<ST_F_TOTAL_FIELDS; i++) {
@@ -1328,7 +1328,7 @@ int hlua_proxy_get_stats(lua_State *L)
 
        px = hlua_check_proxy(L, 1);
        if (px->cap & PR_CAP_BE)
-               stats_fill_be_stats(px, ST_SHLGNDS, stats, STATS_LEN);
+               stats_fill_be_stats(px, STAT_SHLGNDS, stats, STATS_LEN);
        else
                stats_fill_fe_stats(px, stats, STATS_LEN);
        lua_newtable(L);
index 64de70d18e9bf2b8eab7bbe129af04be523dace1..14e5e7c3075184c254db369528079825cf9e120e 100644 (file)
@@ -670,8 +670,8 @@ err:
 }
 
 /* Dump all fields from <stats> into <out> using the HTML format. A column is
- * reserved for the checkbox is ST_SHOWADMIN is set in <flags>. Some extra info
- * are provided if ST_SHLGNDS is present in <flags>.
+ * reserved for the checkbox is STAT_SHOWADMIN is set in <flags>. Some extra info
+ * are provided if STAT_SHLGNDS is present in <flags>.
  */
 static int stats_dump_fields_html(struct buffer *out,
                                  const struct field *stats,
@@ -684,7 +684,7 @@ static int stats_dump_fields_html(struct buffer *out,
                              /* name, queue */
                              "<tr class=\"frontend\">");
 
-               if (flags & ST_SHOWADMIN) {
+               if (flags & STAT_SHOWADMIN) {
                        /* Column sub-heading for Enable or Disable server */
                        chunk_appendf(out, "<td></td>");
                }
@@ -827,7 +827,7 @@ static int stats_dump_fields_html(struct buffer *out,
        }
        else if (stats[ST_F_TYPE].u.u32 == STATS_TYPE_SO) {
                chunk_appendf(out, "<tr class=socket>");
-               if (flags & ST_SHOWADMIN) {
+               if (flags & STAT_SHOWADMIN) {
                        /* Column sub-heading for Enable or Disable server */
                        chunk_appendf(out, "<td></td>");
                }
@@ -838,10 +838,10 @@ static int stats_dump_fields_html(struct buffer *out,
                              "<a class=lfsb href=\"#%s/+%s\">%s</a>"
                              "",
                              field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_SVNAME),
-                             (flags & ST_SHLGNDS)?"<u>":"",
+                             (flags & STAT_SHLGNDS)?"<u>":"",
                              field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_SVNAME), field_str(stats, ST_F_SVNAME));
 
-               if (flags & ST_SHLGNDS) {
+               if (flags & STAT_SHLGNDS) {
                        chunk_appendf(out, "<div class=tips>");
 
                        if (isdigit(*field_str(stats, ST_F_ADDR)))
@@ -866,7 +866,7 @@ static int stats_dump_fields_html(struct buffer *out,
                              /* bytes: in, out */
                              "<td>%s</td><td>%s</td>"
                              "",
-                             (flags & ST_SHLGNDS)?"</u>":"",
+                             (flags & STAT_SHLGNDS)?"</u>":"",
                              U2H(stats[ST_F_SCUR].u.u32), U2H(stats[ST_F_SMAX].u.u32), U2H(stats[ST_F_SLIM].u.u32),
                              U2H(stats[ST_F_STOT].u.u64), U2H(stats[ST_F_BIN].u.u64), U2H(stats[ST_F_BOUT].u.u64));
 
@@ -932,7 +932,7 @@ static int stats_dump_fields_html(struct buffer *out,
                                      (stats[ST_F_BCK].u.u32) ? "backup" : "active", style);
 
 
-               if (flags & ST_SHOWADMIN)
+               if (flags & STAT_SHOWADMIN)
                        chunk_appendf(out,
                                      "<td><input class='%s-checkbox' type=\"checkbox\" name=\"s\" value=\"%s\"></td>",
                                      field_str(stats, ST_F_PXNAME),
@@ -943,10 +943,10 @@ static int stats_dump_fields_html(struct buffer *out,
                              "<a class=lfsb href=\"#%s/%s\">%s</a>"
                              "",
                              field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_SVNAME),
-                             (flags & ST_SHLGNDS) ? "<u>" : "",
+                             (flags & STAT_SHLGNDS) ? "<u>" : "",
                              field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_SVNAME), field_str(stats, ST_F_SVNAME));
 
-               if (flags & ST_SHLGNDS) {
+               if (flags & STAT_SHLGNDS) {
                        chunk_appendf(out, "<div class=tips>");
 
                        if (isdigit(*field_str(stats, ST_F_ADDR)))
@@ -976,7 +976,7 @@ static int stats_dump_fields_html(struct buffer *out,
                              /* sessions rate : current, max, limit */
                              "<td>%s</td><td>%s</td><td></td>"
                              "",
-                             (flags & ST_SHLGNDS) ? "</u>" : "",
+                             (flags & STAT_SHLGNDS) ? "</u>" : "",
                              U2H(stats[ST_F_QCUR].u.u32), U2H(stats[ST_F_QMAX].u.u32), LIM2A(stats[ST_F_QLIMIT].u.u32, "-"),
                              U2H(stats[ST_F_RATE].u.u32), U2H(stats[ST_F_RATE_MAX].u.u32));
 
@@ -1188,7 +1188,7 @@ static int stats_dump_fields_html(struct buffer *out,
        }
        else if (stats[ST_F_TYPE].u.u32 == STATS_TYPE_BE) {
                chunk_appendf(out, "<tr class=\"backend\">");
-               if (flags & ST_SHOWADMIN) {
+               if (flags & STAT_SHOWADMIN) {
                        /* Column sub-heading for Enable or Disable server */
                        chunk_appendf(out, "<td></td>");
                }
@@ -1198,10 +1198,10 @@ static int stats_dump_fields_html(struct buffer *out,
                              "%s<a name=\"%s/Backend\"></a>"
                              "<a class=lfsb href=\"#%s/Backend\">Backend</a>"
                              "",
-                             (flags & ST_SHLGNDS)?"<u>":"",
+                             (flags & STAT_SHLGNDS)?"<u>":"",
                              field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_PXNAME));
 
-               if (flags & ST_SHLGNDS) {
+               if (flags & STAT_SHLGNDS) {
                        /* balancing */
                        chunk_appendf(out, "<div class=tips>balancing: %s",
                                      field_str(stats, ST_F_ALGO));
@@ -1223,7 +1223,7 @@ static int stats_dump_fields_html(struct buffer *out,
                              /* sessions rate : current, max, limit */
                              "<td>%s</td><td>%s</td><td></td>"
                              "",
-                             (flags & ST_SHLGNDS)?"</u>":"",
+                             (flags & STAT_SHLGNDS)?"</u>":"",
                              U2H(stats[ST_F_QCUR].u.u32), U2H(stats[ST_F_QMAX].u.u32),
                              U2H(stats[ST_F_RATE].u.u32), U2H(stats[ST_F_RATE_MAX].u.u32));
 
@@ -1357,7 +1357,7 @@ int stats_dump_one_line(const struct field *stats, unsigned int flags, struct pr
        int ret;
 
        if ((px->cap & PR_CAP_BE) && px->srv && (appctx->ctx.stats.flags & STAT_ADMIN))
-               flags |= ST_SHOWADMIN;
+               flags |= STAT_SHOWADMIN;
 
        if (appctx->ctx.stats.flags & STAT_FMT_HTML)
                ret = stats_dump_fields_html(&trash, stats, flags);
@@ -1468,7 +1468,7 @@ static int stats_dump_fe_stats(struct stream_interface *si, struct proxy *px)
  * preallocated array of length <len>. The length of the array
  * must be at least ST_F_TOTAL_FIELDS. If this length is less
  * then this value, the function returns 0, otherwise, it
- * returns 1. <flags> can take the value ST_SHLGNDS.
+ * returns 1. <flags> can take the value STAT_SHLGNDS.
  */
 int stats_fill_li_stats(struct proxy *px, struct listener *l, int flags,
                         struct field *stats, int len)
@@ -1505,7 +1505,7 @@ int stats_fill_li_stats(struct proxy *px, struct listener *l, int flags,
        stats[ST_F_TYPE]     = mkf_u32(FO_CONFIG|FS_SERVICE, STATS_TYPE_SO);
        stats[ST_F_WREW]     = mkf_u64(FN_COUNTER, l->counters->failed_rewrites);
 
-       if (flags & ST_SHLGNDS) {
+       if (flags & STAT_SHLGNDS) {
                char str[INET6_ADDRSTRLEN];
                int port;
 
@@ -1583,7 +1583,7 @@ static const char *srv_hlt_st[SRV_STATS_STATE_COUNT] = {
  * preallocated array of length <len>. The length of the array
  * must be at least ST_F_TOTAL_FIELDS. If this length is less
  * then this value, the function returns 0, otherwise, it
- * returns 1. <flags> can take the value ST_SHLGNDS.
+ * returns 1. <flags> can take the value STAT_SHLGNDS.
  */
 int stats_fill_sv_stats(struct proxy *px, struct server *sv, int flags,
                         struct field *stats, int len)
@@ -1795,7 +1795,7 @@ int stats_fill_sv_stats(struct proxy *px, struct server *sv, int flags,
        stats[ST_F_RTIME] = mkf_u32(FN_AVG, swrate_avg(sv->counters.d_time, TIME_STATS_SAMPLES));
        stats[ST_F_TTIME] = mkf_u32(FN_AVG, swrate_avg(sv->counters.t_time, TIME_STATS_SAMPLES));
 
-       if (flags & ST_SHLGNDS) {
+       if (flags & STAT_SHLGNDS) {
                switch (addr_to_str(&sv->addr, str, sizeof(str))) {
                case AF_INET:
                        stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out));
@@ -1842,7 +1842,7 @@ static int stats_dump_sv_stats(struct stream_interface *si, struct proxy *px, in
  * preallocated array of length <len>. The length of the array
  * must be at least ST_F_TOTAL_FIELDS. If this length is less
  * then this value, the function returns 0, otherwise, it
- * returns 1. <flags> can take the value ST_SHLGNDS.
+ * returns 1. <flags> can take the value STAT_SHLGNDS.
  */
 int stats_fill_be_stats(struct proxy *px, int flags, struct field *stats, int len)
 {
@@ -1888,7 +1888,7 @@ int stats_fill_be_stats(struct proxy *px, int flags, struct field *stats, int le
        stats[ST_F_RATE]     = mkf_u32(0, read_freq_ctr(&px->be_sess_per_sec));
        stats[ST_F_RATE_MAX] = mkf_u32(0, px->be_counters.sps_max);
 
-       if (flags & ST_SHLGNDS) {
+       if (flags & STAT_SHLGNDS) {
                if (px->cookie_name)
                        stats[ST_F_COOKIE] = mkf_str(FO_CONFIG|FN_NAME|FS_SERVICE, px->cookie_name);
                stats[ST_F_ALGO] = mkf_str(FO_CONFIG|FS_SERVICE, backend_lb_algo_str(px->lbprm.algo & BE_LB_ALGO));
@@ -1981,10 +1981,10 @@ static void stats_dump_html_px_hdr(struct stream_interface *si, struct proxy *px
                      "<a name=\"%s\"></a>%s"
                      "<a class=px href=\"#%s\">%s</a>",
                      px->id,
-                     (uri->flags & ST_SHLGNDS) ? "<u>":"",
+                     (uri->flags & STAT_SHLGNDS) ? "<u>":"",
                      px->id, px->id);
 
-       if (uri->flags & ST_SHLGNDS) {
+       if (uri->flags & STAT_SHLGNDS) {
                /* cap, mode, id */
                chunk_appendf(&trash, "<div class=tips>cap: %s, mode: %s, id: %d",
                              proxy_cap_str(px->cap), proxy_mode_str(px->mode),
@@ -1999,7 +1999,7 @@ static void stats_dump_html_px_hdr(struct stream_interface *si, struct proxy *px
                      "</table>\n"
                      "<table class=\"tbl\" width=\"100%%\">\n"
                      "<tr class=\"titre\">",
-                     (uri->flags & ST_SHLGNDS) ? "</u>":"",
+                     (uri->flags & STAT_SHLGNDS) ? "</u>":"",
                      px->desc ? "desc" : "empty", px->desc ? px->desc : "");
 
        if ((px->cap & PR_CAP_BE) && px->srv && (appctx->ctx.stats.flags & STAT_ADMIN)) {
@@ -2089,9 +2089,9 @@ int stats_dump_proxy_to_buffer(struct stream_interface *si, struct htx *htx,
        if (uri)
                flags = uri->flags;
        else if ((strm_li(s)->bind_conf->level & ACCESS_LVL_MASK) >= ACCESS_LVL_OPER)
-               flags = ST_SHLGNDS | ST_SHNODE | ST_SHDESC;
+               flags = STAT_SHLGNDS | STAT_SHNODE | STAT_SHDESC;
        else
-               flags = ST_SHNODE | ST_SHDESC;
+               flags = STAT_SHNODE | STAT_SHDESC;
 
        chunk_reset(&trash);
 
@@ -2386,8 +2386,8 @@ static void stats_dump_html_head(struct uri_auth *uri)
                      "u:hover div.tips {visibility:visible;}\n"
                      "-->\n"
                      "</style></head>\n",
-                     (uri->flags & ST_SHNODE) ? " on " : "",
-                     (uri->flags & ST_SHNODE) ? (uri->node ? uri->node : global.node) : ""
+                     (uri->flags & STAT_SHNODE) ? " on " : "",
+                     (uri->flags & STAT_SHNODE) ? (uri->node ? uri->node : global.node) : ""
                      );
 }
 
@@ -2454,11 +2454,11 @@ static void stats_dump_html_info(struct stream_interface *si, struct uri_auth *u
                      "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">"
                      "<b>Display option:</b><ul style=\"margin-top: 0.25em;\">"
                      "",
-                     (uri->flags & ST_HIDEVER) ? "" : (stats_version_string),
-                     pid, (uri->flags & ST_SHNODE) ? " on " : "",
-                     (uri->flags & ST_SHNODE) ? (uri->node ? uri->node : global.node) : "",
-                     (uri->flags & ST_SHDESC) ? ": " : "",
-                     (uri->flags & ST_SHDESC) ? (uri->desc ? uri->desc : global.desc) : "",
+                     (uri->flags & STAT_HIDEVER) ? "" : (stats_version_string),
+                     pid, (uri->flags & STAT_SHNODE) ? " on " : "",
+                     (uri->flags & STAT_SHNODE) ? (uri->node ? uri->node : global.node) : "",
+                     (uri->flags & STAT_SHDESC) ? ": " : "",
+                     (uri->flags & STAT_SHDESC) ? (uri->desc ? uri->desc : global.desc) : "",
                      pid, relative_pid, global.nbproc, global.nbthread,
                      up / 86400, (up % 86400) / 3600,
                      (up % 3600) / 60, (up % 60),
index dcfa5e0a711e8fd23473675a9465b5881ea40358..352737a31fcccbcffb9719f7750a39d91fa6e0b9 100644 (file)
@@ -17,6 +17,7 @@
 #include <common/config.h>
 #include <common/uri_auth.h>
 
+#include <types/stats.h>
 #include <proto/log.h>
 
 /*
@@ -108,7 +109,7 @@ struct uri_auth *stats_set_realm(struct uri_auth **root, char *realm)
 }
 
 /*
- * Returns a default uri_auth with ST_SHNODE flag enabled and
+ * Returns a default uri_auth with STAT_SHNODE flag enabled and
  * <node> set as the name if it is not empty.
  * Uses the pointer provided if not NULL and not initialized.
  */
@@ -126,7 +127,7 @@ struct uri_auth *stats_set_node(struct uri_auth **root, char *name)
        if ((u = stats_check_init_uri_auth(root)) == NULL)
                goto out_u;
 
-       if (!stats_set_flag(root, ST_SHNODE))
+       if (!stats_set_flag(root, STAT_SHNODE))
                goto out_u;
 
        if (node_copy) {        
@@ -143,7 +144,7 @@ struct uri_auth *stats_set_node(struct uri_auth **root, char *name)
 }
 
 /*
- * Returns a default uri_auth with ST_SHDESC flag enabled and
+ * Returns a default uri_auth with STAT_SHDESC flag enabled and
  * <description> set as the desc if it is not empty.
  * Uses the pointer provided if not NULL and not initialized.
  */
@@ -161,7 +162,7 @@ struct uri_auth *stats_set_desc(struct uri_auth **root, char *desc)
        if ((u = stats_check_init_uri_auth(root)) == NULL)
                goto out_u;
 
-       if (!stats_set_flag(root, ST_SHDESC))
+       if (!stats_set_flag(root, STAT_SHDESC))
                goto out_u;
 
        if (desc_copy) {