diff --git a/rootfs/etc/nginx/lua/balancer.lua b/rootfs/etc/nginx/lua/balancer.lua index 4487dad16..beabb418a 100644 --- a/rootfs/etc/nginx/lua/balancer.lua +++ b/rootfs/etc/nginx/lua/balancer.lua @@ -49,6 +49,9 @@ local function sync_backend(backend) return end + -- every implementation is the metatable of its instances (see .new(...) functions) + -- here we check if `balancer` is the instance of `implementation` + -- if it is not then we deduce LB algorithm has changed for the backend if getmetatable(balancer) ~= implementation then ngx.log(ngx.INFO, string.format("LB algorithm changed from %s to %s, resetting the instance", balancer.name, implementation.name)) @@ -113,8 +116,9 @@ function _M.balance() end local host, port = balancer:balance() - if not host then - ngx.log(ngx.WARN, "no host returned, balancer: " .. balancer.name) + if not (host and port) then + ngx.log(ngx.WARN, + string.format("host or port is missing, balancer: %s, host: %s, port: %s", balancer.name, host, port)) return end @@ -132,6 +136,10 @@ function _M.log() return end + if not balancer.after_balance then + return + end + balancer:after_balance() end diff --git a/rootfs/etc/nginx/lua/balancer/resty.lua b/rootfs/etc/nginx/lua/balancer/resty.lua index 356c19a66..457300ed5 100644 --- a/rootfs/etc/nginx/lua/balancer/resty.lua +++ b/rootfs/etc/nginx/lua/balancer/resty.lua @@ -19,7 +19,4 @@ function _M.sync(self, backend) self.instance:reinit(nodes) end -function _M.after_balance(_) -end - return _M