From 721d8e028606b11d9f57febf3c7a9d16870a3e0a Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Fri, 1 Dec 2017 18:25:08 +0100 Subject: [PATCH] MINOR: config: report when "monitor fail" rules are misplaced "monitor-uri" may rely on "monitor fail" rules, which are processed very early, immediately after the HTTP request is parsed and before any http rulesets. It's not reported by the config parser when this ruleset is misplaces, causing some configurations not to work like users would expect. Let's just add the warning for a misplaced rule. --- doc/configuration.txt | 14 ++++++++------ src/cfgparse.c | 25 +++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/doc/configuration.txt b/doc/configuration.txt index 36a904e258..208c11e51f 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -5255,12 +5255,14 @@ monitor-uri version and all headers are ignored, but the request must at least be valid at the HTTP level. This keyword may only be used with an HTTP-mode frontend. - Monitor requests are processed very early. It is not possible to block nor - divert them using ACLs. They cannot be logged either, and it is the intended - purpose. They are only used to report HAProxy's health to an upper component, - nothing more. However, it is possible to add any number of conditions using - "monitor fail" and ACLs so that the result can be adjusted to whatever check - can be imagined (most often the number of available servers in a backend). + Monitor requests are processed very early, just after the request is parsed + and even before any "http-request" or "block" rulesets. The only rulesets + applied before are the tcp-request ones. They cannot be logged either, and it + is the intended purpose. They are only used to report HAProxy's health to an + upper component, nothing more. However, it is possible to add any number of + conditions using "monitor fail" and ACLs so that the result can be adjusted + to whatever check can be imagined (most often the number of available servers + in a backend). Example : # Use /haproxy_test to report haproxy's status diff --git a/src/cfgparse.c b/src/cfgparse.c index b3202a68cf..8486f0faa1 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -406,6 +406,19 @@ int warnif_rule_after_tcp_cont(struct proxy *proxy, const char *file, int line, return 0; } +/* Report a warning if a rule is placed after a 'monitor fail' rule. + * Return 1 if the warning has been emitted, otherwise 0. + */ +int warnif_rule_after_monitor(struct proxy *proxy, const char *file, int line, const char *arg) +{ + if (!LIST_ISEMPTY(&proxy->mon_fail_cond)) { + ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'monitor fail' rule will still be processed before.\n", + file, line, arg); + return 1; + } + return 0; +} + /* Report a warning if a rule is placed after a 'block' rule. * Return 1 if the warning has been emitted, otherwise 0. */ @@ -532,13 +545,20 @@ int warnif_misplaced_block(struct proxy *proxy, const char *file, int line, cons warnif_misplaced_http_req(proxy, file, line, arg); } -/* report a warning if a "tcp request content" rule is dangerously placed */ -int warnif_misplaced_tcp_cont(struct proxy *proxy, const char *file, int line, const char *arg) +/* report a warning if a block rule is dangerously placed */ +int warnif_misplaced_monitor(struct proxy *proxy, const char *file, int line, const char *arg) { return warnif_rule_after_block(proxy, file, line, arg) || warnif_misplaced_block(proxy, file, line, arg); } +/* report a warning if a "tcp request content" rule is dangerously placed */ +int warnif_misplaced_tcp_cont(struct proxy *proxy, const char *file, int line, const char *arg) +{ + return warnif_rule_after_monitor(proxy, file, line, arg) || + warnif_misplaced_monitor(proxy, file, line, arg); +} + /* report a warning if a "tcp request session" rule is dangerously placed */ int warnif_misplaced_tcp_sess(struct proxy *proxy, const char *file, int line, const char *arg) { @@ -5807,6 +5827,7 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm) goto out; } + err_code |= warnif_misplaced_monitor(curproxy, file, linenum, "monitor fail"); if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) { ha_alert("parsing [%s:%d] : error detected while parsing a '%s %s' condition : %s.\n", file, linenum, args[0], args[1], errmsg);