]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Fuzzy upstream error threshold config 2854/head
authorMurat Mukhtarov <mmukhtarov@zendesk.com>
Wed, 17 Apr 2019 04:40:53 +0000 (14:40 +1000)
committerMurat Mukhtarov <mmukhtarov@zendesk.com>
Wed, 17 Apr 2019 04:57:49 +0000 (14:57 +1000)
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

index a0e4df0123f7fe9e4869d5f3db03a2b924f6e36d..311bd39453500cb7e615b72e65d73a9677f41b25 100644 (file)
@@ -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) {