Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix chashsubset backend with canary #7235

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)