MINOR: proxy: Add fe_name/be_name fetchers next to existing fe_id/be_id
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.
This commit is contained in:
parent
8e0f17543e
commit
d2471c2bdc
@ -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
|
||||
|
@ -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, },
|
||||
|
@ -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 */ },
|
||||
|
Loading…
x
Reference in New Issue
Block a user