]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: tevt: Add a sample to get termination events for all locations
authorChristopher Faulet <cfaulet@haproxy.com>
Tue, 21 Jan 2025 06:46:17 +0000 (07:46 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 31 Jan 2025 09:41:50 +0000 (10:41 +0100)
"term_events" is a sample fetche function that can be used to get
termination events for all locations in one call. The format equivalent to:

  {fc_term_events,fc_mux_term_events,fs.term_events,txn.term_events,bs.term_events,bc_mux_term_events,bc_term_events}

If no event was reported for a location, the field is empty. If the feature
is not supported yet, a dash ('-') is printed.

doc/configuration.txt
src/stream.c

index ac888590f1357b22adb27fc4245e564fdfce3dec..2d6ba4b1473792c981a21be14cf297d8f1ce15ac 100644 (file)
@@ -22087,6 +22087,7 @@ stopping                                           boolean
 str(<string>)                                      string
 table_avl([<table>])                               integer
 table_cnt([<table>])                               integer
+term_events                                        string
 thread                                             integer
 txn.id32                                           integer
 txn.sess_term_state                                string
@@ -22565,6 +22566,27 @@ table_cnt([<table>]) : integer
   stick-table or in the designated stick-table. See also "table_conn_cnt" and
   table_avl for other entry counting methods.
 
+term_events: string
+  Returns all known termination events for all entities attached a stream, on
+  client and server sides. A tuple of seven elements is returned with following info:
+
+    - the termination events of the frontend connection
+    - the termination events of the frontend mux connection
+    - the termination events of the frontend stream endpoint descriptor
+      (the mux stream or the applet)
+    - the termination events of the stream
+    - the termination events of the backend stream endpoint descriptor
+      (the mux stream or the applet)
+    - the termination events of the backend mux connection
+    - the termination events of the backend connection
+
+  At each level, the first four events are reported. An empty string is
+  returned if no event was reported yet for a specific level. If termination
+  events are not supported, a "-" is returned.
+
+  It must only be used for debugging purpose. The exact format is not
+  documented because it may evolve depending on developers requirements.
+
 thread : integer
   Returns an integer value corresponding to the position of the thread calling
   the function, between 0 and (global.nbthread-1). This is useful for logging
index f82a858063f17b7a26fa5f40e72f49173b746b61..e85c2f61242184cc2e8799195dc0de151aa5d956 100644 (file)
@@ -4271,6 +4271,35 @@ static int smp_fetch_conn_retries(const struct arg *args, struct sample *smp, co
        return 1;
 }
 
+static int smp_fetch_tevts(const struct arg *args, struct sample *smp, const char *km, void *private)
+{
+       struct buffer *trash = get_trash_chunk();
+       struct connection *fconn, *bconn;
+       int fc_mux_ret, bc_mux_ret;
+
+       fconn = smp->sess ? objt_conn(smp->sess->origin) : NULL;
+       bconn = smp->strm ? sc_conn(smp->strm->scb) : NULL;
+       fc_mux_ret = bc_mux_ret = -1;
+
+       if (fconn && fconn->mux && fconn->mux->ctl)
+               fc_mux_ret = fconn->mux->ctl(fconn, MUX_CTL_TEVTS, NULL);
+       if (bconn && bconn->mux && bconn->mux->ctl)
+               bc_mux_ret = bconn->mux->ctl(bconn, MUX_CTL_TEVTS, NULL);
+
+       chunk_printf(trash, "{%s,", fconn ? tevt_evts2str(fconn->term_evts_log) : "-");
+       chunk_appendf(trash, "%s,", (fc_mux_ret != -1) ? tevt_evts2str(fc_mux_ret) : "-");
+       chunk_appendf(trash, "%s,", smp->strm ? tevt_evts2str(smp->strm->scf->sedesc->term_evts_log) : "-");
+       chunk_appendf(trash, "%s,", smp->strm ? tevt_evts2str(smp->strm->term_evts_log) : "-");
+       chunk_appendf(trash, "%s,", smp->strm ? tevt_evts2str(smp->strm->scb->sedesc->term_evts_log) : "-");
+       chunk_appendf(trash, "%s,", (bc_mux_ret != -1) ? tevt_evts2str(bc_mux_ret) : "-");
+       chunk_appendf(trash, "%s}", bconn ? tevt_evts2str(bconn->term_evts_log) : "-");
+
+       smp->data.u.str = *trash;
+       smp->data.type = SMP_T_STR;
+       smp->flags = SMP_F_VOL_TEST | SMP_F_MAY_CHANGE;
+       return 1;
+}
+
 static int smp_fetch_id32(const struct arg *args, struct sample *smp, const char *km, void *private)
 {
        smp->flags = SMP_F_VOL_TXN;
@@ -4304,6 +4333,7 @@ static struct sample_fetch_kw_list smp_kws = {ILH, {
        { "last_entity",        smp_fetch_last_entity,        0, NULL, SMP_T_STR,  SMP_USE_INTRN, },
        { "last_rule_file",     smp_fetch_last_rule_file,     0, NULL, SMP_T_STR,  SMP_USE_INTRN, },
        { "last_rule_line",     smp_fetch_last_rule_line,     0, NULL, SMP_T_SINT, SMP_USE_INTRN, },
+       { "term_events",        smp_fetch_tevts,              0, NULL, SMP_T_STR,  SMP_USE_INTRN, },
        { "txn.conn_retries",   smp_fetch_conn_retries,       0, NULL, SMP_T_SINT, SMP_USE_L4SRV, },
        { "txn.id32",           smp_fetch_id32,               0, NULL, SMP_T_SINT, SMP_USE_INTRN, },
        { "txn.redispatched",   smp_fetch_redispatched,       0, NULL, SMP_T_BOOL, SMP_USE_L4SRV, },