Add a DRAIN sub-state for a server which
will be shown on the stats page instead of UP if
an agent check is in use and the agent has most recently returned "drain".

Signed-off-by: Simon Horman <ho...@verge.net.au>
---
 include/types/server.h |  3 ++-
 src/checks.c           |  7 +++++++
 src/dumpstats.c        | 12 +++++++++---
 3 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/include/types/server.h b/include/types/server.h
index 9f7a23c..dd17d61 100644
--- a/include/types/server.h
+++ b/include/types/server.h
@@ -52,7 +52,8 @@
 #define SRV_GOINGDOWN  0x0020  /* this server says that it's going down (404) 
*/
 #define SRV_WARMINGUP  0x0040  /* this server is warming up after a failure */
 #define SRV_MAINTAIN   0x0080  /* this server is in maintenance mode */
-/* unused: 0x0100, 0x0200, 0x0400 */
+#define SRV_DRAIN      0x0100  /* this server has been requested to drain its 
connections */
+/* unused: 0x0200, 0x0400 */
 #define SRV_SEND_PROXY 0x0800  /* this server talks the PROXY protocol */
 #define SRV_NON_STICK  0x1000  /* never add connections allocated to this 
server to a stick table */
 
diff --git a/src/checks.c b/src/checks.c
index 5d893f8..a9a93ae 100644
--- a/src/checks.c
+++ b/src/checks.c
@@ -829,6 +829,7 @@ static void agent_expect(struct check *check, char *data)
        short status = HCHK_STATUS_L7RSP;
        const char *desc = "Unknown feedback string";
        const char *down_cmd = NULL;
+       int drain = 0;
 
        cut_crlf(data);
 
@@ -843,6 +844,7 @@ static void agent_expect(struct check *check, char *data)
                if (!desc) {
                        desc = "drain";
                        status = HCHK_STATUS_L7OKD;
+                       drain = 1;
                }
        } else if (!strncasecmp(data, "down", strlen("down"))) {
                down_cmd = "down";
@@ -852,6 +854,11 @@ static void agent_expect(struct check *check, char *data)
                down_cmd = "fail";
        }
 
+       if (drain)
+               check->server->state |= SRV_DRAIN;
+       else
+               check->server->state &= ~SRV_DRAIN;
+
        if (down_cmd) {
                const char *end = data + strlen(down_cmd);
                /*
diff --git a/src/dumpstats.c b/src/dumpstats.c
index a7dce57..d9795fa 100644
--- a/src/dumpstats.c
+++ b/src/dumpstats.c
@@ -2112,13 +2112,15 @@ static int stats_dump_sv_stats(struct stream_interface 
*si, struct proxy *px, in
        int i;
 
        if (si->applet.ctx.stats.flags & STAT_FMT_HTML) {
-               static char *srv_hlt_st[7] = {
+               static char *srv_hlt_st[9] = {
                        "DOWN",
                        "DN %d/%d &uarr;",
                        "UP %d/%d &darr;",
                        "UP",
                        "NOLB %d/%d &darr;",
                        "NOLB",
+                       "DRAIN %d/%d &darr;",
+                       "DRAIN",
                        "<i>no check</i>"
                };
 
@@ -2336,13 +2338,15 @@ static int stats_dump_sv_stats(struct stream_interface 
*si, struct proxy *px, in
                        chunk_appendf(&trash, "<td class=ac>-</td></tr>\n");
        }
        else { /* CSV mode */
-               static char *srv_hlt_st[7] = {
+               static char *srv_hlt_st[9] = {
                        "DOWN,",
                        "DOWN %d/%d,",
                        "UP %d/%d,",
                        "UP,",
                        "NOLB %d/%d,",
                        "NOLB,",
+                       "DRAIN %d/%d,",
+                       "DRAIN,",
                        "no check,"
                };
 
@@ -2948,7 +2952,7 @@ static int stats_dump_proxy_to_buffer(struct 
stream_interface *si, struct proxy
 
                        /* FIXME: produce some small strings for "UP/DOWN x/y 
&#xxxx;" */
                        if (!(svs->state & SRV_CHECKED))
-                               sv_state = 6;
+                               sv_state = 8;
                        else if (svs->state & SRV_RUNNING) {
                                if (svs->check.health == svs->rise + svs->fall 
- 1)
                                        sv_state = 3; /* UP */
@@ -2957,6 +2961,8 @@ static int stats_dump_proxy_to_buffer(struct 
stream_interface *si, struct proxy
 
                                if (svs->state & SRV_GOINGDOWN)
                                        sv_state += 2;
+                               else if (svs->state & SRV_DRAIN)
+                                       sv_state += 4;
                        }
                        else
                                if (svs->check.health)
-- 
1.8.3.2


Reply via email to