]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: server: implement check for dynamic servers
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Thu, 22 Jul 2021 14:04:59 +0000 (16:04 +0200)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Fri, 6 Aug 2021 09:09:48 +0000 (11:09 +0200)
Implement check support for dynamic servers. The "check" keyword is now
enabled for dynamic servers. If used, the server check is initialized
and the check task started in the "add server" CLI handler. The check is
explicitely disabled and must be manually activated via "enable health"
CLI handler.

The dynamic server refcount is incremented if a check is configured. On
"delete server" handler, the check is purged, which decrements the
refcount.

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

index 4b01ddcb42346f5885cda2c3ecf9cdb44dba9db6..eaa6e31cd3c8fb3e251a3fb24212bb9352cd0f34 100644 (file)
@@ -1475,20 +1475,33 @@ add server <backend>/<server> [args]*
   another dynamic server. This is to ensure that the tracking chain is kept
   consistent even in the case of dynamic servers deletion.
 
+  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.
+
   Here is the list of the currently supported keywords :
 
   - allow-0rtt
   - alpn
+  - addr
   - backup
   - ca-file
+  - check
+  - check-proto
+  - check-send-proxy
+  - check-via-socks4
   - ciphers
   - ciphersuites
   - crl-file
   - crt
   - disabled
+  - downinter
   - enabled
+  - fall
+  - fastinter
   - force-sslv3/tlsv10/tlsv11/tlsv12/tlsv13
   - id
+  - inter
   - maxconn
   - maxqueue
   - minconn
@@ -1499,8 +1512,10 @@ add server <backend>/<server> [args]*
   - pool-low-conn
   - pool-max-conn
   - pool-purge-delay
+  - port
   - proto
   - proxy-v2-options
+  - rise
   - send-proxy
   - send-proxy-v2
   - send-proxy-v2-ssl
index 4055c9f27efe15e0c9c3729a4e4fd7c2ba6fa996..637b6c905c70c7a4a16774f768638a8212054228 100644 (file)
@@ -2386,7 +2386,7 @@ static struct srv_kw_list srv_kws = { "CHK", { }, {
        { "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. */
-       { "check",               srv_parse_check,               0,  1,  0 }, /* Enable health checks */
+       { "check",               srv_parse_check,               0,  1,  1 }, /* Enable health checks */
        { "check-proto",         srv_parse_check_proto,         1,  1,  1 }, /* Set the mux protocol for health checks  */
        { "check-send-proxy",    srv_parse_check_send_proxy,    0,  1,  1 }, /* Enable PROXY protocol for health checks */
        { "check-via-socks4",    srv_parse_check_via_socks4,    0,  1,  1 }, /* Enable socks4 proxy for health checks */
index 84b9cd25a8d565d2b0420bb70d28bd91c4ba55f9..749d44e5bedb1d733b94d9c707657750875b4a7e 100644 (file)
@@ -4564,6 +4564,18 @@ 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.
+        */
+       if (srv->do_check) {
+               if (init_srv_check(srv))
+                       goto out;
+
+               srv->check.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
         * isolation.
@@ -4615,6 +4627,16 @@ static int cli_parse_add_server(char **args, char *payload, struct appctx *appct
        srv_use_dynsrv(srv);
        thread_release();
 
+       /* Start the check task. The server must be fully initialized.
+        *
+        * <srvpos> and <nbcheck> parameters are set to 1 as there should be no
+        * need to randomly spread the task interval for dynamic servers.
+        */
+       if (srv->check.state & CHK_ST_CONFIGURED) {
+               if (!start_check_task(&srv->check, 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());
 
@@ -4625,6 +4647,9 @@ out:
                if (srv->track)
                        release_server_track(srv);
 
+               if (srv->check.state & CHK_ST_CONFIGURED)
+                       free_check(&srv->check);
+
                /* remove the server from the proxy linked list */
                if (be->srv == srv) {
                        be->srv = srv->next;
@@ -4728,9 +4753,9 @@ static int cli_parse_delete_server(char **args, char *payload, struct appctx *ap
        if (srv->track)
                release_server_track(srv);
 
-       /* TODO remove server for check list once 'check' will be implemented for
-        * dynamic servers
-        */
+       /* stop the check task if running */
+       if (srv->check.state & CHK_ST_CONFIGURED)
+               check_purge(&srv->check);
 
        /* detach the server from the proxy linked list
         * The proxy servers list is currently not protected by a lock, so this