Merge pull request #4272 from ElvinEfendi/balancer-ewma-score-var

introduce ngx.var.balancer_ewma_score
This commit is contained in:
Kubernetes Prow Robot 2019-07-03 14:34:12 -07:00 committed by GitHub
commit 05e764be2c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 3 deletions

View file

@ -73,19 +73,21 @@ local function pick_and_score(self, peers, k)
lowest_score_index, lowest_score = i, new_score
end
end
return peers[lowest_score_index]
return peers[lowest_score_index], lowest_score
end
function _M.balance(self)
local peers = self.peers
local endpoint = peers[1]
local endpoint, score = peers[1], -1
if #peers > 1 then
local k = (#peers < PICK_SET_SIZE) and #peers or PICK_SET_SIZE
local peer_copy = util.deepcopy(peers)
endpoint = pick_and_score(self, peer_copy, k)
endpoint, score = pick_and_score(self, peer_copy, k)
end
ngx.var.balancer_ewma_score = score
-- TODO(elvinefendi) move this processing to _M.sync
return endpoint.address .. ":" .. endpoint.port
end

View file

@ -1090,6 +1090,7 @@ stream {
port_in_redirect {{ if $location.UsePortInRedirects }}on{{ else }}off{{ end }};
set $balancer_ewma_score -1;
set $proxy_upstream_name "{{ buildUpstreamName $location }}";
set $proxy_host $proxy_upstream_name;