]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: server: implement agent check for dynamic servers
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Wed, 4 Aug 2021 09:33:14 +0000 (11:33 +0200)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Fri, 6 Aug 2021 09:09:48 +0000 (11:09 +0200)
This commit is the counterpart for agent check of
"MEDIUM: server: implement check for dynamic servers".

The "agent-check" keyword is enabled for dynamic servers. The agent
check must manually be activated via "enable agent" CLI. This can
enable the dynamic server if the agent response is "ready" without an
explicit "enable server" CLI.

doc/management.txt
src/check.c
src/server.c

index eaa6e31cd3c8fb3e251a3fb24212bb9352cd0f34..dbc32293d84a337fe90885d03aa8b10a19c41853 100644 (file)
@@ -1477,10 +1477,21 @@ add server <backend>/<server> [args]*
 
   Use the "check" keyword to enable health-check support. Note that the
   health-check is disabled by default and must be enabled independently from
-  the server using the "enable health" command.
+  the server using the "enable health" command. For agent checks, use the
+  "agent-check" keyword and the "enable agent" command. Note that in this case
+  the server may be activated via the agent depending on the status reported,
+  without an explicit "enable server" command. This also means that extra care
+  is required when removing a dynamic server with agent check. The agent should
+  be first deactivated via "disable agent" to be able to put the server in the
+  required maintenance mode before removal.
 
   Here is the list of the currently supported keywords :
 
+  - agent-addr
+  - agent-check
+  - agent-inter
+  - agent-port
+  - agent-send
   - allow-0rtt
   - alpn
   - addr
index 637b6c905c70c7a4a16774f768638a8212054228..b49aca61a5843d8ddd4c46ea152e3309a3a18d3e 100644 (file)
@@ -2382,7 +2382,7 @@ static int srv_parse_check_port(char **args, int *cur_arg, struct proxy *curpx,
 static struct srv_kw_list srv_kws = { "CHK", { }, {
        { "addr",                srv_parse_addr,                1,  1,  1 }, /* IP address to send health to or to probe from agent-check */
        { "agent-addr",          srv_parse_agent_addr,          1,  1,  1 }, /* Enable an auxiliary agent check */
-       { "agent-check",         srv_parse_agent_check,         0,  1,  0 }, /* Enable agent checks */
+       { "agent-check",         srv_parse_agent_check,         0,  1,  1 }, /* Enable agent checks */
        { "agent-inter",         srv_parse_agent_inter,         1,  1,  1 }, /* Set the interval between two agent checks */
        { "agent-port",          srv_parse_agent_port,          1,  1,  1 }, /* Set the TCP port used for agent checks. */
        { "agent-send",          srv_parse_agent_send,          1,  1,  1 }, /* Set string to send to agent. */
index 749d44e5bedb1d733b94d9c707657750875b4a7e..b762ce9412ebdf50ccfa0640e79cb43fb8af9271 100644 (file)
@@ -4564,9 +4564,9 @@ static int cli_parse_add_server(char **args, char *payload, struct appctx *appct
                        goto out;
        }
 
-       /* Init check if configured. The check is manually disabled because a
-        * dynamic server is started in a disable state. It must be manually
-        * activated via a "enable health" command.
+       /* Init check/agent if configured. The check is manually disabled
+        * because a dynamic server is started in a disable state. It must be
+        * manually activated via a "enable health/agent" command.
         */
        if (srv->do_check) {
                if (init_srv_check(srv))
@@ -4575,6 +4575,13 @@ static int cli_parse_add_server(char **args, char *payload, struct appctx *appct
                srv->check.state &= ~CHK_ST_ENABLED;
                srv_use_dynsrv(srv);
        }
+       else if (srv->do_agent) {
+               if (init_srv_agent_check(srv))
+                       goto out;
+
+               srv->agent.state &= ~CHK_ST_ENABLED;
+               srv_use_dynsrv(srv);
+       }
 
        /* Attach the server to the end of the proxy linked list. Note that this
         * operation is not thread-safe so this is executed under thread
@@ -4636,6 +4643,10 @@ static int cli_parse_add_server(char **args, char *payload, struct appctx *appct
                if (!start_check_task(&srv->check, 0, 1, 1))
                        ha_alert("System might be unstable, consider to execute a reload");
        }
+       else if (srv->agent.state & CHK_ST_CONFIGURED) {
+               if (!start_check_task(&srv->agent, 0, 1, 1))
+                       ha_alert("System might be unstable, consider to execute a reload");
+       }
 
        ha_notice("New server registered.\n");
        cli_msg(appctx, LOG_INFO, usermsgs_str());
@@ -4649,6 +4660,8 @@ out:
 
                if (srv->check.state & CHK_ST_CONFIGURED)
                        free_check(&srv->check);
+               else if (srv->agent.state & CHK_ST_CONFIGURED)
+                       free_check(&srv->agent);
 
                /* remove the server from the proxy linked list */
                if (be->srv == srv) {
@@ -4756,6 +4769,8 @@ static int cli_parse_delete_server(char **args, char *payload, struct appctx *ap
        /* stop the check task if running */
        if (srv->check.state & CHK_ST_CONFIGURED)
                check_purge(&srv->check);
+       else if (srv->agent.state & CHK_ST_CONFIGURED)
+               check_purge(&srv->agent);
 
        /* detach the server from the proxy linked list
         * The proxy servers list is currently not protected by a lock, so this