/* Performs a postparsing check on logformat expression <expr> for a given <px>
* proxy. The function will behave differently depending on the proxy state
* (during parsing we will try to adapt proxy configuration to make it
- * compatible with logformat expression, but once the proxy is checked, we fail
- * as soon as we face incompatibilities)
+ * compatible with logformat expression, but once the proxy is checked, we
+ * cannot help anymore so all we can do is raise a diag warning and hope that
+ * the conditions will be met when executing the logformat expression)
*
- * If the proxy is a default section, then allow the postcheck to succeed:
- * the logformat expression may or may not work properly depending on the
- * actual proxy that effectively runs it during runtime, but we have to stay
- * permissive since we cannot assume it won't work.
+ * If the proxy is a default section, then allow the postcheck to succeed
+ * without errors nor warnings: the logformat expression may or may not work
+ * properly depending on the actual proxy that effectively runs it during
+ * runtime, but we have to stay permissive since we cannot assume it won't work.
*
- * It returns 1 on success and 0 on error, <err> will be set in case of error.
+ * It returns 1 on success (although diag_warnings may have been emitted) and 0
+ * on error (cannot be recovered from), <err> will be set in case of error.
*/
int lf_expr_postcheck(struct lf_expr *lf_expr, struct proxy *px, char **err)
{
struct logformat_node *lf;
int default_px = (px->cap & PR_CAP_DEF);
+ uint8_t http_mode = (px->mode == PR_MODE_HTTP || (px->options & PR_O_HTTP_UPG));
if (!(px->flags & PR_FL_CHECKED))
px->to_log |= LW_INIT;
struct sample_expr *expr = lf->expr;
uint8_t http_needed = !!(expr->fetch->use & SMP_USE_HTTP_ANY);
+ if (!default_px && !http_mode && http_needed)
+ ha_diag_warning("parsing [%s:%d]: sample fetch '%s' used from %s '%s' may not work as expected (item depends on HTTP proxy mode).\n",
+ lf_expr->conf.file, lf_expr->conf.line,
+ expr->fetch->kw,
+ proxy_type_str(px), px->id);
+
if ((px->flags & PR_FL_CHECKED)) {
- /* fail as soon as proxy properties are not compatible */
- if (http_needed && !px->http_needed) {
- memprintf(err, "sample fetch '%s' requires HTTP enabled proxy which is not available here",
- expr->fetch->kw);
- goto fail;
- }
+ if (http_needed && !px->http_needed)
+ ha_diag_warning("parsing [%s:%d]: sample fetch '%s' used from %s '%s' requires HTTP-specific proxy attributes, but the current proxy lacks them.\n",
+ lf_expr->conf.file, lf_expr->conf.line,
+ expr->fetch->kw,
+ proxy_type_str(px), px->id);
goto next_node;
}
/* check if we need to allocate an http_txn struct for HTTP parsing */
px->to_log |= LW_REQ;
}
else if (lf->type == LOG_FMT_ALIAS) {
- if (lf->alias->mode == PR_MODE_HTTP &&
- !default_px && px->mode != PR_MODE_HTTP) {
- memprintf(err, "format alias '%s' is reserved for HTTP mode",
- lf->alias->name);
- goto fail;
- }
+ if (!default_px && !http_mode &&
+ (lf->alias->mode == PR_MODE_HTTP ||
+ (lf->alias->lw & ((LW_REQ | LW_RESP)))))
+ ha_diag_warning("parsing [%s:%d]: format alias '%s' used from %s '%s' may not work as expected (item depends on HTTP proxy mode).\n",
+ lf_expr->conf.file, lf_expr->conf.line,
+ lf->alias->name,
+ proxy_type_str(px), px->id);
+
if (lf->alias->config_callback &&
!lf->alias->config_callback(lf, px)) {
- memprintf(err, "cannot configure format alias '%s' in this context",
+ memprintf(err, "error while configuring format alias '%s'",
lf->alias->name);
goto fail;
}
if (!lf_expr_postcheck_node_opt(lf_expr, lf, err))
goto fail;
}
- if (!default_px && (px->to_log & (LW_REQ | LW_RESP)) &&
- (px->mode != PR_MODE_HTTP && !(px->options & PR_O_HTTP_UPG))) {
- memprintf(err, "logformat expression not usable here (at least one item depends on HTTP mode)");
- goto fail;
- }
return 1;
fail: