Merge pull request #3415 from Shopify/fix-canary-bug
bugfix: set canary attributes when initializing balancer
This commit is contained in:
commit
9d4060c463
5 changed files with 28 additions and 4 deletions
|
@ -133,9 +133,25 @@ local function route_to_alternative_balancer(balancer)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- TODO: support traffic shaping for n > 1 alternative backends
|
-- TODO: support traffic shaping for n > 1 alternative backends
|
||||||
local alternative_balancer = balancers[balancer.alternative_backends[1]]
|
local backend_name = balancer.alternative_backends[1]
|
||||||
|
if not backend_name then
|
||||||
|
ngx.log(ngx.ERR, "empty alternative backend")
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
local clean_target_header = util.replace_special_char(alternative_balancer.traffic_shaping_policy.header, "-", "_")
|
local alternative_balancer = balancers[backend_name]
|
||||||
|
if not alternative_balancer then
|
||||||
|
ngx.log(ngx.ERR, "no alternative balancer for backend: " .. tostring(backend_name))
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
local traffic_shaping_policy = alternative_balancer.traffic_shaping_policy
|
||||||
|
if not traffic_shaping_policy then
|
||||||
|
ngx.log(ngx.ERR, "traffic shaping policy is not set for balanacer of backend: " .. tostring(backend_name))
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
local clean_target_header = util.replace_special_char(traffic_shaping_policy.header, "-", "_")
|
||||||
|
|
||||||
local header = ngx.var["http_" .. clean_target_header]
|
local header = ngx.var["http_" .. clean_target_header]
|
||||||
if header then
|
if header then
|
||||||
|
@ -146,7 +162,7 @@ local function route_to_alternative_balancer(balancer)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local clean_target_cookie = util.replace_special_char(alternative_balancer.traffic_shaping_policy.cookie, "-", "_")
|
local clean_target_cookie = util.replace_special_char(traffic_shaping_policy.cookie, "-", "_")
|
||||||
|
|
||||||
local cookie = ngx.var["cookie_" .. clean_target_cookie]
|
local cookie = ngx.var["cookie_" .. clean_target_cookie]
|
||||||
if cookie then
|
if cookie then
|
||||||
|
@ -157,7 +173,7 @@ local function route_to_alternative_balancer(balancer)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if math.random(100) <= alternative_balancer.traffic_shaping_policy.weight then
|
if math.random(100) <= traffic_shaping_policy.weight then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,8 @@ function _M.new(self, backend)
|
||||||
local o = {
|
local o = {
|
||||||
instance = self.factory:new(nodes),
|
instance = self.factory:new(nodes),
|
||||||
hash_by = backend["upstream-hash-by"],
|
hash_by = backend["upstream-hash-by"],
|
||||||
|
traffic_shaping_policy = backend.trafficShapingPolicy,
|
||||||
|
alternative_backends = backend.alternativeBackends,
|
||||||
}
|
}
|
||||||
setmetatable(o, self)
|
setmetatable(o, self)
|
||||||
self.__index = self
|
self.__index = self
|
||||||
|
|
|
@ -120,6 +120,8 @@ end
|
||||||
function _M.new(self, backend)
|
function _M.new(self, backend)
|
||||||
local o = {
|
local o = {
|
||||||
peers = backend.endpoints,
|
peers = backend.endpoints,
|
||||||
|
traffic_shaping_policy = backend.trafficShapingPolicy,
|
||||||
|
alternative_backends = backend.alternativeBackends,
|
||||||
}
|
}
|
||||||
setmetatable(o, self)
|
setmetatable(o, self)
|
||||||
self.__index = self
|
self.__index = self
|
||||||
|
|
|
@ -8,6 +8,8 @@ function _M.new(self, backend)
|
||||||
local nodes = util.get_nodes(backend.endpoints)
|
local nodes = util.get_nodes(backend.endpoints)
|
||||||
local o = {
|
local o = {
|
||||||
instance = self.factory:new(nodes),
|
instance = self.factory:new(nodes),
|
||||||
|
traffic_shaping_policy = backend.trafficShapingPolicy,
|
||||||
|
alternative_backends = backend.alternativeBackends,
|
||||||
}
|
}
|
||||||
setmetatable(o, self)
|
setmetatable(o, self)
|
||||||
self.__index = self
|
self.__index = self
|
||||||
|
|
|
@ -18,6 +18,8 @@ function _M.new(self, backend)
|
||||||
cookie_expires = backend["sessionAffinityConfig"]["cookieSessionAffinity"]["expires"],
|
cookie_expires = backend["sessionAffinityConfig"]["cookieSessionAffinity"]["expires"],
|
||||||
cookie_max_age = backend["sessionAffinityConfig"]["cookieSessionAffinity"]["maxage"],
|
cookie_max_age = backend["sessionAffinityConfig"]["cookieSessionAffinity"]["maxage"],
|
||||||
digest_func = digest_func,
|
digest_func = digest_func,
|
||||||
|
traffic_shaping_policy = backend.trafficShapingPolicy,
|
||||||
|
alternative_backends = backend.alternativeBackends,
|
||||||
}
|
}
|
||||||
setmetatable(o, self)
|
setmetatable(o, self)
|
||||||
self.__index = self
|
self.__index = self
|
||||||
|
|
Loading…
Reference in a new issue