MINOR: server: make srv_set_admin_state() capable of telling why this happens

It will be important to help debugging some DNS resolution issues to
know why a server was marked down, so let's make  the function support
a 3rd argument with an indication of the reason. Passing NULL will keep
the message as-is.
This commit is contained in:
Willy Tarreau 2016-11-07 15:53:43 +01:00
parent b96dd28477
commit 8b42848a44
3 changed files with 22 additions and 17 deletions

View File

@ -189,9 +189,10 @@ void srv_set_stopping(struct server *s, const char *reason);
* one flag at once. The equivalent "inherited" flag is propagated to all * one flag at once. The equivalent "inherited" flag is propagated to all
* tracking servers. Maintenance mode disables health checks (but not agent * tracking servers. Maintenance mode disables health checks (but not agent
* checks). When either the flag is already set or no flag is passed, nothing * checks). When either the flag is already set or no flag is passed, nothing
* is done. * is done. If <cause> is non-null, it will be displayed at the end of the log
* lines to justify the state change.
*/ */
void srv_set_admin_flag(struct server *s, enum srv_admin mode); void srv_set_admin_flag(struct server *s, enum srv_admin mode, const char *cause);
/* Disables admin flag <mode> (among SRV_ADMF_*) on server <s>. This is used to /* Disables admin flag <mode> (among SRV_ADMF_*) on server <s>. This is used to
* stop enforcing either maint mode or drain mode. It is not allowed to set more * stop enforcing either maint mode or drain mode. It is not allowed to set more
@ -206,7 +207,7 @@ void srv_clr_admin_flag(struct server *s, enum srv_admin mode);
*/ */
static inline void srv_adm_set_maint(struct server *s) static inline void srv_adm_set_maint(struct server *s)
{ {
srv_set_admin_flag(s, SRV_ADMF_FMAINT); srv_set_admin_flag(s, SRV_ADMF_FMAINT, NULL);
srv_clr_admin_flag(s, SRV_ADMF_FDRAIN); srv_clr_admin_flag(s, SRV_ADMF_FDRAIN);
} }
@ -215,7 +216,7 @@ static inline void srv_adm_set_maint(struct server *s)
*/ */
static inline void srv_adm_set_drain(struct server *s) static inline void srv_adm_set_drain(struct server *s)
{ {
srv_set_admin_flag(s, SRV_ADMF_FDRAIN); srv_set_admin_flag(s, SRV_ADMF_FDRAIN, NULL);
srv_clr_admin_flag(s, SRV_ADMF_FMAINT); srv_clr_admin_flag(s, SRV_ADMF_FMAINT);
} }

View File

@ -5477,7 +5477,7 @@ static int stats_process_http_post(struct stream_interface *si)
if (!(sv->admin & SRV_ADMF_FMAINT)) { if (!(sv->admin & SRV_ADMF_FMAINT)) {
altered_servers++; altered_servers++;
total_servers++; total_servers++;
srv_set_admin_flag(sv, SRV_ADMF_FMAINT); srv_set_admin_flag(sv, SRV_ADMF_FMAINT, "'disable' on stats page");
} }
break; break;
case ST_ADM_ACTION_ENABLE: case ST_ADM_ACTION_ENABLE:
@ -5489,7 +5489,7 @@ static int stats_process_http_post(struct stream_interface *si)
break; break;
case ST_ADM_ACTION_STOP: case ST_ADM_ACTION_STOP:
if (!(sv->admin & SRV_ADMF_FDRAIN)) { if (!(sv->admin & SRV_ADMF_FDRAIN)) {
srv_set_admin_flag(sv, SRV_ADMF_FDRAIN); srv_set_admin_flag(sv, SRV_ADMF_FDRAIN, "'stop' on stats page");
altered_servers++; altered_servers++;
total_servers++; total_servers++;
} }

View File

