Great! I have attached the patch generated with "git format-patch -1"
and copied it below, feel free to adjust the commit message.

Thank you!
-Joey Lynch

=== Patch ===

>From d91890e9e1ea7ded8e6b2e50472ee08fc2008667 Mon Sep 17 00:00:00 2001
From: Joseph Lynch <[email protected]>
Date: Thu, 15 Jan 2015 17:52:59 -0800
Subject: [PATCH] Include server address and port in the send-state header

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 | 8 ++++++++
 src/checks.c          | 9 +++++++--
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/doc/configuration.txt b/doc/configuration.txt
index 3ae6624..c8b648b 100644
--- a/doc/configuration.txt
+++ b/doc/configuration.txt
@@ -2896,6 +2896,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.
diff --git a/src/checks.c b/src/checks.c
index 71debb6..1959c98 100644
--- a/src/checks.c
+++ b/src/checks.c
@@ -471,6 +471,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",
@@ -501,8 +503,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,
-- 
2.2.1

=== End patch ===

On Wed, Mar 25, 2015 at 11:32 PM, Willy Tarreau <[email protected]> wrote:
> Hi Joseph,
>
> On Wed, Mar 25, 2015 at 06:45:29PM -0700, Joseph Lynch wrote:
>> Willy,
>>
>> Thank you for the feedback. I believe that the patch attached at the
>> bottom of this email incorporates your suggestions. Please let me know
>> any further steps I need to take.
>
> It took me a while to remember this conversation but your patch is OK :-)
> Could you please provide a commit message briefly describing the problem
> the patch is trying to solve and how it solves it ? You seem to be using
> git, so if in doubt, just do a "git log" to get an idea about the type of
> messages you could build. Then you can do "git format-patch -1" to get the
> complete patch+commit ready to be applied. If you don't use it, don't
> worry, simply send such a description and I'll use that as the commit
> message while applying your patch.
>
> Thanks!
> Willy
>

Attachment: 0001-Include-server-address-and-port-in-the-send-state-he.patch
Description: Binary data

Reply via email to