]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: mux-h2: update session trackers with number of glitches
authorWilly Tarreau <w@1wt.eu>
Fri, 19 Jan 2024 16:33:27 +0000 (17:33 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 8 Feb 2024 14:51:49 +0000 (15:51 +0100)
We now update the session's tracked counters with the observed glitches.
In order to avoid incurring a high cost, e.g. if many small frames contain
issues, we batch the updates around h2_process_demux() by directly passing
the difference. Indeed, for now all functions that increment glitches are
called from h2_process_demux(). If that were to change, we'd just need to
keep the value of the last synced counter in the h2c struct instead of the
stack.

The regtest was updated to verify that the 3rd client that does not cause
issue still sees the counter resulting from client 2's mistakes. The rate
is also verified, considering it shouldn't fail since the period is very
long (1m).

reg-tests/connection/h2_glitches.vtc
src/mux_h2.c

index 39ec4d68522d6626c1db7b4684d63cf036239b26..4f25164d0406acbb15cb5bb82bf3e5f62b725ef6 100644 (file)
@@ -11,7 +11,9 @@ haproxy hap -conf {
 
        listen fe1
                bind "fd@${fe1}" proto h2
-               http-request return status 200 hdr x-glitches %[fc_glitches]
+               tcp-request session track-sc0 src
+               http-request return status 200 hdr x-glitches %[fc_glitches] hdr x-glitch-cnt %[sc0_glitch_cnt] hdr x-glitch-rate %[sc0_glitch_rate]
+               stick-table type ip size 10 store glitch_cnt,glitch_rate(1m)
 } -start
 
 # valid request: no glitch
@@ -73,6 +75,8 @@ client c2-path -connect ${hap_fe1_sock} {
                rxresp
                expect resp.status == 200
                expect resp.http.x-glitches == 1
+               expect resp.http.x-glitch-cnt == 1
+               expect resp.http.x-glitch-rate == 1
        } -run
 } -run
 
@@ -104,5 +108,7 @@ client c3-scheme -connect ${hap_fe1_sock} {
                rxresp
                expect resp.status == 200
                expect resp.http.x-glitches == 0
+               expect resp.http.x-glitch-cnt == 1
+               expect resp.http.x-glitch-rate == 1
        } -run
 } -run
index 4925d8d155ae8e69efa0cad7f68dd5e78eef252e..94724a2f9a0bd46a46f466073f5b9dfa56a3211b 100644 (file)
@@ -4364,8 +4364,13 @@ static int h2_process(struct h2c *h2c)
 
        if (!(h2c->flags & H2_CF_DEM_BLOCK_ANY) &&
            (b_data(&h2c->dbuf) || (h2c->flags & H2_CF_RCVD_SHUT))) {
+               int prev_glitches = h2c->glitches;
+
                h2_process_demux(h2c);
 
+               if (h2c->glitches != prev_glitches && !(h2c->flags & H2_CF_IS_BACK))
+                       session_add_glitch_ctr(h2c->conn->owner, h2c->glitches - prev_glitches);
+
                if (h2c->st0 >= H2_CS_ERROR || (h2c->flags & H2_CF_ERROR))
                        b_reset(&h2c->dbuf);