upstream-hash-by annotation support for dynamic configuraton mode

This commit is contained in:
Elvin Efendi 2018-04-19 23:02:22 -04:00
parent 0813b38314
commit 2ce9196ecf
7 changed files with 174 additions and 3 deletions

View file

@ -6,6 +6,7 @@ local lrucache = require("resty.lrucache")
local resty_lock = require("resty.lock")
local ewma = require("balancer.ewma")
local sticky = require("sticky")
local chash = require("balancer.chash")
-- measured in seconds
-- for an Nginx worker to pick up the new list of upstream peers
@ -62,6 +63,11 @@ local function balance()
lb_alg = "round_robin"
end
if backend["upstream-hash-by"] then
local endpoint = chash.balance(backend)
return endpoint.address, endpoint.port
end
if lb_alg == "ip_hash" then
-- TODO(elvinefendi) implement me
return backend.endpoints[0].address, backend.endpoints[0].port
@ -111,6 +117,11 @@ local function sync_backend(backend)
ngx.shared.balancer_ewma_last_touched_at:flush_all()
end
-- reset chash for this backend
if backend["upstream-hash-by"] then
chash.reinit(backend)
end
ngx.log(ngx.INFO, "syncronization completed for: " .. backend.name)
end