]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Fix] Fix Lua 5.4 compatibility in clickhouse and elastic plugins
authorVsevolod Stakhov <vsevolod@rspamd.com>
Tue, 16 Dec 2025 11:25:29 +0000 (11:25 +0000)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Tue, 16 Dec 2025 11:34:32 +0000 (11:34 +0000)
- Merge nested settings tables (limits, retention) to preserve defaults
  when user provides partial configuration
- Use %d with math.floor() instead of %.0f for integer formatting

src/plugins/lua/clickhouse.lua
src/plugins/lua/elastic.lua

index 76586894f778db7b90a5598efbdef2fbae474a1f..04803e1be0c4fdb44def759f8843dc751471089a 100644 (file)
@@ -1042,9 +1042,9 @@ local function clickhouse_maybe_send_data_periodic(cfg, ev_base, now)
   if last_collection > 0 and settings.limits.max_interval > 0 then
     if now - last_collection > settings.limits.max_interval then
       need_collect = true
-      reason = string.format('limit of time since last collection has been reached: %.0f seconds passed ' ..
-          '(%.0f seconds trigger)',
-          (now - last_collection), settings.limits.max_interval)
+      reason = string.format('limit of time since last collection has been reached: %d seconds passed ' ..
+          '(%d seconds trigger)',
+          math.floor(now - last_collection), math.floor(settings.limits.max_interval))
     end
   end
 
@@ -1408,6 +1408,10 @@ if opts then
           rspamd_logger.errx(rspamd_config, 'custom rule has no required attributes: schema, first_row and get_row')
         end
       end
+    elseif k == 'limits' or k == 'retention' then
+      for sk, sv in pairs(v) do
+        settings[k][sk] = sv
+      end
     else
       settings[k] = lua_util.deepcopy(v)
     end
index b26fbd8e8451afe621364abbb42f0776277fffc6..6c59be685ab1f42a8be69860a46ae0bac9103800 100644 (file)
@@ -1518,9 +1518,24 @@ end
 
 local opts = rspamd_config:get_all_opt('elastic')
 
+-- Merge nested tables to preserve defaults when user provides partial config
+local function merge_settings(src, dst)
+  for k, v in pairs(src) do
+    if type(v) == 'table' and type(dst[k]) == 'table' then
+      merge_settings(v, dst[k])
+    else
+      dst[k] = v
+    end
+  end
+end
+
 if opts then
   for k, v in pairs(opts) do
-    settings[k] = v
+    if type(v) == 'table' and settings[k] and type(settings[k]) == 'table' then
+      merge_settings(v, settings[k])
+    else
+      settings[k] = v
+    end
   end
 
   if not settings['enabled'] then