MINOR: sample: add the "when" converter to condition some expressions
authorWilly Tarreau <w@1wt.eu>
Tue, 22 Oct 2024 17:43:18 +0000 (19:43 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Thu, 9 Jan 2025 09:28:04 +0000 (10:28 +0100)
commit2f5a432d581e11f867a55979c23d7f5d214eb8fa
treee6cb06f73b12c0f7fe73d2060e6750d99a03dd53
parent84649cd0ed5e510b47e7f1b44eaee1d1d4aab71d
MINOR: sample: add the "when" converter to condition some expressions

Sometimes it would be desirable to include some debugging output only
under certain conditions, but the end of the transfer is too late to
apply some rules.

Here we take the approach of making a converter ("when") that takes a
condition among an arbitrary list, and decides whether or not to let
the input sample pass through or not based on the condition. This
allows for example to log debugging information only when an error
was encountered during the processing (sort of an extension of
dontlog-normal). The conditions are quite limited (stopping, error,
normal, toapplet, forwarded, processed) and can be negated. The
converter can also be chained to use more complex conditions.

A suggested example will be:

    # log "dbg={-}" when fine, or "dbg={... debug info ...}" on error:
    log-format "$HAPROXY_HTTP_LOG_FMT dbg={%[bs.debug_str,when(!normal)]}"

(cherry picked from commit b74fb1325e60a2573f1ed8a460129bc6c0c9e53f)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
doc/configuration.txt
src/sample.c