CLEANUP: stats: rename the stats state values an mark the old ones deprecated

The STAT_ST_* values have been abused by virtually every applet and CLI
keyword handler, and this must not continue as it's a source of bugs and
of overly complicated code.

This patch renames the states to STAT_STATE_*, and keeps the previous
enum while marking each entry as deprecated. This should be sufficient to
catch out-of-tree code that might rely on them and to let them know what
to do with that.
This commit is contained in:
Willy Tarreau 2022-05-06 18:07:53 +02:00
parent 1c0715b12a
commit 6ef1648dc2
3 changed files with 32 additions and 20 deletions

View File

@ -123,12 +123,24 @@ enum {
/* data transmission states for the stats responses */
enum stat_state {
STAT_ST_INIT = 0,
STAT_ST_HEAD,
STAT_ST_INFO,
STAT_ST_LIST,
STAT_ST_END,
STAT_ST_FIN,
STAT_STATE_INIT = 0,
STAT_STATE_HEAD,
STAT_STATE_INFO,
STAT_STATE_LIST,
STAT_STATE_END,
STAT_STATE_FIN,
};
/* kept in 2.6 only for compatibility with legacy code. Will be removed in 2.7,
* please do not use these values anymore and defined your own!
*/
enum obsolete_stat_state {
STAT_ST_INIT __attribute__((deprecated)) = 0,
STAT_ST_HEAD __attribute__((deprecated)),
STAT_ST_INFO __attribute__((deprecated)),
STAT_ST_LIST __attribute__((deprecated)),
STAT_ST_END __attribute__((deprecated)),
STAT_ST_FIN __attribute__((deprecated)),
};
/* data transmission states for the stats responses inside a proxy */

View File

@ -3928,7 +3928,7 @@ static int http_handle_stats(struct stream *s, struct channel *req)
struct htx_sl *sl;
appctx->st1 = 0;
ctx->state = STAT_ST_INIT;
ctx->state = STAT_STATE_INIT;
ctx->st_code = STAT_STATUS_INIT;
ctx->flags |= uri_auth->flags;
ctx->flags |= STAT_FMT_HTML; /* assume HTML mode by default */

View File

@ -3733,11 +3733,11 @@ static int stats_dump_stat_to_buffer(struct conn_stream *cs, struct htx *htx,
chunk_reset(&trash);
switch (ctx->state) {
case STAT_ST_INIT:
ctx->state = STAT_ST_HEAD; /* let's start producing data */
case STAT_STATE_INIT:
ctx->state = STAT_STATE_HEAD; /* let's start producing data */
/* fall through */
case STAT_ST_HEAD:
case STAT_STATE_HEAD:
if (ctx->flags & STAT_FMT_HTML)
stats_dump_html_head(appctx, uri);
else if (ctx->flags & STAT_JSON_SCHM)
@ -3751,13 +3751,13 @@ static int stats_dump_stat_to_buffer(struct conn_stream *cs, struct htx *htx,
goto full;
if (ctx->flags & STAT_JSON_SCHM) {
ctx->state = STAT_ST_FIN;
ctx->state = STAT_STATE_FIN;
return 1;
}
ctx->state = STAT_ST_INFO;
ctx->state = STAT_STATE_INFO;
/* fall through */
case STAT_ST_INFO:
case STAT_STATE_INFO:
if (ctx->flags & STAT_FMT_HTML) {
stats_dump_html_info(cs, uri);
if (!stats_putchk(rep, htx, &trash))
@ -3768,10 +3768,10 @@ 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;
ctx->state = STAT_ST_LIST;
ctx->state = STAT_STATE_LIST;
/* fall through */
case STAT_ST_LIST:
case STAT_STATE_LIST:
switch (domain) {
case STATS_DOMAIN_RESOLVERS:
if (!stats_dump_resolvers(cs, stat_l[domain],
@ -3789,10 +3789,10 @@ static int stats_dump_stat_to_buffer(struct conn_stream *cs, struct htx *htx,
break;
}
ctx->state = STAT_ST_END;
ctx->state = STAT_STATE_END;
/* fall through */
case STAT_ST_END:
case STAT_STATE_END:
if (ctx->flags & (STAT_FMT_HTML|STAT_FMT_JSON)) {
if (ctx->flags & STAT_FMT_HTML)
stats_dump_html_end();
@ -3802,15 +3802,15 @@ static int stats_dump_stat_to_buffer(struct conn_stream *cs, struct htx *htx,
goto full;
}
ctx->state = STAT_ST_FIN;
ctx->state = STAT_STATE_FIN;
/* fall through */
case STAT_ST_FIN:
case STAT_STATE_FIN:
return 1;
default:
/* unknown state ! */
ctx->state = STAT_ST_FIN;
ctx->state = STAT_STATE_FIN;
return -1;
}