Re: suppress reqrep / use_backend warning

2014-04-13 Thread Cyril Bonté

Hi Patrick,

Le 08/04/2014 23:04, Patrick Hemmer a écrit :

Would it be possible to get an option to suppress the warning when a
reqrep rule is placed after a use_backend rule?
[WARNING] 097/205824 (4777) : parsing
[/var/run/hapi/haproxy/haproxy.cfg:1443] : a 'reqrep' rule placed after
a 'use_backend' rule will still be processed before.

I prefer keeping my related rules grouped together, and so this message
pops up every time haproxy is (re)started. Currently it logs out 264
lines each start (I have a lot of rules), and is thus fairly annoying. I
am well aware of what the message means and my configuration is not
affected by it.



Do you want to ignore every warnings or only some warnings ?

For the first case you can use the global keyword quiet (or its 
command line equivalent -q).


For the second one, there is nothing available yet, but I was thinking 
of something like annotations in configuration comments.

For example :
- @ignore-warnings to ignore the warnings of the current line
- @BEGIN ignore-warnings to start a block of lines where warnings will 
be ignored

- @END ignore-warnings to stop ignoring warnings.

frontend test :
  mode http
  reqrep ^([^\ :]*)\ /static/(.*) \1\ /\2
  block if TRUE   # @ignore-warnings
  block if FALSE  # @ignore-warnings
  block if TRUE
  block if TRUE
  block if TRUE
  # @BEGIN ignore-warnings
  block if TRUE
  block if TRUE
  block if TRUE
  block if TRUE
  block if TRUE
  # @END ignore-warnings
  block if TRUE
  block if TRUE
  block if TRUE

Please find a quick and dirty patch to illustrate. Is this something 
that could be useful ?



--
Cyril Bonté
diff --git a/include/types/global.h b/include/types/global.h
index 669ec23..cb18593 100644
--- a/include/types/global.h
+++ b/include/types/global.h
@@ -64,6 +64,11 @@
 #define ACCESS_LVL_OPER 2
 #define ACCESS_LVL_ADMIN3
 
+/* Annotations */
+#define AN_IGNORE_WARN_LO   0x01	/* Annotation to ignore warnings on the current line */
+#define AN_IGNORE_WARN_BLCK 0x02	/* Annotation to ignore warnings on the current block */
+#define AN_IGNORE_WARN_MASK 0x03
+
 /* SSL server verify mode */
 enum {
 	SSL_SERVER_VERIFY_NONE = 0,
@@ -151,6 +156,7 @@ struct global {
 	struct proxy *stats_fe; /* the frontend holding the stats settings */
 };
 
+extern int annotations;
 extern struct global global;
 extern int  pid;/* current process id */
 extern int  relative_pid;   /* process id starting at 1 */
diff --git a/src/cfgparse.c b/src/cfgparse.c
index 344bde1..d7c4d37 100644
--- a/src/cfgparse.c
+++ b/src/cfgparse.c
@@ -5557,6 +5557,8 @@ int readcfgfile(const char *file)
 		args[arg] = line;
 
 		while (*line  arg  MAX_LINE_ARGS) {
+			annotations = ~AN_IGNORE_WARN_LO;
+
 			/* first, we'll replace \\, \space, \#, \r, \n, \t, \xXX with their
 			 * C equivalent value. Other combinations left unchanged (eg: \1).
 			 */
@@ -5600,6 +5602,22 @@ int readcfgfile(const char *file)
 line++;
 			}
 			else if (*line == '#' || *line == '\n' || *line == '\r') {
+char *aline = line;
+while (*aline) {
+	if (*aline == '@') {
+		aline++;
+		if (strncmp(aline, ignore-warnings, strlen(ignore-warnings)) == 0) {
+			annotations |= AN_IGNORE_WARN_LO;
+		}
+		else if (strncmp(aline, BEGIN ignore-warnings, strlen(BEGIN ignore-warnings)) == 0) {
+			annotations |= AN_IGNORE_WARN_BLCK;
+		}
+		else if (strncmp(aline, END ignore-warnings, strlen(END ignore-warnings)) == 0) {
+			annotations = ~AN_IGNORE_WARN_BLCK;
+		}
+	}
+	aline++;
+}
 /* end of string, end of loop */
 *line = 0;
 break;
@@ -5685,6 +5703,7 @@ int readcfgfile(const char *file)
 		if (err_code  ERR_ABORT)
 			break;
 	}
+	annotations = 0;
 	cursection = NULL;
 	fclose(f);
 	return err_code;
diff --git a/src/haproxy.c b/src/haproxy.c
index fb8c8a1..cbc4888 100644
--- a/src/haproxy.c
+++ b/src/haproxy.c
@@ -118,6 +118,8 @@ static struct list cfg_cfgfiles = LIST_HEAD_INIT(cfg_cfgfiles);
 int  pid;			/* current process id */
 int  relative_pid = 1;		/* process id starting at 1 */
 
+int annotations = 0;		/* Configuration annotations */
+
 /* global options */
 struct global global = {
 	.nbproc = 1,
diff --git a/src/log.c b/src/log.c
index 176a725..71326f8 100644
--- a/src/log.c
+++ b/src/log.c
@@ -571,7 +571,7 @@ void Warning(const char *fmt, ...)
 	va_list argp;
 	struct tm tm;
 
-	if (!(global.mode  MODE_QUIET) || (global.mode  MODE_VERBOSE)) {
+	if (!(global.mode  MODE_QUIET || annotations  AN_IGNORE_WARN_MASK) || (global.mode  MODE_VERBOSE)) {
 		va_start(argp, fmt);
 
 		get_localtime(date.tv_sec, tm);


Re: suppress reqrep / use_backend warning

2014-04-13 Thread Patrick Hemmer


*From: *Cyril Bonté cyril.bo...@free.fr
*Sent: * 2014-04-13 11:15:26 E
*To: *Patrick Hemmer hapr...@stormcloud9.net
*CC: *haproxy@formilux.org
*Subject: *Re: suppress reqrep / use_backend warning

 Hi Patrick,

 Le 08/04/2014 23:04, Patrick Hemmer a écrit :
 Would it be possible to get an option to suppress the warning when a
 reqrep rule is placed after a use_backend rule?
 [WARNING] 097/205824 (4777) : parsing
 [/var/run/hapi/haproxy/haproxy.cfg:1443] : a 'reqrep' rule placed after
 a 'use_backend' rule will still be processed before.

 I prefer keeping my related rules grouped together, and so this message
 pops up every time haproxy is (re)started. Currently it logs out 264
 lines each start (I have a lot of rules), and is thus fairly annoying. I
 am well aware of what the message means and my configuration is not
 affected by it.


 Do you want to ignore every warnings or only some warnings ?
I would think ignoring only some warnings would be preferable. Ignoring
all warnings might lead to people disabling them all, and then when a
new warning comes up that hasn't been seen before, it'll be missed.


 For the first case you can use the global keyword quiet (or its
 command line equivalent -q).
Ah, didn't know `quiet` would suppress warnings as well. This might be
acceptable.


 For the second one, there is nothing available yet, but I was thinking
 of something like annotations in configuration comments.
 For example :
 - @ignore-warnings to ignore the warnings of the current line
 - @BEGIN ignore-warnings to start a block of lines where warnings will
 be ignored
 - @END ignore-warnings to stop ignoring warnings.

 frontend test :
   mode http
   reqrep ^([^\ :]*)\ /static/(.*) \1\ /\2
   block if TRUE   # @ignore-warnings
   block if FALSE  # @ignore-warnings
   block if TRUE
   block if TRUE
   block if TRUE
   # @BEGIN ignore-warnings
   block if TRUE
   block if TRUE
   block if TRUE
   block if TRUE
   block if TRUE
   # @END ignore-warnings
   block if TRUE
   block if TRUE
   block if TRUE

 Please find a quick and dirty patch to illustrate. Is this something
 that could be useful ?
Hadn't really thought about the best way to solve it until now. I like
the per-line suppression more than the @BEGIN/@END one. The only other
way I can think of doing this is by having a config directive such as:
ignore-warnings reqrep_use_backend
Which would suppress all occurrences of that specific warning. But then
the warning message itself would need some sort of identifier on it so
we knew what argument to pass to 'ignore-warnings'

I'll play with the patch tomorrow, see how manageable it is.

But really, this is a trivial matter. I'd be OK with whatever is decided.


-Patrick


suppress reqrep / use_backend warning

2014-04-08 Thread Patrick Hemmer
Would it be possible to get an option to suppress the warning when a
reqrep rule is placed after a use_backend rule?
[WARNING] 097/205824 (4777) : parsing
[/var/run/hapi/haproxy/haproxy.cfg:1443] : a 'reqrep' rule placed after
a 'use_backend' rule will still be processed before.

I prefer keeping my related rules grouped together, and so this message
pops up every time haproxy is (re)started. Currently it logs out 264
lines each start (I have a lot of rules), and is thus fairly annoying. I
am well aware of what the message means and my configuration is not
affected by it.

-Patrick