]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: check: include server address and port in the send-state header
authorJoseph Lynch <joe.e.lynch@gmail.com>
Fri, 16 Jan 2015 01:52:59 +0000 (17:52 -0800)
committerWilly Tarreau <w@1wt.eu>
Thu, 26 Mar 2015 22:40:42 +0000 (23:40 +0100)
This fixes an issue that occurs when backend servers run on different
addresses or ports and you wish to healthcheck them via a consistent
port. For example, if you allocate backends dynamically as containers
that expose different ports and you use an inetd based healthchecking
component that runs on a dedicated port.

By adding the server address and port to the send-state header, the
healthcheck component can deduce which address and port to check by
reading the X-Haproxy-Server-State header out of the healthcheck and
parsing out the address and port.

doc/configuration.txt
src/checks.c

index 34a1e49156b7cab876d1a6f658f4fbb83d071a4a..e0aa485abb64d3a0edac1512d796e800f6a1a140 100644 (file)
@@ -3109,6 +3109,14 @@ http-check send-state
   checks on the total number before transition, just as appears in the stats
   interface. Next headers are in the form "<variable>=<value>", indicating in
   no specific order some values available in the stats interface :
+    - a variable "address", containing the address of the backend server.
+      This corresponds to the <address> field in the server declaration. For
+      unix domain sockets, it will read "unix".
+
+    - a variable "port", containing the port of the backend server. This
+      corresponds to the <port> field in the server declaration. For unix
+      domain sockets, it will read "unix".
+
     - a variable "name", containing the name of the backend followed by a slash
       ("/") then the name of the server. This can be used when a server is
       checked in multiple backends.
index 2ef14d10291b00ce4464b96ebbe8d317f3c32508..89e5eeeb35a6d98f01a5422ab50e6c50b50cdcd3 100644 (file)
@@ -494,6 +494,8 @@ static int httpchk_build_status_header(struct server *s, char *buffer, int size)
        int sv_state;
        int ratio;
        int hlen = 0;
+       char addr[46];
+       char port[6];
        const char *srv_hlt_st[7] = { "DOWN", "DOWN %d/%d",
                                      "UP %d/%d", "UP",
                                      "NOLB %d/%d", "NOLB",
@@ -524,8 +526,11 @@ static int httpchk_build_status_header(struct server *s, char *buffer, int size)
                             (s->state != SRV_ST_STOPPED) ? (s->check.health - s->check.rise + 1) : (s->check.health),
                             (s->state != SRV_ST_STOPPED) ? (s->check.fall) : (s->check.rise));
 
-       hlen += snprintf(buffer + hlen,  size - hlen, "; name=%s/%s; node=%s; weight=%d/%d; scur=%d/%d; qcur=%d",
-                            s->proxy->id, s->id,
+       addr_to_str(&s->addr, addr, sizeof(addr));
+       port_to_str(&s->addr, port, sizeof(port));
+
+       hlen += snprintf(buffer + hlen,  size - hlen, "; address=%s; port=%s; name=%s/%s; node=%s; weight=%d/%d; scur=%d/%d; qcur=%d",
+                            addr, port, s->proxy->id, s->id,
                             global.node,
                             (s->eweight * s->proxy->lbprm.wmult + s->proxy->lbprm.wdiv - 1) / s->proxy->lbprm.wdiv,
                             (s->proxy->lbprm.tot_weight * s->proxy->lbprm.wmult + s->proxy->lbprm.wdiv - 1) / s->proxy->lbprm.wdiv,