]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: log: indicate it when some unreliable sample fetches are logged
authorWilly Tarreau <w@1wt.eu>
Tue, 8 Jan 2013 00:10:24 +0000 (01:10 +0100)
committerWilly Tarreau <w@1wt.eu>
Wed, 3 Apr 2013 00:12:56 +0000 (02:12 +0200)
If a log-format involves some sample fetches that may not be present at
the logging instant, we can now report a warning.

Note that this is done both for log-format and for add-header and carefully
respects the original fetch keyword's capabilities.

include/proto/log.h
src/cfgparse.c
src/log.c
src/proto_http.c

index 08a9a1bf60c2fea88cac756034a59b12b547dc2e..86b41856252e8fb24761ba6f5b6075ae92f6ab0b 100644 (file)
@@ -70,7 +70,7 @@ void add_to_logformat_list(char *start, char *end, int type, struct list *list_f
  * Variable name are preceded by % and composed by characters [a-zA-Z0-9]* : %varname
  * You can set arguments using { } : %{many arguments}varname
  */
-void parse_logformat_string(const char *str, struct proxy *curproxy, struct list *list_format, int options);
+void parse_logformat_string(const char *str, struct proxy *curproxy, struct list *list_format, int options, int cap);
 /*
  * Displays the message on stderr with the date and pid. Overrides the quiet
  * mode during startup.
index a0178e6872242a45fcffd888acb6a9248c4dee41..6b27c24d84b067fb47a635bddd3fdd3e10f06430 100644 (file)
@@ -6518,10 +6518,12 @@ out_uri_auth_compat:
                }
 
                if (curproxy->logformat_string)
-                       parse_logformat_string(curproxy->logformat_string, curproxy, &curproxy->logformat, LOG_OPT_MANDATORY);
+                       parse_logformat_string(curproxy->logformat_string, curproxy, &curproxy->logformat, LOG_OPT_MANDATORY,
+                                              SMP_VAL_FE_LOG_END);
 
                if (curproxy->uniqueid_format_string)
-                       parse_logformat_string(curproxy->uniqueid_format_string, curproxy, &curproxy->format_unique_id, 0);
+                       parse_logformat_string(curproxy->uniqueid_format_string, curproxy, &curproxy->format_unique_id, 0,
+                                              (proxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR);
 
                /* first, we will invert the servers list order */
                newsrv = NULL;
index 45cc67e6c0a49ebb0657a52e2ca968f2f8b599c0..25dda04b068c51a9f4fa224d8f4153c87af6750f 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -309,7 +309,7 @@ void add_to_logformat_list(char *start, char *end, int type, struct list *list_f
  * success. At the moment, sample converters are not yet supported but fetch arguments
  * should work.
  */
-void add_sample_to_logformat_list(char *text, char *arg, int arg_len, struct proxy *curpx, struct list *list_format, int options)
+void add_sample_to_logformat_list(char *text, char *arg, int arg_len, struct proxy *curpx, struct list *list_format, int options, int cap)
 {
        char *cmd[2];
        struct sample_expr *expr;
@@ -335,12 +335,16 @@ void add_sample_to_logformat_list(char *text, char *arg, int arg_len, struct pro
                node->arg = my_strndup(arg, arg_len);
                parse_logformat_var_args(node->arg, node);
        }
-       if (expr->fetch->val & SMP_VAL_REQUEST)
+       if (expr->fetch->val & cap & SMP_VAL_REQUEST)
                node->options |= LOG_OPT_REQ_CAP; /* fetch method is request-compatible */
 
-       if (expr->fetch->val & SMP_VAL_RESPONSE)
+       if (expr->fetch->val & cap & SMP_VAL_RESPONSE)
                node->options |= LOG_OPT_RES_CAP; /* fetch method is response-compatible */
 
+       if (!(expr->fetch->val & cap))
+               Warning("log-format: sample fetch <%s> may not be reliably used %s because it needs '%s' which is not available here.\n",
+                       text, cap == SMP_VAL_FE_LOG_END ? "with 'log-format'" : "here", sample_src_names(expr->fetch->use));
+
        /* check if we need to allocate an hdr_idx struct for HTTP parsing */
        /* Note, we may also need to set curpx->to_log with certain fetches */
        if (expr->fetch->use & SMP_USE_HTTP_ANY)
@@ -363,8 +367,9 @@ void add_sample_to_logformat_list(char *text, char *arg, int arg_len, struct pro
  *  curproxy: the proxy affected
  *  list_format: the destination list
  *  options: LOG_OPT_* to force on every node
+ *  cap: all SMP_VAL_* flags supported by the consumer
  */
-void parse_logformat_string(const char *fmt, struct proxy *curproxy, struct list *list_format, int options)
+void parse_logformat_string(const char *fmt, struct proxy *curproxy, struct list *list_format, int options, int cap)
 {
        char *sp, *str, *backfmt; /* start pointer for text parts */
        char *arg = NULL; /* start pointer for args */
@@ -473,7 +478,7 @@ void parse_logformat_string(const char *fmt, struct proxy *curproxy, struct list
                                parse_logformat_var(arg, arg_len, var, var_len, curproxy, list_format, &options);
                                break;
                        case LF_STEXPR:
-                               add_sample_to_logformat_list(var, arg, arg_len, curproxy, list_format, options);
+                               add_sample_to_logformat_list(var, arg, arg_len, curproxy, list_format, options, cap);
                                break;
                        case LF_TEXT:
                        case LF_SEPARATOR:
index 36965573f17519c4715cd99156ae64db50066a46..56d8dd6ddab24710b6bbea2a2ff3402289943fcf 100644 (file)
@@ -8139,7 +8139,8 @@ struct http_req_rule *parse_http_req_cond(const char **args, const char *file, i
                rule->arg.hdr_add.name = strdup(args[cur_arg]);
                rule->arg.hdr_add.name_len = strlen(rule->arg.hdr_add.name);
                LIST_INIT(&rule->arg.hdr_add.fmt);
-               parse_logformat_string(args[cur_arg + 1], proxy, &rule->arg.hdr_add.fmt, 0);
+               parse_logformat_string(args[cur_arg + 1], proxy, &rule->arg.hdr_add.fmt, 0,
+                                      (proxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR);
                cur_arg += 2;
        } else if (strcmp(args[0], "redirect") == 0) {
                struct redirect_rule *redir;