]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: config: report when "monitor fail" rules are misplaced
authorWilly Tarreau <w@1wt.eu>
Fri, 1 Dec 2017 17:25:08 +0000 (18:25 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 1 Dec 2017 17:25:08 +0000 (18:25 +0100)
"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
src/cfgparse.c

index 36a904e258a729afd07a3341bc4038bcf8ff0c94..208c11e51f5f8999bface7cae7f40a7979d5eec0 100644 (file)
@@ -5255,12 +5255,14 @@ monitor-uri <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
index b3202a68cf3d2541490cc908bb421cb3b04e61c8..8486f0faa1a1b3e976c2701ae38bcd6fd4b5b3f6 100644 (file)
@@ -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 @@ stats_error_parsing:
                                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);