From: Christopher Faulet Date: Tue, 4 Nov 2025 17:40:06 +0000 (+0100) Subject: MINOR: stream: Remove bytes_in and bytes_out counters from stream X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=567df50d91b9e58961d785eccd8ac596ca526a22;p=thirdparty%2Fhaproxy.git MINOR: stream: Remove bytes_in and bytes_out counters from stream 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. --- diff --git a/doc/configuration.txt b/doc/configuration.txt index e7ef09429..c47af4fbc 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -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 | diff --git a/include/haproxy/stream-t.h b/include/haproxy/stream-t.h index 8a1ba8fb3..77d8112bc 100644 --- a/include/haproxy/stream-t.h +++ b/include/haproxy/stream-t.h @@ -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 { diff --git a/src/cli.c b/src/cli.c index 22a6bf689..60e3eba73 100644 --- 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); diff --git a/src/http_ana.c b/src/http_ana.c index 6630edec2..78391b59f 100644 --- a/src/http_ana.c +++ b/src/http_ana.c @@ -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: diff --git a/src/log.c b/src/log.c index 9f8b7fb75..1aff73272 100644 --- 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; diff --git a/src/sample.c b/src/sample.c index c4fc16afc..943adc7a0 100644 --- a/src/sample.c +++ b/src/sample.c @@ -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; } diff --git a/src/stream.c b/src/stream.c index d8ed41935..a9539fa5b 100644 --- a/src/stream.c +++ b/src/stream.c @@ -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;