]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: mux-h2: implement the debug string for logs
authorWilly Tarreau <w@1wt.eu>
Tue, 30 Jul 2024 17:33:07 +0000 (19:33 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 7 Aug 2024 12:07:41 +0000 (14:07 +0200)
Now it permits to have this for a front and a back:

<134>Jul 30 19:32:53 haproxy[24405]: 127.0.0.1:64860 [30/Jul/2024:19:32:53.732] test2 test2/s1 0/0/0/0/0 200 130 - - ---- 2/1/0/0/0 0/0 "GET /blah HTTP/2.0"  h2s.id=1 .st=CLO .flg=0x7003 .rxbuf=0@(nil)+0/0 .sc=0x1e03fb0(.flg=0x00034482 .app=0x1e04020) .sd=0x1e03f30(.flg=0x50405601) .subs=(nil) h2c.st0=FRH .err=0 .maxid=1 .lastid=-1 .flg=0x100e00 .nbst=0 .nbsc=1, .glitches=0 .fctl_cnt=0 .send_cnt=0 .tree_cnt=1 .orph_cnt=0 .sub=1 .dsi=1 .dbuf=0@(nil)+0/0 .mbuf=[1..1|32],h=[0@(nil)+0/0],t=[0@(nil)+0/0] .task=(nil) conn.flg=0x80000300
<134>Jul 30 19:32:53 haproxy[24405]: 127.0.0.1:65246 [30/Jul/2024:19:32:53.732] test1 test1/s1 0/0/0/0/0 200 130 - - ---- 2/1/0/0/0 0/0 "GET /blah HTTP/1.1"  h2s.id=1 .st=CLO .flg=0x7003 .rxbuf=0@(nil)+0/0 .sc=0x1dfc7b0(.flg=0x0006d01b .app=0x1c65fe0) .sd=0x1dfc820(.flg=0x1040ca01) .subs=(nil) h2c.st0=FRH .err=0 .maxid=1 .lastid=-1 .flg=0x108e00 .nbst=0 .nbsc=1, .glitches=0 .fctl_cnt=0 .send_cnt=0 .tree_cnt=1 .orph_cnt=0 .sub=1 .dsi=1 .dbuf=0@(nil)+0/0 .mbuf=[1..1|32],h=[0@(nil)+0/0],t=[0@(nil)+0/0] .task=(nil) conn.flg=0x000300

Just with this in the front and back proxies respectively:
  log-format "$HAPROXY_HTTP_LOG_FMT %[bs.debug_str(15)]"
  log-format "$HAPROXY_HTTP_LOG_FMT %[fs.debug_str(15)]"

For now the mux only implements muxs, muxc, conn. Xprt is ignored.

src/mux_h2.c

index 8b670df64b02e3920bc988d2b1501dcf86ab430c..76c9b0805316fae4260c97361b9d29b5770f43a7 100644 (file)
@@ -521,6 +521,8 @@ struct task *h2_deferred_shut(struct task *t, void *ctx, unsigned int state);
 static struct h2s *h2c_bck_stream_new(struct h2c *h2c, struct stconn *sc, struct session *sess);
 static void h2s_alert(struct h2s *h2s);
 static inline void h2_remove_from_list(struct h2s *h2s);
+static int h2_dump_h2c_info(struct buffer *msg, struct h2c *h2c, const char *pfx);
+static int h2_dump_h2s_info(struct buffer *msg, const struct h2s *h2s, const char *pfx);
 
 /* returns the stconn associated to the H2 stream */
 static forceinline struct stconn *h2s_sc(const struct h2s *h2s)
@@ -4743,12 +4745,30 @@ static int h2_sctl(struct stconn *sc, enum mux_sctl_type mux_sctl, void *output)
 {
        int ret = 0;
        struct h2s *h2s = __sc_mux_strm(sc);
+       union mux_sctl_dbg_str_ctx *dbg_ctx;
+       struct buffer *buf;
 
        switch (mux_sctl) {
        case MUX_SCTL_SID:
                if (output)
                        *((int64_t *)output) = h2s->id;
                return ret;
+       case MUX_SCTL_DBG_STR:
+               dbg_ctx = output;
+               buf = get_trash_chunk();
+
+               if (dbg_ctx->arg.debug_flags & MUX_SCTL_DBG_STR_L_MUXS)
+                       h2_dump_h2s_info(buf, h2s, NULL);
+
+               if (dbg_ctx->arg.debug_flags & MUX_SCTL_DBG_STR_L_MUXC)
+                       h2_dump_h2c_info(buf, h2s->h2c, NULL);
+
+               if (dbg_ctx->arg.debug_flags & MUX_SCTL_DBG_STR_L_CONN)
+                       chunk_appendf(buf, " conn.flg=%#08x", h2s->h2c->conn->flags);
+
+               /* other layers not implemented */
+               dbg_ctx->ret.buf = *buf;
+               return ret;
 
        default:
                return -1;