]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: agent-check: Be able to set absolute weight via an agent
authorChristopher Faulet <cfaulet@haproxy.com>
Mon, 18 Nov 2024 07:35:22 +0000 (08:35 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Tue, 19 Nov 2024 14:29:40 +0000 (15:29 +0100)
Historically, an agent-check program is only able to set a proportial weight
to the initial server's weight. However, it could be handy to also set an
absolute value. It is the purpose of this patch.

Instead of changing the current way to set a server's weight, a new
agent-check command is introduced. The string "weight:", followed by an
positive interger or a positive interger percentage, can now be used. If the
value ends with the '%' sign, then the new weight will be proportional to
the initially weight of the server. Otherwise, the value is considered as an
absolute weight and must be between 0 and 256.

This patch should fix the issue #360.

doc/configuration.txt
src/tcpcheck.c

index afe5edb385961494b9fb04082dd955b916c9aa4e..ebebcbd0a0483958d258108b66831369c4ef4468 100644 (file)
@@ -17351,7 +17351,22 @@ agent-check
     Values in this format will set the weight proportional to the initial
     weight of a server as configured when HAProxy starts. Note that a zero
     weight is reported on the stats page as "DRAIN" since it has the same
-    effect on the server (it's removed from the LB farm).
+    effect on the server (it's removed from the LB farm). It is the legacy way
+    to set the weight of a server. Setting it with the "weight:" prefix is
+    preferred.
+
+  - The string "weight:" following by an positive interger or a positive
+    interger percentage, with no space. If the value ends with the '%' sign,
+    then the new weight will be proportional to the initially weight of the
+    server. Otherwise, the value is considered as an absolute weight and must
+    be between 0 and 256. Servers which are part of a farm running a static
+    load-balancing algorithm have stricter limitations because the weight
+    cannot change once set. Thus for these servers, the only accepted values
+    are 0 and 100% (or 0 and the initial weight). Changes take effect
+    immediately, though certain LB algorithms require a certain amount of
+    requests to consider changes. Note that a zero weight is reported on the
+    stats page as "DRAIN" since it has the same effect on the server (it's
+    removed from the LB farm).
 
   - The string "maxconn:" followed by an integer (no space between). Values
     in this format will set the maxconn of a server. The maximum number of
index 10aad1af82fffb62d3bf4e341938b3d95be6ca06..6e12eb6c28ca41ba92ac388498c3e77346ce23af 100644 (file)
@@ -1090,6 +1090,10 @@ enum tcpcheck_eval_ret tcpcheck_agent_expect_reply(struct check *check, struct t
                else if (strncasecmp(cmd, "maxconn:", strlen("maxconn:")) == 0) {
                        sc = cmd;
                }
+               /* try to parse a maxconn here */
+               else if (strncasecmp(cmd, "weight:", strlen("weight:")) == 0) {
+                       ps = cmd + strlen("weight:");
+               }
                else {
                        /* keep a copy of the first error */
                        if (!err)