Skip to content

Commit

Permalink
Fix chashsubset backend with canary (#7235)
Browse files Browse the repository at this point in the history
* Fix chashsubset backend with canary

* use floor for buckets calculation to remove hot spot

* Remove testing code
  • Loading branch information
weiwu-sre authored Dec 30, 2021
1 parent a14edba commit e625c25
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
5 changes: 3 additions & 2 deletions rootfs/etc/nginx/lua/balancer/chashsubset.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ local function build_subset_map(backend)

local set_count = math.ceil(#endpoints/subset_size)
local node_count = set_count * subset_size

-- if we don't have enough endpoints, we reuse endpoints in the last set to
-- keep the same number on all of them.
local j = 1
Expand Down Expand Up @@ -61,7 +60,9 @@ function _M.new(self, backend)
instance = resty_chash:new(subset_map),
hash_by = complex_val,
subsets = subsets,
current_endpoints = backend.endpoints
current_endpoints = backend.endpoints,
traffic_shaping_policy = backend.trafficShapingPolicy,
alternative_backends = backend.alternativeBackends,
}
setmetatable(o, self)
self.__index = self
Expand Down
16 changes: 16 additions & 0 deletions rootfs/etc/nginx/lua/test/balancer/chashsubset_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,21 @@ describe("Balancer chash subset", function()
assert.are.equal(#endpoints, 3)
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)

0 comments on commit e625c25

Please sign in to comment.