Support the combination of nginx variables and text value for annotation upstream-hash-by.
This commit is contained in:
parent
b18ea267a8
commit
c035a144f8
6 changed files with 95 additions and 22 deletions
|
|
@ -1,14 +1,21 @@
|
|||
local balancer_resty = require("balancer.resty")
|
||||
local resty_chash = require("resty.chash")
|
||||
local util = require("util")
|
||||
local ngx_log = ngx.log
|
||||
local ngx_ERR = ngx.ERR
|
||||
|
||||
local _M = balancer_resty:new({ factory = resty_chash, name = "chash" })
|
||||
|
||||
function _M.new(self, backend)
|
||||
local nodes = util.get_nodes(backend.endpoints)
|
||||
local complex_val, err = util.parse_complex_value(backend["upstreamHashByConfig"]["upstream-hash-by"])
|
||||
if err ~= nil then
|
||||
ngx_log(ngx_ERR, "could not parse the value of the upstream-hash-by: ", err)
|
||||
end
|
||||
|
||||
local o = {
|
||||
instance = self.factory:new(nodes),
|
||||
hash_by = backend["upstreamHashByConfig"]["upstream-hash-by"],
|
||||
hash_by = complex_val,
|
||||
traffic_shaping_policy = backend.trafficShapingPolicy,
|
||||
alternative_backends = backend.alternativeBackends,
|
||||
}
|
||||
|
|
@ -18,7 +25,7 @@ function _M.new(self, backend)
|
|||
end
|
||||
|
||||
function _M.balance(self)
|
||||
local key = util.lua_ngx_var(self.hash_by)
|
||||
local key = util.generate_var_value(self.hash_by)
|
||||
return self.instance:find(key)
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue