MEDIUM: stats: introduce new actions to simplify admin status management

Instead of enabling/disabling maintenance mode and drain mode separately
using 4 actions, we now offer 3 simplified actions :
  - set state to READY
  - set state to DRAIN
  - set state to MAINT

They have the benefit of reporting the same state as displayed on the page,
and of doing the double-switch atomically eg when switching from drain to
maint.

Note that the old actions are still supported for users running scripts.
This commit is contained in:
Willy Tarreau 2014-05-22 18:04:49 +02:00
parent fae3a7eacd
commit ed7df90068
2 changed files with 46 additions and 18 deletions

View File

@ -307,16 +307,6 @@ enum {
HTTP_ERR_SIZE
};
/* Actions available for the stats admin forms */
enum {
ST_ADM_ACTION_NONE = 0,
ST_ADM_ACTION_DISABLE,
ST_ADM_ACTION_ENABLE,
ST_ADM_ACTION_STOP,
ST_ADM_ACTION_START,
ST_ADM_ACTION_SHUTDOWN,
};
/* status codes available for the stats admin page */
enum {
STAT_STATUS_INIT = 0,

View File

@ -86,6 +86,20 @@ enum {
STAT_CLI_O_POOLS, /* dump memory pools */
};
/* Actions available for the stats admin forms */
enum {
ST_ADM_ACTION_NONE = 0,
ST_ADM_ACTION_READY,
ST_ADM_ACTION_DRAIN,
ST_ADM_ACTION_MAINT,
ST_ADM_ACTION_SHUTDOWN,
/* these are the ancient actions, still available for compatibility */
ST_ADM_ACTION_DISABLE,
ST_ADM_ACTION_ENABLE,
ST_ADM_ACTION_STOP,
ST_ADM_ACTION_START,
};
static int stats_dump_info_to_buffer(struct stream_interface *si);
static int stats_dump_pools_to_buffer(struct stream_interface *si);
static int stats_dump_full_sess_to_buffer(struct stream_interface *si, struct session *sess);
@ -3446,10 +3460,9 @@ static void stats_dump_html_px_end(struct stream_interface *si, struct proxy *px
"Choose the action to perform on the checked servers : "
"<select name=action>"
"<option value=\"\"></option>"
"<option value=\"disable\">Disable</option>"
"<option value=\"enable\">Enable</option>"
"<option value=\"stop\">Soft Stop</option>"
"<option value=\"start\">Soft Start</option>"
"<option value=\"ready\">Set state to READY</option>"
"<option value=\"drain\">Set state to DRAIN</option>"
"<option value=\"maint\">set state to MAINT</option>"
"<option value=\"shutdown\">Kill Sessions</option>"
"</select>"
"<input type=\"hidden\" name=\"b\" value=\"#%d\">"
@ -4206,7 +4219,20 @@ static int stats_process_http_post(struct stream_interface *si)
}
}
else if (!action && (strcmp(key, "action") == 0)) {
if (strcmp(value, "disable") == 0) {
if (strcmp(value, "ready") == 0) {
action = ST_ADM_ACTION_READY;
}
else if (strcmp(value, "drain") == 0) {
action = ST_ADM_ACTION_DRAIN;
}
else if (strcmp(value, "maint") == 0) {
action = ST_ADM_ACTION_MAINT;
}
else if (strcmp(value, "shutdown") == 0) {
action = ST_ADM_ACTION_SHUTDOWN;
}
/* else these are the old supported methods */
else if (strcmp(value, "disable") == 0) {
action = ST_ADM_ACTION_DISABLE;
}
else if (strcmp(value, "enable") == 0) {
@ -4218,9 +4244,6 @@ static int stats_process_http_post(struct stream_interface *si)
else if (strcmp(value, "start") == 0) {
action = ST_ADM_ACTION_START;
}
else if (strcmp(value, "shutdown") == 0) {
action = ST_ADM_ACTION_SHUTDOWN;
}
else {
appctx->ctx.stats.st_code = STAT_STATUS_ERRP;
goto out;
@ -4268,6 +4291,21 @@ static int stats_process_http_post(struct stream_interface *si)
total_servers++;
}
break;
case ST_ADM_ACTION_READY:
srv_adm_set_ready(sv);
altered_servers++;
total_servers++;
break;
case ST_ADM_ACTION_DRAIN:
srv_adm_set_drain(sv);
altered_servers++;
total_servers++;
break;
case ST_ADM_ACTION_MAINT:
srv_adm_set_maint(sv);
altered_servers++;
total_servers++;
break;
case ST_ADM_ACTION_SHUTDOWN:
if (px->state != PR_STSTOPPED) {
struct session *sess, *sess_bck;