From ae0f8be0111b8ea128c6e35ee22451162eb98818 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Fri, 2 Jun 2023 08:35:50 +0200 Subject: [PATCH] MINOR: stats: protect against future stats fields omissions As seen in commits 33a4461fa ("BUG/MINOR: stats: Fix Lua's `get_stats` function") and a46b142e8 ("BUG/MINOR: Missing stat_field_names (since f21d17bb)") it seems frequent to omit to update stats_fields[] when adding a new ST_F_xxx entry. This breaks Lua's get_stats() and shows a "(null)" in the header of "show stat", but that one is not detectable to the naked eye anymore. Let's add a reminder above the enum declaration about this, and a small reg tests checking for the absence of "(null)". It was verified to fail before the last patch above. --- include/haproxy/stats-t.h | 4 +++- reg-tests/webstats/missing-stats-fields.vtc | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 reg-tests/webstats/missing-stats-fields.vtc diff --git a/include/haproxy/stats-t.h b/include/haproxy/stats-t.h index 07eaf6d50..ca2b78d03 100644 --- a/include/haproxy/stats-t.h +++ b/include/haproxy/stats-t.h @@ -355,7 +355,9 @@ enum info_field { /* Stats fields for CSV output. For any field added here, please add the text * representation in the stat_fields array. Please only append at the end, * before the ST_F_TOTAL_FIELDS entry, and never insert anything in the middle - * nor at the beginning. + * nor at the beginning.When adding an entry here, one must always add a + * corresponding one in stat_fields[] otherwise Lua's get_stats() will break, + * and "show stats" will show a null. */ enum stat_field { ST_F_PXNAME, diff --git a/reg-tests/webstats/missing-stats-fields.vtc b/reg-tests/webstats/missing-stats-fields.vtc new file mode 100644 index 000000000..c85855d5f --- /dev/null +++ b/reg-tests/webstats/missing-stats-fields.vtc @@ -0,0 +1,14 @@ +varnishtest "Verifies the absence of (null) in 'show stats' header" + +# This can happen if a new ST_F_xxx enum is added without updating +# stats_fields[]. + +feature ignore_unknown_macro + +haproxy h1 -conf { +} -start + +haproxy h1 -cli { + send "show stat" + expect !~ (null) +}