From b54d5fdc8d8693e8d31050bca5f66f8eab4760d0 Mon Sep 17 00:00:00 2001 From: Bryan Call Date: Thu, 19 Feb 2026 14:46:34 -0800 Subject: [PATCH 1/2] Fix: msdms log fields emit "-" instead of "-1" for unset milestones Add unmarshal_milestone_diff() which outputs a single "-" character when the marshalled value is negative (milestone was unset), instead of the literal string "-1". This makes log parsing cleaner -- parsers can distinguish between "0 ms" (a valid timing) and "not applicable" without checking for a magic integer value. The MSDMS container now uses this new unmarshal function instead of the generic unmarshal_int_to_str. --- include/proxy/logging/LogAccess.h | 1 + src/proxy/logging/LogAccess.cc | 35 +++++++++++++++++++++++++++++++ src/proxy/logging/LogField.cc | 2 +- 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/include/proxy/logging/LogAccess.h b/include/proxy/logging/LogAccess.h index 7cdf8ed48be..1d8d6974e24 100644 --- a/include/proxy/logging/LogAccess.h +++ b/include/proxy/logging/LogAccess.h @@ -316,6 +316,7 @@ class LogAccess static int unmarshal_itox(int64_t val, char *dest, int field_width = 0, char leading_char = ' '); static int unmarshal_int_to_str(char **buf, char *dest, int len); static int unmarshal_int_to_str_hex(char **buf, char *dest, int len); + static int unmarshal_milestone_diff(char **buf, char *dest, int len); static int unmarshal_str(char **buf, char *dest, int len, LogSlice *slice, LogEscapeType escape_type); static int unmarshal_ttmsf(char **buf, char *dest, int len); static int unmarshal_int_to_date_str(char **buf, char *dest, int len); diff --git a/src/proxy/logging/LogAccess.cc b/src/proxy/logging/LogAccess.cc index 908ec8c22ff..c5faa13d99e 100644 --- a/src/proxy/logging/LogAccess.cc +++ b/src/proxy/logging/LogAccess.cc @@ -626,6 +626,41 @@ LogAccess::unmarshal_int_to_str(char **buf, char *dest, int len) return -1; } +/*------------------------------------------------------------------------- + LogAccess::unmarshal_milestone_diff + + Unmarshal a milestone difference value. Returns "-" when the + marshalled value is negative (milestone was unset), otherwise + the decimal string representation. + -------------------------------------------------------------------------*/ + +int +LogAccess::unmarshal_milestone_diff(char **buf, char *dest, int len) +{ + ink_assert(buf != nullptr); + ink_assert(*buf != nullptr); + ink_assert(dest != nullptr); + + int64_t val = unmarshal_int(buf); + if (val < 0) { + if (len >= 1) { + dest[0] = '-'; + return 1; + } + DBG_UNMARSHAL_DEST_OVERRUN + return -1; + } + + char val_buf[128]; + int val_len = unmarshal_itoa(val, val_buf + 127); + if (val_len < len) { + memcpy(dest, val_buf + 128 - val_len, val_len); + return val_len; + } + DBG_UNMARSHAL_DEST_OVERRUN + return -1; +} + /*------------------------------------------------------------------------- LogAccess::unmarshal_int_to_str_hex diff --git a/src/proxy/logging/LogField.cc b/src/proxy/logging/LogField.cc index f7dcbbd067a..039aca32a74 100644 --- a/src/proxy/logging/LogField.cc +++ b/src/proxy/logging/LogField.cc @@ -388,7 +388,7 @@ LogField::LogField(const char *field, Container container) if (0 != rv) { Note("Invalid milestone range in LogField ctor: %s", m_name); } - m_unmarshal_func = &(LogAccess::unmarshal_int_to_str); + m_unmarshal_func = &(LogAccess::unmarshal_milestone_diff); m_type = LogField::sINT; break; } From 4181d0b1f9558bf74c37b11bb180a11774ee77fa Mon Sep 17 00:00:00 2001 From: Bryan Call Date: Thu, 19 Feb 2026 15:26:35 -0800 Subject: [PATCH 2/2] Address review: only map -1 sentinel to dash, not all negatives Copilot correctly noted that val < 0 would also catch reversed milestone pairs (end < start), hiding potentially useful debug info. Tighten to val == -1 which is the specific "missing" sentinel returned by difference_msec() when a milestone is unset. --- src/proxy/logging/LogAccess.cc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/proxy/logging/LogAccess.cc b/src/proxy/logging/LogAccess.cc index c5faa13d99e..3f5d6868564 100644 --- a/src/proxy/logging/LogAccess.cc +++ b/src/proxy/logging/LogAccess.cc @@ -630,8 +630,10 @@ LogAccess::unmarshal_int_to_str(char **buf, char *dest, int len) LogAccess::unmarshal_milestone_diff Unmarshal a milestone difference value. Returns "-" when the - marshalled value is negative (milestone was unset), otherwise - the decimal string representation. + marshalled value is -1 (the "missing" sentinel from difference_msec, + meaning one or both milestones were unset). Other negative values + (reversed milestone order) are preserved as numeric output for + debugging. -------------------------------------------------------------------------*/ int @@ -642,7 +644,7 @@ LogAccess::unmarshal_milestone_diff(char **buf, char *dest, int len) ink_assert(dest != nullptr); int64_t val = unmarshal_int(buf); - if (val < 0) { + if (val == -1) { if (len >= 1) { dest[0] = '-'; return 1;