Fix chashsubset backend with canary (#7235)
* Fix chashsubset backend with canary * use floor for buckets calculation to remove hot spot * Remove testing code
This commit is contained in:
parent
a14edba8d5
commit
e625c2507a
2 changed files with 19 additions and 2 deletions
|
@ -25,7 +25,6 @@ local function build_subset_map(backend)
|
||||||
|
|
||||||
local set_count = math.ceil(#endpoints/subset_size)
|
local set_count = math.ceil(#endpoints/subset_size)
|
||||||
local node_count = set_count * subset_size
|
local node_count = set_count * subset_size
|
||||||
|
|
||||||
-- if we don't have enough endpoints, we reuse endpoints in the last set to
|
-- if we don't have enough endpoints, we reuse endpoints in the last set to
|
||||||
-- keep the same number on all of them.
|
-- keep the same number on all of them.
|
||||||
local j = 1
|
local j = 1
|
||||||
|
@ -61,7 +60,9 @@ function _M.new(self, backend)
|
||||||
instance = resty_chash:new(subset_map),
|
instance = resty_chash:new(subset_map),
|
||||||
hash_by = complex_val,
|
hash_by = complex_val,
|
||||||
subsets = subsets,
|
subsets = subsets,
|
||||||
current_endpoints = backend.endpoints
|
current_endpoints = backend.endpoints,
|
||||||
|
traffic_shaping_policy = backend.trafficShapingPolicy,
|
||||||
|
alternative_backends = backend.alternativeBackends,
|
||||||
}
|
}
|
||||||
setmetatable(o, self)
|
setmetatable(o, self)
|
||||||
self.__index = self
|
self.__index = self
|
||||||
|
|
|
@ -86,5 +86,21 @@ describe("Balancer chash subset", function()
|
||||||
assert.are.equal(#endpoints, 3)
|
assert.are.equal(#endpoints, 3)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it("set alternative backends", function()
|
||||||
|
local backend = get_test_backend(7)
|
||||||
|
backend.trafficShapingPolicy = {
|
||||||
|
weight = 0,
|
||||||
|
header = "",
|
||||||
|
headerValue = "",
|
||||||
|
cookie = ""
|
||||||
|
}
|
||||||
|
backend.alternativeBackends = {
|
||||||
|
"my-dummy-canary-backend"
|
||||||
|
}
|
||||||
|
local instance = balancer_chashsubset:new(backend)
|
||||||
|
assert.not_equal(instance.traffic_shaping_policy, nil)
|
||||||
|
assert.not_equal(instance.alternative_backends, nil)
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
Loading…
Reference in a new issue