From 6c7771f1b40985b9458cdeb0adfd7bf2d14c3940 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Fri, 17 Nov 2023 19:29:02 +0100 Subject: [PATCH] MINOR: stream/cli: add another filter "susp" to "show sess" This one reports streams considered as "suspicious", i.e. those with no expiration dates or dates in the past, or those without a front endpoint. More criteria could be added in the future. --- doc/management.txt | 6 ++++-- src/stream.c | 19 ++++++++++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/doc/management.txt b/doc/management.txt index 163c04fe270b..00bee6f73867 100644 --- a/doc/management.txt +++ b/doc/management.txt @@ -3144,13 +3144,15 @@ show sess the last one that was created before the command was entered; those which die in the mean time will not appear. -show sess | older | all +show sess | older | susp | all Display a lot of internal information about the matching sessions. In the first form, only the session matching the specified session identifier will be shown. This identifier is the first field at the beginning of the lines in the dumps of "show sess" (it corresponds to the session pointer). In the second form, only sessions older than (in seconds by default) will be - shown. If "all" is used instead, then all sessions will be dumped. Dumping + shown. Passing "susp" instead will only report entries that are considered as + suspicious by the developers based on criteria that may in time or vary along + versions. If "all" is used instead, then all sessions will be dumped. Dumping many sessions can produce a huge output, take a lot of time and be CPU intensive, so it's always better to only dump the minimum needed. Those information are useless to most users but may be used by haproxy developers diff --git a/src/stream.c b/src/stream.c index 1eddd9cd5932..392dc79cc104 100644 --- a/src/stream.c +++ b/src/stream.c @@ -3109,6 +3109,8 @@ void list_services(FILE *out) } /* appctx context used by the "show sess" command */ +/* flags used for show_sess_ctx.flags */ +#define CLI_SHOWSESS_F_SUSP 0x00000001 /* show only suspicious streams */ struct show_sess_ctx { struct bref bref; /* back-reference from the session being dumped */ @@ -3116,6 +3118,7 @@ struct show_sess_ctx { unsigned int thr; /* the thread number being explored (0..MAX_THREADS-1) */ unsigned int uid; /* if non-null, the uniq_id of the session being dumped */ unsigned int min_age; /* minimum age of streams to dump */ + unsigned int flags; /* CLI_SHOWSESS_* */ int section; /* section of the session being dumped */ int pos; /* last position of the current session's buffer */ }; @@ -3532,6 +3535,10 @@ static int cli_parse_show_sess(char **args, char *payload, struct appctx *appctx ctx->min_age = timeout; ctx->target = (void *)-1; /* show all matching entries */ } + else if (*args[2] && strcmp(args[2], "susp") == 0) { + ctx->flags |= CLI_SHOWSESS_F_SUSP; + ctx->target = (void *)-1; /* show all matching entries */ + } else if (*args[2] && strcmp(args[2], "all") == 0) ctx->target = (void *)-1; else if (*args[2]) @@ -3619,6 +3626,16 @@ static int cli_io_handler_dump_sess(struct appctx *appctx) goto next_sess; } + if (ctx->flags & CLI_SHOWSESS_F_SUSP) { + /* only show suspicious streams. Non-suspicious ones have a valid + * expiration date in the future and a valid front endpoint. + */ + if (curr_strm->task->expire && + !tick_is_expired(curr_strm->task->expire, now_ms) && + curr_strm->scf && curr_strm->scf->sedesc && curr_strm->scf->sedesc->se) + goto next_sess; + } + if (ctx->target) { if (ctx->target != (void *)-1 && ctx->target != curr_strm) goto next_sess; @@ -3845,7 +3862,7 @@ static int cli_parse_shutdown_sessions_server(char **args, char *payload, struct /* register cli keywords */ static struct cli_kw_list cli_kws = {{ },{ - { { "show", "sess", NULL }, "show sess [|all|older ] : report the list of current sessions or dump this exact session", cli_parse_show_sess, cli_io_handler_dump_sess, cli_release_show_sess }, + { { "show", "sess", NULL }, "show sess [|all|susp|older ] : report the list of current sessions or dump this exact session", cli_parse_show_sess, cli_io_handler_dump_sess, cli_release_show_sess }, { { "shutdown", "session", NULL }, "shutdown session [id] : kill a specific session", cli_parse_shutdown_session, NULL, NULL }, { { "shutdown", "sessions", "server" }, "shutdown sessions server / : kill sessions on a server", cli_parse_shutdown_sessions_server, NULL, NULL }, {{},}