MINOR: sample: extend the "when" converter to support an ACL
authorWilly Tarreau <w@1wt.eu>
Mon, 18 Nov 2024 14:27:28 +0000 (15:27 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Thu, 9 Jan 2025 09:28:05 +0000 (10:28 +0100)
commitea911d1a52ca53cfc5d9cf0638b8df6ae6da3d1c
treeef5e0b2a8d2737e48391109dbddb6cf12b3bd91b
parent042e43570c069e25ef03c48700a0e529828845be
MINOR: sample: extend the "when" converter to support an ACL

Sometimes conditions to decide of an anomaly are not as easy to define
as just an error or a success. One example use case would be to monitor
the transfer time and fix a threshold.

An idea suggested by Tristan would be to make permit the "when"
converter to refer to a more variable or dynamic condition.

Here we make this possible by making "when" rely on a named ACL. The
ACL then needs to be specified in either the proxy or the defaults
section. Since it is evaluated inline, it may even refer to information
available at the end (at log time) such as the data transfer time. If
the ACL evalutates to true, the converter passes the data.

Example: log "dbg={-}" when fine, or "dbg={... debug info ...}" on slow
transfers:

  acl slow_xfer res.timer.data ge 10000   # more than 10s is slow
  log-format "$HAPROXY_HTTP_LOG_FMT                                \
              fsdbg={%[fs.debug_str,when(acl,slow_xfer)]}          \
              bsdbg={%[bs.debug_str,when(acl,slow_xfer)]}"

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