MEDIUM: server: Inherit CLI weight changes and agent-check weight responses
When agent-check or CLI command executes relative weight change this patch
propagates it to tracking server allowing grouping many backends running on
same server underneath. Additionaly in case with many src IPs many backends
can have shared state checker, so there won't be unnecessary health checks.
[wt: Note: this will induce some behaviour change on some setups]
diff --git a/doc/configuration.txt b/doc/configuration.txt
index 05f0701..2914581 100644
--- a/doc/configuration.txt
+++ b/doc/configuration.txt
@@ -11422,6 +11422,10 @@
enabled. If <proxy> is omitted the current one is used. If disable-on-404 is
used, it has to be enabled on both proxies.
+ Note:
+ Relative weight changes are propagated to all tracking servers. Each
+ tracking server will have its weight recalculated separately.
+
tlsv10
This option may be used as "server" setting to reset any "no-tlsv10"
setting which would have been inherited from "default-server" directive as
diff --git a/doc/management.txt b/doc/management.txt
index 1d34f84..d4b7b68 100644
--- a/doc/management.txt
+++ b/doc/management.txt
@@ -1694,6 +1694,10 @@
"admin". Both the backend and the server may be specified either by their
name or by their numeric ID, prefixed with a sharp ('#').
+ Note:
+ Relative weight changes are propagated to all tracking servers. Each
+ tracking server will have its weight recalculated separately.
+
show cli sockets
List CLI sockets. The output format is composed of 3 fields separated by
spaces. The first field is the socket address, it can be a unix socket, a
diff --git a/src/server.c b/src/server.c
index b5d8890..721de33 100644
--- a/src/server.c
+++ b/src/server.c
@@ -47,6 +47,9 @@
static void srv_update_state(struct server *srv, int version, char **params);
static int srv_apply_lastaddr(struct server *srv, int *err_code);
+const char *server_propagate_weight_change_request(struct server *sv,
+ const char *weight_str);
+
/* List head of all known server keywords */
static struct srv_kw_list srv_keywords = {
.list = LIST_HEAD_INIT(srv_keywords.list)
@@ -1445,6 +1448,8 @@
struct proxy *px;
long int w;
char *end;
+ const char *msg;
+ int relative = 0;
px = sv->proxy;
@@ -1466,6 +1471,8 @@
w = sv->iweight * w / 100;
if (w > 256)
w = 256;
+
+ relative = 1;
}
else if (w < 0 || w > 256)
return "Absolute weight can only be between 0 and 256 inclusive.\n";
@@ -1478,6 +1485,28 @@
sv->uweight = w;
server_recalc_eweight(sv);
+ if (relative) {
+ msg = server_propagate_weight_change_request(sv, weight_str);
+ if (msg != NULL) {
+ return msg;
+ }
+ }
+
+ return NULL;
+}
+
+const char *server_propagate_weight_change_request(struct server *sv,
+ const char *weight_str)
+{
+ struct server *tracker;
+ const char *msg;
+
+ for (tracker = sv->trackers; tracker; tracker = tracker->tracknext) {
+ msg = server_parse_weight_change_request(tracker, weight_str);
+ if (msg)
+ return msg;
+ }
+
return NULL;
}