Skip to content

Commit bd47e34

Browse files
committed
MINOR: connection: Add samples to retrieve info on streams for a connection
Thanks to the previous fix, it is now possible to get the number of opened streams for a connection and the negociated limit. Here, corresponding sample feches are added, in fc_ and bc_ scopes. On frontend side, the limit of streams is imposed by HAProxy. But on the backend side, the limit is defined by the server. it may be useful for debugging purpose because it may explain slow-downs on some processing.
1 parent eca9831 commit bd47e34

2 files changed

Lines changed: 77 additions & 1 deletion

File tree

doc/configuration.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21366,9 +21366,11 @@ bc_err integer
2136621366
bc_err_str string
2136721367
bc_glitches integer
2136821368
bc_http_major integer
21369+
bc_nb_streams integer
2136921370
bc_src ip
2137021371
bc_src_port integer
2137121372
bc_srv_queue integer
21373+
bc_settings_streams_limit integer
2137221374
be_id integer
2137321375
be_name string
2137421376
bc_rtt(<unit>) integer
@@ -21395,6 +21397,7 @@ fc_fackets integer
2139521397
fc_glitches integer
2139621398
fc_http_major integer
2139721399
fc_lost integer
21400+
fc_nb_streams integer
2139821401
fc_pp_authority string
2139921402
fc_pp_unique_id string
2140021403
fc_pp_tlv(<id>) string
@@ -21407,6 +21410,7 @@ fc_sacked integer
2140721410
fc_src ip
2140821411
fc_src_is_local boolean
2140921412
fc_src_port integer
21413+
fc_settings_streams_limit integer
2141021414
fc_unacked integer
2141121415
fe_defbe string
2141221416
fe_id integer
@@ -21639,6 +21643,9 @@ bc_http_major : integer
2163921643
for HTTP/0.9 to HTTP/1.1 or 2 for HTTP/2. Note, this is based on the on-wire
2164021644
encoding and not the version present in the request header.
2164121645

21646+
bc_nb_streams : integer
21647+
Returns the number of streams opened on the backend connection.
21648+
2164221649
bc_src : ip
2164321650
This is the source ip address of the connection on the server side, which is
2164421651
the server address HAProxy connected from. It is of type IP and works on both
@@ -21653,6 +21660,11 @@ bc_srv_queue : integer
2165321660
Number of streams de-queued while waiting for a connection slot on the
2165421661
target server. This is the equivalent of %sq in the log-format.
2165521662

21663+
bc_settings_streams_limit : integer
21664+
Returns the maximum number of streams allowed on the backend connection. For
21665+
TCP and HTTP/1.1 connections, it is always 1. For other protocols, it depends
21666+
on the settings negociated with the server.
21667+
2165621668
be_id : integer
2165721669
Returns an integer containing the current backend's id. It can be used in
2165821670
frontends with responses to check which backend processed the request. If
@@ -21877,6 +21889,9 @@ fc_lost : integer
2187721889
not TCP or if the operating system does not support TCP_INFO, for example
2187821890
Linux kernels before 2.4, the sample fetch fails.
2187921891

21892+
fc_nb_streams : integer
21893+
Returns the number of streams opened on the frontend connection.
21894+
2188021895
fc_pp_authority : string
2188121896
Returns the first authority TLV sent by the client in the PROXY protocol
2188221897
header, if any.
@@ -21962,6 +21977,10 @@ fc_src_port : integer
2196221977
connection on the client side. Only "tcp-request connection" rules may alter
2196321978
this address. See "src-port" for details.
2196421979

21980+
fc_settings_streams_limit : integer
21981+
Returns the maximum number of streams allowed on the frontend connection. For
21982+
TCP and HTTP/1.1 connections, it is always 1. For other protocols, it depends
21983+
on the settings negociated with the client.
2196521984

2196621985
fc_unacked : integer
2196721986
Returns the unacked counter measured by the kernel for the client connection.

src/connection.c

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2529,6 +2529,59 @@ int smp_fetch_fc_err_str(const struct arg *args, struct sample *smp, const char
25292529
return 1;
25302530
}
25312531

