]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: proxy: Add fe_name/be_name fetchers next to existing fe_id/be_id
authorMarcin Deranek <marcin.deranek@booking.com>
Mon, 12 Dec 2016 13:08:05 +0000 (14:08 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 12 Dec 2016 14:10:43 +0000 (15:10 +0100)
These 2 patches add ability to fetch frontend/backend name in your
logic, so they can be used later to make routing decisions (fe_name) or
taking some actions based on backend which responded to request (be_name).
In our case we needed a fetcher to be able to extract information we
needed from frontend name.

doc/configuration.txt
src/backend.c
src/frontend.c

index ae76ef317601b0110fb25b0562c339ef51ba4bc8..4cc9926b010b673ecbb678a0d7074aff6408f776 100644 (file)
@@ -13089,6 +13089,10 @@ be_id : integer
   Returns an integer containing the current backend's id. It can be used in
   frontends with responses to check which backend processed the request.
 
+be_name : string
+  Returns a string containing the current backend's name. It can be used in
+  frontends with responses to check which backend processed the request.
+
 dst : ip
   This is the destination IPv4 address of the connection on the client side,
   which is the address the client connected to. It can be useful when running
@@ -13181,6 +13185,11 @@ fe_id : integer
   backends to check from which backend it was called, or to stick all users
   coming via a same frontend to the same server.
 
+fe_name : string
+  Returns a string containing the current frontend's name. It can be used in
+  backends to check from which frontend it was called, or to stick all users
+  coming via a same frontend to the same server.
+
 sc_bytes_in_rate(<ctr>[,<table>]) : integer
 sc0_bytes_in_rate([<table>]) : integer
 sc1_bytes_in_rate([<table>]) : integer
index 57f811f38f814e741366cd23f9102efcfa9a7911..e0e53ffa04a08133d854161fbd64e067d8720d42 100644 (file)
@@ -1681,6 +1681,24 @@ smp_fetch_be_id(const struct arg *args, struct sample *smp, const char *kw, void
        return 1;
 }
 
+/* set string to the name of the backend */
+static int
+smp_fetch_be_name(const struct arg *args, struct sample *smp, const char *kw, void *private)
+{
+       if (!smp->strm)
+               return 0;
+
+       smp->data.u.str.str = (char *)smp->strm->be->id;
+       if (!smp->data.u.str.str)
+               return 0;
+
+       smp->data.type = SMP_T_STR;
+       smp->flags = SMP_F_CONST;
+       smp->data.u.str.len = strlen(smp->data.u.str.str);
+
+       return 1;
+}
+
 /* set temp integer to the id of the server */
 static int
 smp_fetch_srv_id(const struct arg *args, struct sample *smp, const char *kw, void *private)
@@ -1803,6 +1821,7 @@ static struct sample_fetch_kw_list smp_kws = {ILH, {
        { "avg_queue",     smp_fetch_avg_queue_size, ARG1(1,BE),  NULL, SMP_T_SINT, SMP_USE_INTRN, },
        { "be_conn",       smp_fetch_be_conn,        ARG1(1,BE),  NULL, SMP_T_SINT, SMP_USE_INTRN, },
        { "be_id",         smp_fetch_be_id,          0,           NULL, SMP_T_SINT, SMP_USE_BKEND, },
+       { "be_name",       smp_fetch_be_name,        0,           NULL, SMP_T_STR,  SMP_USE_BKEND, },
        { "be_sess_rate",  smp_fetch_be_sess_rate,   ARG1(1,BE),  NULL, SMP_T_SINT, SMP_USE_INTRN, },
        { "connslots",     smp_fetch_connslots,      ARG1(1,BE),  NULL, SMP_T_SINT, SMP_USE_INTRN, },
        { "nbsrv",         smp_fetch_nbsrv,          ARG1(1,BE),  NULL, SMP_T_SINT, SMP_USE_INTRN, },
index 5cc6202a26c5495a53e156c3eca1b002d60641ab..2fafdeaf7c1593fa42f140e6ff75141511cbd9bd 100644 (file)
@@ -167,6 +167,20 @@ smp_fetch_fe_id(const struct arg *args, struct sample *smp, const char *kw, void
        return 1;
 }
 
+/* set string to the name of the frontend */
+static int
+smp_fetch_fe_name(const struct arg *args, struct sample *smp, const char *kw, void *private)
+{
+       smp->data.u.str.str = (char *)smp->sess->fe->id;
+       if (!smp->data.u.str.str)
+               return 0;
+
+       smp->data.type = SMP_T_STR;
+       smp->flags = SMP_F_CONST;
+       smp->data.u.str.len = strlen(smp->data.u.str.str);
+       return 1;
+}
+
 /* set temp integer to the number of HTTP requests per second reaching the frontend.
  * Accepts exactly 1 argument. Argument is a frontend, other types will cause
  * an undefined behaviour.
@@ -213,6 +227,7 @@ smp_fetch_fe_conn(const struct arg *args, struct sample *smp, const char *kw, vo
 static struct sample_fetch_kw_list smp_kws = {ILH, {
        { "fe_conn",      smp_fetch_fe_conn,      ARG1(1,FE), NULL, SMP_T_SINT, SMP_USE_INTRN, },
        { "fe_id",        smp_fetch_fe_id,        0,          NULL, SMP_T_SINT, SMP_USE_FTEND, },
+       { "fe_name",      smp_fetch_fe_name,      0,          NULL, SMP_T_STR,  SMP_USE_FTEND, },
        { "fe_req_rate",  smp_fetch_fe_req_rate,  ARG1(1,FE), NULL, SMP_T_SINT, SMP_USE_INTRN, },
        { "fe_sess_rate", smp_fetch_fe_sess_rate, ARG1(1,FE), NULL, SMP_T_SINT, SMP_USE_INTRN, },
        { /* END */ },