From 13ea9586dae5ae002c020eee62e95a0ecba65a37 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Mon, 7 May 2018 15:37:58 +0100 Subject: [PATCH] [Fix] Use better sharding for ip_score Updating: true --- src/plugins/lua/ip_score.lua | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/plugins/lua/ip_score.lua b/src/plugins/lua/ip_score.lua index 083556066..d861b4806 100644 --- a/src/plugins/lua/ip_score.lua +++ b/src/plugins/lua/ip_score.lua @@ -53,22 +53,28 @@ local options = { servers = '', -- list of servers lower_bound = 10, -- minimum number of messages to be scored metric = 'default', + old_shard = false, min_score = nil, max_score = nil, score_divisor = 1, } local function ip_score_hash_key(asn, country, ipnet, ip) - -- We use the most common attribute as hashing key - if country then - return country - elseif asn then - return asn - elseif ipnet then - return ipnet - else - return ip:to_string() + if options.old_shard then + if country then + return country + elseif asn then + return asn + elseif ipnet then + return ipnet + else + return ip:to_string() + end end + + -- Better sharding + return string.format('%s:%s:%s:%s', asn, country, ipnet, + ip:to_string()) end local function ip_score_get_task_vars(task) -- 2.39.5