2532+
2533+
/* fetch the current number of streams opened for a connection */
2534+
int smp_fetch_fc_nb_streams(const struct arg *args, struct sample *smp, const char *kw, void *private)
2535+
{
2536+
struct connection *conn;
2537+
unsigned int nb_strm;
2538+
2539+
conn = (kw[0] != 'b') ? objt_conn(smp->sess->origin) : smp->strm ? sc_conn(smp->strm->scb) : NULL;
2540+
2541+
if (!conn)
2542+
return 0;
2543+
2544+
if (!conn->mux || !conn->mux->ctl) {
2545+
if (!conn->mux)
2546+
smp->flags |= SMP_F_MAY_CHANGE;
2547+
return 0;
2548+
}
2549+
2550+
nb_strm = conn->mux->ctl(conn, MUX_CTL_GET_NBSTRM, NULL);
2551+
2552+
smp->flags = SMP_F_VOL_TEST;
2553+
smp->data.type = SMP_T_SINT;
2554+
smp->data.u.sint = nb_strm;
2555+
2556+
return 1;
2557+
}
2558+
2559+
/* fetch the maximum number of streams supported by a connection */
2560+
int smp_fetch_fc_streams_limit(const struct arg *args, struct sample *smp, const char *kw, void *private)
2561+
{
2562+
struct connection *conn;
2563+
unsigned int strm_limit;
2564+
2565+
conn = (kw[0] != 'b') ? objt_conn(smp->sess->origin) : smp->strm ? sc_conn(smp->strm->scb) : NULL;
2566+
2567+
if (!conn)
2568+
return 0;
2569+
2570+
if (!conn->mux || !conn->mux->ctl) {
2571+
if (!conn->mux)
2572+
smp->flags |= SMP_F_MAY_CHANGE;
2573+
return 0;
2574+
}
2575+
2576+
strm_limit = conn->mux->ctl(conn, MUX_CTL_GET_MAXSTRM, NULL);
2577+
2578+
smp->flags = 0;
2579+
smp->data.type = SMP_T_SINT;
2580+
smp->data.u.sint = strm_limit;
2581+
2582+
return 1;
2583+
}
2584+
25322585
/* Note: must not be declared <const> as its list will be overwritten.
25332586
* Note: fetches that may return multiple types should be declared using the
25342587
* appropriate pseudo-type. If not available it must be declared as the lowest
@@ -2539,14 +2592,18 @@ static struct sample_fetch_kw_list sample_fetch_keywords = {ILH, {
25392592
{ "bc_err_str", smp_fetch_fc_err_str, 0, NULL, SMP_T_STR, SMP_USE_L4SRV },
25402593
{ "bc_glitches", smp_fetch_fc_glitches, 0, NULL, SMP_T_SINT, SMP_USE_L4SRV },
25412594
{ "bc_http_major", smp_fetch_fc_http_major, 0, NULL, SMP_T_SINT, SMP_USE_L4SRV },
2595+
{ "bc_nb_streams", smp_fetch_fc_nb_streams, 0, NULL, SMP_T_SINT, SMP_USE_L5SRV },
2596+
{ "bc_setting_streams_limit", smp_fetch_fc_streams_limit, 0, NULL, SMP_T_SINT, SMP_USE_L5SRV },
25422597
{ "fc_err", smp_fetch_fc_err, 0, NULL, SMP_T_SINT, SMP_USE_L4CLI },
25432598
{ "fc_err_str", smp_fetch_fc_err_str, 0, NULL, SMP_T_STR, SMP_USE_L4CLI },
25442599
{ "fc_glitches", smp_fetch_fc_glitches, 0, NULL, SMP_T_SINT, SMP_USE_L4CLI },
25452600
{ "fc_http_major", smp_fetch_fc_http_major, 0, NULL, SMP_T_SINT, SMP_USE_L4CLI },
25462601
{ "fc_rcvd_proxy", smp_fetch_fc_rcvd_proxy, 0, NULL, SMP_T_BOOL, SMP_USE_L4CLI },
2602+
{ "fc_nb_streams", smp_fetch_fc_nb_streams, 0, NULL, SMP_T_SINT, SMP_USE_L4CLI },
25472603
{ "fc_pp_authority", smp_fetch_fc_pp_authority, 0, NULL, SMP_T_STR, SMP_USE_L4CLI },
25482604
{ "fc_pp_unique_id", smp_fetch_fc_pp_unique_id, 0, NULL, SMP_T_STR, SMP_USE_L4CLI },
2549-
{ "fc_pp_tlv", smp_fetch_fc_pp_tlv, ARG1(1, STR), smp_check_tlv_type, SMP_T_STR, SMP_USE_L4CLI },
2605+
{ "fc_pp_tlv", smp_fetch_fc_pp_tlv, ARG1(1, STR), smp_check_tlv_type, SMP_T_STR, SMP_USE_L5CLI },
2606+
{ "fc_settings_streams_limit", smp_fetch_fc_streams_limit, 0, NULL, SMP_T_SINT, SMP_USE_L5CLI },
25502607
{ /* END */ },
25512608
}};
25522609

0 commit comments

Comments
 (0)