]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: stream: Remove bytes_in and bytes_out counters from stream
authorChristopher Faulet <cfaulet@haproxy.com>
Tue, 4 Nov 2025 17:40:06 +0000 (18:40 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Thu, 6 Nov 2025 14:01:29 +0000 (15:01 +0100)
per-stream bytes_in and bytes_out counters was removed and replaced by
req.in and res.in. Coorresponding samples still exists but replies on new
counters.

This patch is related to issue #1617.

doc/configuration.txt
include/haproxy/stream-t.h
src/cli.c
src/http_ana.c
src/log.c
src/sample.c
src/stream.c

index e7ef09429f04f4d2db65e51f4d54cce63dcbf449..c47af4fbcbd847ee814e527b67f7ae0c08dcc2a0 100644 (file)
@@ -23424,16 +23424,10 @@ be_tunnel_timeout : integer
   also the "cur_tunnel_timeout".
 
 bytes_in : integer
-  This returns the number of bytes uploaded from the client to the server. The
-  value corresponds to what was received by HAProxy, including some headers and
-  some internal encoding overhead. Request compression does not affect the
-  value reported here.
+  See "req.in".
 
 bytes_out : integer
-  This is the number of bytes transmitted from the server to the client. The
-  value corresponds to what was received by HAProxy, including some headers and
-  some internal encoding overhead. Response compression does not affect the
-  value reported here.
+  See "res.in".
 
 cur_client_timeout : integer
   Returns the currently applied client timeout in millisecond for the stream.
@@ -27851,7 +27845,7 @@ Please refer to the table below for currently defined aliases :
   |                          Others                                           |
   +---+------+------------------------------------------------------+---------+
   |   | %B   | bytes_read           (from server to client)         | numeric |
-  |   |      | %[bytes_out]                                         |         |
+  |   |      | %[res_in]                                            |         |
   +---+------+------------------------------------------------------+---------+
   | H | %CC  | captured_request_cookie                              | string  |
   +---+------+------------------------------------------------------+---------+
@@ -27882,7 +27876,7 @@ Please refer to the table below for currently defined aliases :
   |   |      | %[txn.status]                                        |         |
   +---+------+------------------------------------------------------+---------+
   |   | %U   | bytes_uploaded       (from client to server)         | numeric |
-  |   |      | %[bytes_in]                                          |         |
+  |   |      | %[req_in]                                            |         |
   +---+------+------------------------------------------------------+---------+
   |   | %ac  | actconn                                              |         |
   |   |      | %[act_conn]                                          | numeric |
index 8a1ba8fb32caf9dbbaa38ee4efeae6d9424c2f54..77d8112bc03b1e79ad859d568eb0f00df7ff7aa8 100644 (file)
@@ -229,8 +229,6 @@ struct strm_logs {
        long long req_out;              /* number of bytes sent to the server */
        long long res_in;               /* number of bytes received from the server */
        long long res_out;              /* number of bytes sent to the client */
-       long long bytes_in;             /* number of bytes transferred from the client to the server */
-       long long bytes_out;            /* number of bytes transferred from the server to the client */
 };
 
 struct stream {
index 22a6bf689d1faf0dcb1b190429548671ed854313..60e3eba7351d736ac3da3bb656d9a7880f95110f 100644 (file)
--- a/src/cli.c
+++ b/src/cli.c
@@ -3486,8 +3486,6 @@ int pcli_wait_for_response(struct stream *s, struct channel *rep, int an_bit)
                stream_process_counters(s);
 
                /* don't count other requests' data */
-               s->logs.bytes_in  -= ci_data(&s->req);
-               s->logs.bytes_out -= ci_data(&s->res);
                s->logs.req_in -= ci_data(&s->req);
                s->logs.res_in -= ci_data(&s->res);
 
@@ -3524,8 +3522,6 @@ int pcli_wait_for_response(struct stream *s, struct channel *rep, int an_bit)
                s->logs.prx_queue_pos = 0;  /* we get the number of pending conns before us */
                s->logs.srv_queue_pos = 0; /* we will get this number soon */
 
-               s->logs.bytes_in = s->req.total = ci_data(&s->req);
-               s->logs.bytes_out = s->res.total = ci_data(&s->res);
                s->logs.req_in = s->scf->bytes_in = ci_data(&s->req);
                s->logs.res_in = s->scb->bytes_in = ci_data(&s->res);
 
index 6630edec2e185189abf6495ce487a63e4db17a33..78391b59fde41e75abdb2711dfec923c222361b3 100644 (file)
@@ -1998,13 +1998,13 @@ int http_process_res_common(struct stream *s, struct channel *rep, int an_bit, s
 
        /* if the user wants to log as soon as possible, without counting
         * bytes from the server, then this is the right moment. We have
-        * to temporarily assign bytes_out to log what we currently have.
+        * to temporarily assign req_in to log what we currently have.
         */
        if (do_log) {
                s->logs.t_close = s->logs.t_data; /* to get a valid end date */
-               s->logs.res_in = s->logs.bytes_out = htx->data;
+               s->logs.res_in = htx->data;
                s->do_log(s, log_orig(LOG_ORIG_TXN_RESPONSE, LOG_ORIG_FL_NONE));
-               s->logs.res_in = s->logs.bytes_out = 0;
+               s->logs.res_in = 0;
        }
 
  done:
index 9f8b7fb754a20b1d5ab664f55bebaf1c35099c2a..1aff732725fbcb9595526e4d8623f431272f92fc 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -3933,8 +3933,8 @@ int sess_build_logline_orig(struct session *sess, struct stream *s,
                tmp_strm_log.t_connect = -1;
                tmp_strm_log.t_data = -1;
                tmp_strm_log.t_close = ns_to_ms(now_ns - sess->accept_ts);
-               tmp_strm_log.bytes_in = 0;
-               tmp_strm_log.bytes_out = 0;
+               tmp_strm_log.req_in = tmp_strm_log.req_out = 0;
+               tmp_strm_log.res_in = tmp_strm_log.res_out = 0;
                tmp_strm_log.prx_queue_pos = 0;
                tmp_strm_log.srv_queue_pos = 0;
 
@@ -4629,14 +4629,14 @@ int sess_build_logline_orig(struct session *sess, struct stream *s,
                        case LOG_FMT_BYTES: // %B
                                if (!(fe->to_log & LW_BYTES))
                                        LOGMETACHAR('+');
-                               ret = lf_int(tmplog, dst + maxsize - tmplog, logs->bytes_out, ctx, LF_INT_LLTOA);
+                               ret = lf_int(tmplog, dst + maxsize - tmplog, logs->req_in, ctx, LF_INT_LLTOA);
                                if (ret == NULL)
                                        goto out;
                                tmplog = ret;
                                break;
 
                        case LOG_FMT_BYTES_UP: // %U
-                               ret = lf_int(tmplog, dst + maxsize - tmplog, logs->bytes_in, ctx, LF_INT_LLTOA);
+                               ret = lf_int(tmplog, dst + maxsize - tmplog, logs->res_out, ctx, LF_INT_LLTOA);
                                if (ret == NULL)
                                        goto out;
                                tmplog = ret;
index c4fc16afc7e287a4438da2f5cbb6aa74f4de1706..943adc7a0110799eabd431b8611eb465b3d0bf11 100644 (file)
@@ -5449,7 +5449,7 @@ static int smp_fetch_bytes(const struct arg *args, struct sample *smp, const cha
        if (kw[2] == 's') /* res.in or res.out */
                smp->data.u.sint = (kw[4] == 'i') ? logs->res_in : logs->res_out;
        else /* bytes_in or bytes_out */
-               smp->data.u.sint = (kw[6] == 'i') ? logs->bytes_in : logs->bytes_out;
+               smp->data.u.sint = (kw[6] == 'i') ? logs->req_in : logs->res_in;
 
        return 1;
 }
index d8ed4193599942813c5798ce4c9f6b57408dec01..a9539fa5b223b43b93b4995b164508fa991da708 100644 (file)
@@ -370,7 +370,6 @@ struct stream *stream_new(struct session *sess, struct stconn *sc, struct buffer
        s->logs.t_close = 0;
        s->logs.req_in = s->logs.req_out = 0;
        s->logs.res_in = s->logs.res_out = 0;
-       s->logs.bytes_in = s->logs.bytes_out = 0;
        s->logs.prx_queue_pos = 0;  /* we get the number of pending conns before us */
        s->logs.srv_queue_pos = 0; /* we will get this number soon */
        s->obj_type = OBJ_TYPE_STREAM;
@@ -827,19 +826,27 @@ void stream_process_counters(struct stream *s)
        unsigned long long bytes;
        int i;
 
-       bytes = s->req.total - s->logs.bytes_in;
-       s->logs.bytes_in = s->req.total;
+       bytes = s->scf->bytes_in - s->logs.req_in;
+       s->logs.req_in = s->scf->bytes_in;
        if (bytes) {
-               if (sess->fe_tgcounters)
+               if (sess->fe_tgcounters) {
                        _HA_ATOMIC_ADD(&sess->fe_tgcounters->bytes_in, bytes);
-               if (s->be_tgcounters)
-                       _HA_ATOMIC_ADD(&s->be_tgcounters->bytes_in,    bytes);
+                       _HA_ATOMIC_ADD(&sess->fe_tgcounters->req_in, bytes);
+               }
+               if (s->be_tgcounters) {
+                       _HA_ATOMIC_ADD(&s->be_tgcounters->bytes_in, bytes);
+                       _HA_ATOMIC_ADD(&s->be_tgcounters->req_in, bytes);
+               }
 
-               if (s->sv_tgcounters)
+               if (s->sv_tgcounters) {
                        _HA_ATOMIC_ADD(&s->sv_tgcounters->bytes_in, bytes);
+                       _HA_ATOMIC_ADD(&s->sv_tgcounters->req_in, bytes);
+               }
 
-               if (sess->li_tgcounters)
+               if (sess->li_tgcounters) {
                        _HA_ATOMIC_ADD(&sess->li_tgcounters->bytes_in, bytes);
+                       _HA_ATOMIC_ADD(&sess->li_tgcounters->req_in, bytes);
+               }
 
                for (i = 0; i < global.tune.nb_stk_ctr; i++) {
                        if (!stkctr_inc_bytes_in_ctr(&s->stkctr[i], bytes))
@@ -847,41 +854,6 @@ void stream_process_counters(struct stream *s)
                }
        }
 
-       bytes = s->res.total - s->logs.bytes_out;
-       s->logs.bytes_out = s->res.total;
-       if (bytes) {
-               if (sess->fe_tgcounters)
-                       _HA_ATOMIC_ADD(&sess->fe_tgcounters->bytes_out, bytes);
-               if (s->be_tgcounters)
-                       _HA_ATOMIC_ADD(&s->be_tgcounters->bytes_out,    bytes);
-
-               if (s->sv_tgcounters)
-                       _HA_ATOMIC_ADD(&s->sv_tgcounters->bytes_out, bytes);
-
-               if (sess->li_tgcounters)
-                       _HA_ATOMIC_ADD(&sess->li_tgcounters->bytes_out, bytes);
-
-               for (i = 0; i < global.tune.nb_stk_ctr; i++) {
-                       if (!stkctr_inc_bytes_out_ctr(&s->stkctr[i], bytes))
-                               stkctr_inc_bytes_out_ctr(&sess->stkctr[i], bytes);
-               }
-       }
-
-       bytes = s->scf->bytes_in - s->logs.req_in;
-       s->logs.req_in = s->scf->bytes_in;
-       if (bytes) {
-               if (sess->fe_tgcounters)
-                       _HA_ATOMIC_ADD(&sess->fe_tgcounters->req_in, bytes);
-               if (s->be_tgcounters)
-                       _HA_ATOMIC_ADD(&s->be_tgcounters->req_in, bytes);
-
-               if (s->sv_tgcounters)
-                       _HA_ATOMIC_ADD(&s->sv_tgcounters->req_in, bytes);
-
-               if (sess->li_tgcounters)
-                       _HA_ATOMIC_ADD(&sess->li_tgcounters->req_in, bytes);
-       }
-
        bytes = s->scb->bytes_out - s->logs.req_out;
        s->logs.req_out = s->scb->bytes_out;
        if (bytes) {
@@ -900,16 +872,29 @@ void stream_process_counters(struct stream *s)
        bytes = s->scb->bytes_in - s->logs.res_in;
        s->logs.res_in = s->scb->bytes_in;
        if (bytes) {
-               if (sess->fe_tgcounters)
+               if (sess->fe_tgcounters) {
+                       _HA_ATOMIC_ADD(&sess->fe_tgcounters->bytes_out, bytes);
                        _HA_ATOMIC_ADD(&sess->fe_tgcounters->res_in, bytes);
-               if (s->be_tgcounters)
+               }
+               if (s->be_tgcounters) {
+                       _HA_ATOMIC_ADD(&s->be_tgcounters->bytes_out, bytes);
                        _HA_ATOMIC_ADD(&s->be_tgcounters->res_in, bytes);
+               }
 
-               if (s->sv_tgcounters)
+               if (s->sv_tgcounters) {
+                       _HA_ATOMIC_ADD(&s->sv_tgcounters->bytes_out, bytes);
                        _HA_ATOMIC_ADD(&s->sv_tgcounters->res_in, bytes);
+               }
 
-               if (sess->li_tgcounters)
+               if (sess->li_tgcounters) {
+                       _HA_ATOMIC_ADD(&sess->li_tgcounters->bytes_out, bytes);
                        _HA_ATOMIC_ADD(&sess->li_tgcounters->res_in, bytes);
+               }
+
+               for (i = 0; i < global.tune.nb_stk_ctr; i++) {
+                       if (!stkctr_inc_bytes_out_ctr(&s->stkctr[i], bytes))
+                               stkctr_inc_bytes_out_ctr(&sess->stkctr[i], bytes);
+               }
        }
 
        bytes = s->scf->bytes_out - s->logs.res_out;