aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
authorMurat Mukhtarov <mmukhtarov@zendesk.com>2019-04-17 14:40:53 +1000
committerMurat Mukhtarov <mmukhtarov@zendesk.com>2019-04-17 14:57:49 +1000
commit2d6e5544e40beedc8f8db6f7559d7375a7c1d7d5 (patch)
treeb5457140e812c931760055c7dbd1983f9efe3625 /src/plugins
parentdbcc1c94520c55afcaa4a623a894c8e68c5cbb61 (diff)
downloadrspamd-2d6e5544e40beedc8f8db6f7559d7375a7c1d7d5.tar.gz
rspamd-2d6e5544e40beedc8f8db6f7559d7375a7c1d7d5.zip
[Minor] Fuzzy upstream error threshold config
It would be nice to be able to configure `max_errors` and `revive_time` for fuzzy check module for low traffic systems. When traffic volume is relatively low an error rate builds at very slow rate and it would take a while to reach default 40% threshold. At the same time waiting for 60s sometimes could be unreasonable for dynamic environments to re-resolve rspamd fuzzy storage.
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/fuzzy_check.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/plugins/fuzzy_check.c b/src/plugins/fuzzy_check.c
index a0e4df012..311bd3945 100644
--- a/src/plugins/fuzzy_check.c
+++ b/src/plugins/fuzzy_check.c
@@ -52,6 +52,8 @@
#define DEFAULT_IO_TIMEOUT 500
#define DEFAULT_RETRANSMITS 3
+#define DEFAULT_MAX_ERRORS 4
+#define DEFAULT_REVIVE_TIME 60
#define DEFAULT_PORT 11335
#define RSPAMD_FUZZY_PLUGIN_VERSION RSPAMD_FUZZY_VERSION
@@ -98,6 +100,8 @@ struct fuzzy_ctx {
struct rspamd_keypair_cache *keypairs_cache;
guint32 io_timeout;
guint32 retransmits;
+ guint max_errors;
+ gdouble revive_time;
gint check_mime_part_ref; /* Lua callback */
gint process_rule_ref; /* Lua callback */
gint cleanup_rules_ref;
@@ -461,6 +465,10 @@ fuzzy_parse_rule (struct rspamd_config *cfg, const ucl_object_t *obj,
if ((value = ucl_object_lookup (obj, "servers")) != NULL) {
rule->servers = rspamd_upstreams_create (cfg->ups_ctx);
+ /* pass max_error and revive_time configuration in upstream for fuzzy storage
+ * it allows to configure error_rate threshold and upstream dead timer
+ */
+ rspamd_upstreams_set_limits (rule->servers, (gdouble) fuzzy_module_ctx->revive_time, NAN, NAN, NAN, (guint) fuzzy_module_ctx->max_errors, NAN);
rspamd_mempool_add_destructor (cfg->cfg_pool,
(rspamd_mempool_destruct_t)rspamd_upstreams_destroy,
@@ -718,6 +726,24 @@ fuzzy_check_module_init (struct rspamd_config *cfg, struct module_ctx **ctx)
0);
rspamd_rcl_add_doc_by_path (cfg,
"fuzzy_check",
+ "Maximum number of upstream errors, affects error rate threshold",
+ "max_errors",
+ UCL_INT,
+ NULL,
+ 0,
+ NULL,
+ 0);
+ rspamd_rcl_add_doc_by_path (cfg,
+ "fuzzy_check",
+ "Time to lapse before re-resolve faulty upstream",
+ "revive_time",
+ UCL_FLOAT,
+ NULL,
+ 0,
+ NULL,
+ 0);
+ rspamd_rcl_add_doc_by_path (cfg,
+ "fuzzy_check",
"Whitelisted IPs map",
"whitelist",
UCL_STRING,
@@ -1000,6 +1026,24 @@ fuzzy_check_module_config (struct rspamd_config *cfg)
if ((value =
rspamd_config_get_module_opt (cfg, "fuzzy_check",
+ "max_errors")) != NULL) {
+ fuzzy_module_ctx->max_errors = ucl_obj_toint (value);
+ }
+ else {
+ fuzzy_module_ctx->max_errors = DEFAULT_MAX_ERRORS;
+ }
+
+ if ((value =
+ rspamd_config_get_module_opt (cfg, "fuzzy_check",
+ "revive_time")) != NULL) {
+ fuzzy_module_ctx->revive_time = ucl_obj_todouble (value);
+ }
+ else {
+ fuzzy_module_ctx->revive_time = DEFAULT_REVIVE_TIME;
+ }
+
+ if ((value =
+ rspamd_config_get_module_opt (cfg, "fuzzy_check",
"whitelist")) != NULL) {
rspamd_config_radix_from_ucl (cfg, value, "Fuzzy whitelist",
&fuzzy_module_ctx->whitelist, NULL);