Skip to content

Commit e9bc593

Browse files
committed
MINOR: agent-check: Be able to set absolute weight via an agent
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.
1 parent 1be7140 commit e9bc593

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

doc/configuration.txt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17351,7 +17351,22 @@ agent-check
1735117351
Values in this format will set the weight proportional to the initial
1735217352
weight of a server as configured when HAProxy starts. Note that a zero
1735317353
weight is reported on the stats page as "DRAIN" since it has the same
17354-
effect on the server (it's removed from the LB farm).
17354+
effect on the server (it's removed from the LB farm). It is the legacy way
17355+
to set the weight of a server. Setting it with the "weight:" prefix is
17356+
preferred.
17357+
17358+
- The string "weight:" following by an positive interger or a positive
17359+
interger percentage, with no space. If the value ends with the '%' sign,
17360+
then the new weight will be proportional to the initially weight of the
17361+
server. Otherwise, the value is considered as an absolute weight and must
17362+
be between 0 and 256. Servers which are part of a farm running a static
17363+
load-balancing algorithm have stricter limitations because the weight
17364+
cannot change once set. Thus for these servers, the only accepted values
17365+
are 0 and 100% (or 0 and the initial weight). Changes take effect
17366+
immediately, though certain LB algorithms require a certain amount of
17367+
requests to consider changes. Note that a zero weight is reported on the
17368+
stats page as "DRAIN" since it has the same effect on the server (it's
17369+
removed from the LB farm).
1735517370

1735617371
- The string "maxconn:" followed by an integer (no space between). Values
1735717372
in this format will set the maxconn of a server. The maximum number of

src/tcpcheck.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,6 +1090,10 @@ enum tcpcheck_eval_ret tcpcheck_agent_expect_reply(struct check *check, struct t
10901090
else if (strncasecmp(cmd, "maxconn:", strlen("maxconn:")) == 0) {
10911091
sc = cmd;
10921092
}
1093+
/* try to parse a maxconn here */
1094+
else if (strncasecmp(cmd, "weight:", strlen("weight:")) == 0) {
1095+
ps = cmd + strlen("weight:");
1096+
}
10931097
else {
10941098
/* keep a copy of the first error */
10951099
if (!err)

0 commit comments

Comments
 (0)