aboutsummaryrefslogtreecommitdiffstats
path: root/lualib
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2018-12-05 14:41:01 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2018-12-05 14:41:01 +0000
commitd027dca0f2c45caa9d8a26e476d44f94a92f639e (patch)
treedf02e6750a87078cd60041374ad51b5d5f64fcf6 /lualib
parent8feff3e587c05658f5c9ccab3decb12208decc71 (diff)
downloadrspamd-d027dca0f2c45caa9d8a26e476d44f94a92f639e.tar.gz
rspamd-d027dca0f2c45caa9d8a26e476d44f94a92f639e.zip
[Feature] Query sentinel on master errors
Issue: #2665
Diffstat (limited to 'lualib')
-rw-r--r--lualib/lua_redis.lua18
1 files changed, 18 insertions, 0 deletions
diff --git a/lualib/lua_redis.lua b/lualib/lua_redis.lua
index 658e26242..a5879e130 100644
--- a/lualib/lua_redis.lua
+++ b/lualib/lua_redis.lua
@@ -35,6 +35,7 @@ local common_schema = ts.shape {
sentinels = (ts.string + ts.array_of(ts.string)):is_optional(),
sentinel_watch_time = (ts.number + ts.string / lutil.parse_time_interval):is_optional(),
sentinel_masters_pattern = ts.string:is_optional(),
+ sentinel_master_maxerrors = (ts.number + ts.string / tonumber):is_optional(),
}
local config_schema =
@@ -181,6 +182,19 @@ local function redis_query_sentinel(ev_base, params, initialised)
addr:get_addr():to_string(true), write_servers_str)
params.write_servers = write_upstreams
params.write_servers_str = write_servers_str
+
+ local queried = false
+
+ local function monitor_failures(up, _, count)
+ if count > params.sentinel_master_maxerrors and not queried then
+ logger.infox(rspamd_config, 'sentinel: master with address %s, caused %s failures, try to query sentinel',
+ up:get_addr():to_string(true), count)
+ queried = true -- Avoid multiple checks caused by this monitor
+ redis_query_sentinel(ev_base, params, true)
+ end
+ end
+
+ write_upstreams:add_watcher('failure', monitor_failures)
end
end
@@ -212,6 +226,10 @@ local function add_redis_sentinels(params)
params.sentinel_watch_time = 60 -- Each minute
end
+ if not params.sentinel_master_maxerrors then
+ params.sentinel_master_maxerrors = 2 -- Maximum number of errors before rechecking
+ end
+
rspamd_config:add_on_load(function(cfg, ev_base, worker)
local initialised = false
if worker:is_scanner() then