From: Willy Tarreau Date: Thu, 8 Feb 2024 20:45:22 +0000 (+0100) Subject: MINOR: cli: add a new "wait" command to wait for a certain delay X-Git-Tag: v3.0-dev3~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1d2255a78a728a68e711a0c7ecffb1b57dc673fe;p=thirdparty%2Fhaproxy.git MINOR: cli: add a new "wait" command to wait for a certain delay This allows to insert delays between commands, i.e. to collect a same set of metrics at a fixed interval. E.g: $ socat -t20 /path/to/socket <<< "show activity; wait 10s; show activity" The goal will be to extend the feature to optionally support waiting on certain conditions. For this reason the struct definitions and enums were placed into cli-t.h. --- diff --git a/doc/management.txt b/doc/management.txt index 63ba742c1f..c5e5579d37 100644 --- a/doc/management.txt +++ b/doc/management.txt @@ -3997,6 +3997,15 @@ update ssl ocsp-response local tree, its contents will be displayed on the standard output. The format is the same as the one described in "show ssl ocsp-response". +wait + This simply waits for the requested delay before continuing. This can be used + to collect metrics around a specific interval. The default unit for the delay + is milliseconds, though other units are accepted if suffixed with the usual + timer units (s, m, h, d). When used with the 'socat' utility, do not forget + to extend socat's close timeout to cover the wait time. + Example: + $ socat -t20 /path/to/socket <<< "show activity; wait 10s; show activity" + 9.4. Master CLI --------------- diff --git a/include/haproxy/cli-t.h b/include/haproxy/cli-t.h index c155df3387..9334fcd9f0 100644 --- a/include/haproxy/cli-t.h +++ b/include/haproxy/cli-t.h @@ -81,6 +81,27 @@ struct cli_print_ctx { int severity; /* severity of the message to be returned according to (syslog) rfc5424 */ }; +/* context for the "wait" command that's used to wait for some time on a + * condition. We store the start date and the expiration date. The error + * value is set by the I/O handler to be printed by the release handler at + * the end. + */ +enum cli_wait_err { + CLI_WAIT_ERR_DONE, // condition satisfied + CLI_WAIT_ERR_INTR, // interrupted + CLI_WAIT_ERR_EXP, // finished on wait expiration +}; + +enum cli_wait_cond { + CLI_WAIT_COND_NONE, // no condition to wait on +}; + +struct cli_wait_ctx { + uint start, deadline; // both are in ticks. + enum cli_wait_cond cond; // CLI_WAIT_COND_* + enum cli_wait_err error; // CLI_WAIT_ERR_* +}; + struct cli_kw { const char *str_kw[CLI_PREFIX_KW_NB]; /* keywords ended by NULL, limited to CLI_PREFIX_KW_NB separated keywords combination */ diff --git a/src/cli.c b/src/cli.c index 1546c0d7cd..acd5b8729e 100644 --- a/src/cli.c +++ b/src/cli.c @@ -2010,6 +2010,105 @@ static int cli_parse_set_ratelimit(char **args, char *payload, struct appctx *ap return 1; } +/* Parse a "wait