mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2025-04-16 20:15:49 +00:00
MINOR: log: indicate it when some unreliable sample fetches are logged
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.
This commit is contained in:
parent
80aca90ad2
commit
434c57c95c
@ -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
|
* Variable name are preceded by % and composed by characters [a-zA-Z0-9]* : %varname
|
||||||
* You can set arguments using { } : %{many arguments}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
|
* Displays the message on stderr with the date and pid. Overrides the quiet
|
||||||
* mode during startup.
|
* mode during startup.
|
||||||
|
@ -6518,10 +6518,12 @@ out_uri_auth_compat:
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (curproxy->logformat_string)
|
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)
|
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 */
|
/* first, we will invert the servers list order */
|
||||||
newsrv = NULL;
|
newsrv = NULL;
|
||||||
|
15
src/log.c
15
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
|
* success. At the moment, sample converters are not yet supported but fetch arguments
|
||||||
* should work.
|
* 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];
|
char *cmd[2];
|
||||||
struct sample_expr *expr;
|
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);
|
node->arg = my_strndup(arg, arg_len);
|
||||||
parse_logformat_var_args(node->arg, node);
|
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 */
|
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 */
|
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 */
|
/* 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 */
|
/* Note, we may also need to set curpx->to_log with certain fetches */
|
||||||
if (expr->fetch->use & SMP_USE_HTTP_ANY)
|
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
|
* curproxy: the proxy affected
|
||||||
* list_format: the destination list
|
* list_format: the destination list
|
||||||
* options: LOG_OPT_* to force on every node
|
* 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 *sp, *str, *backfmt; /* start pointer for text parts */
|
||||||
char *arg = NULL; /* start pointer for args */
|
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);
|
parse_logformat_var(arg, arg_len, var, var_len, curproxy, list_format, &options);
|
||||||
break;
|
break;
|
||||||
case LF_STEXPR:
|
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;
|
break;
|
||||||
case LF_TEXT:
|
case LF_TEXT:
|
||||||
case LF_SEPARATOR:
|
case LF_SEPARATOR:
|
||||||
|
@ -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 = strdup(args[cur_arg]);
|
||||||
rule->arg.hdr_add.name_len = strlen(rule->arg.hdr_add.name);
|
rule->arg.hdr_add.name_len = strlen(rule->arg.hdr_add.name);
|
||||||
LIST_INIT(&rule->arg.hdr_add.fmt);
|
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;
|
cur_arg += 2;
|
||||||
} else if (strcmp(args[0], "redirect") == 0) {
|
} else if (strcmp(args[0], "redirect") == 0) {
|
||||||
struct redirect_rule *redir;
|
struct redirect_rule *redir;
|
||||||
|
Loading…
Reference in New Issue
Block a user