Quantcast
Channel: Serverphorums.com - HAProxy
Viewing all articles
Browse latest Browse all 5112

Multiplexing multiple services behind one agent (feature suggestion; patch attached) (5 replies)

$
0
0
Hello haproxy@:

My name is James Brown; I wrote a small piece of software called hacheck
(https://github.com/Roguelazer/hacheck) which is designed to be a healthcheck
proxy for decentralized load balancer control (remove a node from a load
balancer without knowing where the load balancers are; helpful once you
start to have a truly, stupidly large number of load balancers).

I am interested in using agent-checks instead of co-opting the existing
httpchk mechanism; unfortunately, it looks like there's no convenient way to
multiplex multiple services onto a single agent-port and reasonably
disambiguate them. For example, it'd be great if I could have a server which
runs one agent-check responder and can `MAINT` any of a dozen (or a hundred)
different services running on this box.

I've attached a small patch which adds a new server parameter (agent-send)
which is a static string which will be sent to the agent on every server.
This allows me to generate configs that look like

backend foo
server web1 10.1.2.1:8001 agent-check agent-port 3334 agent-send "foo/web1\n"
server web2 10.1.2.2:8001 agent-check agent-port 3334 agent-send "foo/web2\n"

backend bar
server web1 10.1.2.1:8002 agent-check agent-port 3334 agent-send "bar/web1\n"
server web2 10.1.2.2:8002 agent-check agent-port 3334 agent-send "bar/web2\n"

And have a single service (running on port 3334) which can easily MAINT or
UP either "foo" or "bar" depending on the value that it receives.

The patch seems to work in my limited testing (that is to say, HAProxy sends
the string and doesn't segfault or leak infinite amounts of RAM).

Does this sound useful to anyone else? Is it worth upstreaming the patch? I
welcome your thoughts.
--
James Brown
Engineer
EasyPost
commit dde76f0aadfcd386c36b27fb4ff49a5163bc9b93
Author: James Brown <jbrown@easypost.com>
Date: Wed Oct 21 18:19:05 2015 -0700

Add agent-send server parameter

Causes HAProxy to emit a static string to the agent on every check,
so that you can independently control multiple services running
behind a single agent port.

diff --git a/doc/configuration.txt b/doc/configuration.txt
index b509238..2452223 100644
--- a/doc/configuration.txt
+++ b/doc/configuration.txt
@@ -10056,6 +10056,13 @@ agent-check

Supported in default-server: No

+agent-send <string>
+ If this option is specified, haproxy will send the given string (verbatim)
+ to the agent server upon connection. You could, for example, encode
+ the backend name into this string, which would enable your agent to send
+ different responses based on the backend. Make sure to include a '\n' if
+ you want to terminate your request with a newline.
+
agent-inter <delay>
The "agent-inter" parameter sets the interval between two agent checks
to <delay> milliseconds. If left unspecified, the delay defaults to 2000 ms.
diff --git a/include/types/checks.h b/include/types/checks.h
index 02fc743..dd20184 100644
--- a/include/types/checks.h
+++ b/include/types/checks.h
@@ -176,6 +176,8 @@ struct check {
* rise to rise+fall-1 = good */
int rise, fall; /* time in iterations */
int type; /* Check type, one of PR_O2_*_CHK */
+ char *send_string; /* optionally send a string when connecting to the agent */
+ int send_string_len; /* length of agent command string */
struct server *server; /* back-pointer to server */
char **argv; /* the arguments to use if running a process-based check */
char **envp; /* the environment to use if running a process-based check */
diff --git a/src/checks.c b/src/checks.c
index ade2428..0e72a32 100644
--- a/src/checks.c
+++ b/src/checks.c
@@ -1459,6 +1459,10 @@ static int connect_conn_chk(struct task *t)
}
}

+ if ((check->type & PR_O2_LB_AGENT_CHK) && check->send_string_len) {
+ bo_putblk(check->bo, check->send_string, check->send_string_len);
+ }
+
/* prepare a new connection */
conn_init(conn);

diff --git a/src/server.c b/src/server.c
index 8ddff00..55c2678 100644
--- a/src/server.c
+++ b/src/server.c
@@ -984,6 +984,8 @@ int parse_server(const char *file, int linenum, char **args, struct proxy *curpr
newsrv->check.downinter = curproxy->defsrv.check.downinter;
newsrv->agent.use_ssl = curproxy->defsrv.agent.use_ssl;
newsrv->agent.port = curproxy->defsrv.agent.port;
+ newsrv->agent.send_string = curproxy->defsrv.agent.send_string;
+ newsrv->agent.send_string_len = curproxy->defsrv.agent.send_string_len;
newsrv->agent.inter = curproxy->defsrv.agent.inter;
newsrv->agent.fastinter = curproxy->defsrv.agent.fastinter;
newsrv->agent.downinter = curproxy->defsrv.agent.downinter;
@@ -1052,6 +1054,13 @@ int parse_server(const char *file, int linenum, char **args, struct proxy *curpr
newsrv->agent.port = atol(args[cur_arg + 1]);
cur_arg += 2;
}
+ else if (!strcmp(args[cur_arg], "agent-send")) {
+ global.maxsock++;
+ newsrv->agent.send_string_len = strlen(args[cur_arg + 1]);
+ newsrv->agent.send_string = calloc(1, newsrv->agent.send_string_len + 1);
+ memcpy(newsrv->agent.send_string, args[cur_arg + 1], newsrv->agent.send_string_len);
+ cur_arg += 2;
+ }
else if (!defsrv && !strcmp(args[cur_arg], "cookie")) {
newsrv->cookie = strdup(args[cur_arg + 1]);
newsrv->cklen = strlen(args[cur_arg + 1]);

Viewing all articles
Browse latest Browse all 5112

Trending Articles