@ -395,9 +395,10 @@ void srv_set_stopping(struct server *s, const char *reason)
* one flag at once. The equivalent "inherited" flag is propagated to all * one flag at once. The equivalent "inherited" flag is propagated to all
* tracking servers. Maintenance mode disables health checks (but not agent * tracking servers. Maintenance mode disables health checks (but not agent
* checks). When either the flag is already set or no flag is passed, nothing * checks). When either the flag is already set or no flag is passed, nothing
* is done. * is done. If <cause> is non-null, it will be displayed at the end of the log
* lines to justify the state change.
*/ */
void srv_set_admin_flag(struct server *s, enum srv_admin mode) void srv_set_admin_flag(struct server *s, enum srv_admin mode, const char *cause)
{ {
struct check *check = &s->check; struct check *check = &s->check;
struct server *srv; struct server *srv;
@ -426,8 +427,9 @@ void srv_set_admin_flag(struct server *s, enum srv_admin mode)
if (s->state == SRV_ST_STOPPED) { /* server was already down */ if (s->state == SRV_ST_STOPPED) { /* server was already down */
chunk_printf(&trash, chunk_printf(&trash,
"%sServer %s/%s was DOWN and now enters maintenance", "%sServer %s/%s was DOWN and now enters maintenance%s%s%s",
s->flags & SRV_F_BACKUP ? "Backup " : "", s->proxy->id, s->id); s->flags & SRV_F_BACKUP ? "Backup " : "", s->proxy->id, s->id,
cause ? " (" : "", cause ? cause : "", cause ? ")" : "");
srv_append_status(&trash, s, NULL, -1, (mode & SRV_ADMF_FMAINT)); srv_append_status(&trash, s, NULL, -1, (mode & SRV_ADMF_FMAINT));
@ -456,9 +458,10 @@ void srv_set_admin_flag(struct server *s, enum srv_admin mode)
xferred = pendconn_redistribute(s); xferred = pendconn_redistribute(s);
chunk_printf(&trash, chunk_printf(&trash,
"%sServer %s/%s is going DOWN for maintenance", "%sServer %s/%s is going DOWN for maintenance%s%s%s",
s->flags & SRV_F_BACKUP ? "Backup " : "", s->flags & SRV_F_BACKUP ? "Backup " : "",
s->proxy->id, s->id); s->proxy->id, s->id,
cause ? " (" : "", cause ? cause : "", cause ? ")" : "");
srv_append_status(&trash, s, NULL, xferred, (mode & SRV_ADMF_FMAINT)); srv_append_status(&trash, s, NULL, xferred, (mode & SRV_ADMF_FMAINT));
@ -488,8 +491,9 @@ void srv_set_admin_flag(struct server *s, enum srv_admin mode)
*/ */
xferred = pendconn_redistribute(s); xferred = pendconn_redistribute(s);
chunk_printf(&trash, "%sServer %s/%s enters drain state", chunk_printf(&trash, "%sServer %s/%s enters drain state%s%s%s",
s->flags & SRV_F_BACKUP ? "Backup " : "", s->proxy->id, s->id); s->flags & SRV_F_BACKUP ? "Backup " : "", s->proxy->id, s->id,
cause ? " (" : "", cause ? cause : "", cause ? ")" : "");
srv_append_status(&trash, s, NULL, xferred, (mode & SRV_ADMF_FDRAIN)); srv_append_status(&trash, s, NULL, xferred, (mode & SRV_ADMF_FDRAIN));
@ -509,7 +513,7 @@ void srv_set_admin_flag(struct server *s, enum srv_admin mode)
mode = SRV_ADMF_IDRAIN; mode = SRV_ADMF_IDRAIN;
for (srv = s->trackers; srv; srv = srv->tracknext) for (srv = s->trackers; srv; srv = srv->tracknext)
srv_set_admin_flag(srv, mode); srv_set_admin_flag(srv, mode, cause);
} }
/* Disables admin flag <mode> (among SRV_ADMF_*) on server <s>. This is used to /* Disables admin flag <mode> (among SRV_ADMF_*) on server <s>. This is used to
@ -743,10 +747,10 @@ static void srv_propagate_admin_state(struct server *srv)
for (srv2 = srv->trackers; srv2; srv2 = srv2->tracknext) { for (srv2 = srv->trackers; srv2; srv2 = srv2->tracknext) {
if (srv->admin & (SRV_ADMF_MAINT | SRV_ADMF_CMAINT)) if (srv->admin & (SRV_ADMF_MAINT | SRV_ADMF_CMAINT))
srv_set_admin_flag(srv2, SRV_ADMF_IMAINT); srv_set_admin_flag(srv2, SRV_ADMF_IMAINT, NULL);
if (srv->admin & SRV_ADMF_DRAIN) if (srv->admin & SRV_ADMF_DRAIN)
srv_set_admin_flag(srv2, SRV_ADMF_IDRAIN); srv_set_admin_flag(srv2, SRV_ADMF_IDRAIN, NULL);
} }
} }