]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: log: Be able to use %ID alias at anytime of the stream's evaluation
authorChristopher Faulet <cfaulet@haproxy.com>
Mon, 23 Jun 2025 05:50:01 +0000 (07:50 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Tue, 24 Jun 2025 06:04:50 +0000 (08:04 +0200)
In a log-format string, using "%[unique-id]" or "%ID" should be equivalent.
However, for the first one, the unique ID is generated when the sample fetch
function is called. For the alias, it is not true. It that case, the
stream's unique ID is generated when the log message is emitted. Otherwise,
by default, the unique id is automatically generated at the end of the HTTP
request analysis.

So, if the alias "%ID" is use in a log-format string anywhere before the end
of the request analysis, the evaluation failed and the ID is considered as
empty. It is not consistent and in contradiction with the "%ID"
documentation.

To fix the issue, instead of evaluating the unique ID when the log message
is emitted, it is now performed on demand when "%ID" format is evaluated.

This patch should fix the issue #3016. It should be backported to all stable
versions. It relies on the following commit:

  * BUG/MINOR: stream: Avoid recursive evaluation for unique-id based on itself

src/log.c

index 053ef84508b8faf49351c352094176564acb084b..0227a2a8c64e35b4d830f9101f5a52e69e373dcc 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -5121,8 +5121,13 @@ int sess_build_logline_orig(struct session *sess, struct stream *s,
 
                        case LOG_FMT_UNIQUEID: // %ID
                                ret = NULL;
-                               if (s)
+                               if (s) {
+                                       /* if unique-id was not generated */
+                                       if (!isttest(s->unique_id) && !lf_expr_isempty(&sess->fe->format_unique_id)) {
+                                               stream_generate_unique_id(s, &sess->fe->format_unique_id);
+                                       }
                                        ret = lf_text_len(tmplog, s->unique_id.ptr, s->unique_id.len, maxsize - (tmplog - dst), ctx);
+                               }
                                else
                                        ret = lf_text_len(tmplog, NULL, 0, maxsize - (tmplog - dst), ctx);
                                if (ret == NULL)
@@ -5218,10 +5223,6 @@ void do_log(struct session *sess, struct stream *s, struct log_orig origin)
                        }
                        level = s->logs.level - 1;
                }
-               /* if unique-id was not generated */
-               if (!isttest(s->unique_id) && !lf_expr_isempty(&sess->fe->format_unique_id)) {
-                       stream_generate_unique_id(s, &sess->fe->format_unique_id);
-               }
        }
 
        if (level == -1) {
@@ -5282,11 +5283,6 @@ void strm_log(struct stream *s, struct log_orig origin)
                        level = LOG_ERR;
        }
 
-       /* if unique-id was not generated */
-       if (!isttest(s->unique_id) && !lf_expr_isempty(&sess->fe->format_unique_id)) {
-               stream_generate_unique_id(s, &sess->fe->format_unique_id);
-       }
-
        if (!lf_expr_isempty(&sess->fe->logformat_sd)) {
                sd_size = build_logline_orig(s, logline_rfc5424, global.max_syslog_len,
                                             &sess->fe->logformat_sd, origin);