MINOR: sample: allow custom date format in error-log-format

Sample fetches %[accept_date] and %[request_date] with converters can be used
in error-log-format string. But in the most error cases they fetches nothing,
as error logs are produced on SSL handshake issues or when invalid PROXY
protocol header is used. Stream object is never allocated in such cases and
smp_fetch_accept_date() just simply returns 0.

There is a need to have a custom date format (ISO8601) also in the error logs,
along with normal logs. When sess_build_logline_orig() builds log line it
always copies the accept date to strm_logs structure. When stream is absent,
accept date is copied from the session object.

So, if the steam object wasn't allocated, let's use the session date info in
smp_fetch_accept_date(). This allows then, in sample_process(), to apply to the
fetched date different converters and formats.

This fixes the issue #2884.
This commit is contained in:
Valentine Krasnobaeva 2025-03-04 16:35:05 +01:00 committed by William Lallemand
parent 335ef3264b
commit b46b81949f

View File

@ -499,18 +499,26 @@ smp_fetch_accept_date(const struct arg *args, struct sample *smp, const char *kw
struct strm_logs *logs;
struct timeval tv;
if (!smp->strm)
if (smp->strm) {
logs = &smp->strm->logs;
if (kw[0] == 'r') { /* request_date */
tv_ms_add(&tv, &logs->accept_date, logs->t_idle >= 0 ? logs->t_idle + logs->t_handshake : 0);
} else { /* accept_date */
tv.tv_sec = logs->accept_date.tv_sec;
tv.tv_usec = logs->accept_date.tv_usec;
}
/* case of error-log-format */
} else if (smp->sess) {
if (kw[0] == 'r') { /* request_date */
tv_ms_add(&tv, &smp->sess->accept_date, smp->sess->t_idle >= 0 ? smp->sess->t_idle + smp->sess->t_handshake : 0);
} else { /* accept_date */
tv.tv_sec = smp->sess->accept_date.tv_sec;
tv.tv_usec = smp->sess->accept_date.tv_usec;
}
} else
return 0;
logs = &smp->strm->logs;
if (kw[0] == 'r') { /* request_date */
tv_ms_add(&tv, &logs->accept_date, logs->t_idle >= 0 ? logs->t_idle + logs->t_handshake : 0);
} else { /* accept_date */
tv.tv_sec = logs->accept_date.tv_sec;
tv.tv_usec = logs->accept_date.tv_usec;
}
smp->data.u.sint = tv.tv_sec;
/* report in milliseconds */