From 2d6e5544e40beedc8f8db6f7559d7375a7c1d7d5 Mon Sep 17 00:00:00 2001 From: Murat Mukhtarov Date: Wed, 17 Apr 2019 14:40:53 +1000 Subject: [PATCH] [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. --- src/plugins/fuzzy_check.c | 44 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) 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, @@ -716,6 +724,24 @@ fuzzy_check_module_init (struct rspamd_config *cfg, struct module_ctx **ctx) 0, NULL, 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", @@ -998,6 +1024,24 @@ fuzzy_check_module_config (struct rspamd_config *cfg) fuzzy_module_ctx->retransmits = DEFAULT_RETRANSMITS; } + 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) { -- 2.39.5