Skip to content

Commit

Permalink
fix: do not get peer status if heartbeat not enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
yejingx committed Apr 13, 2017
1 parent 915a910 commit 5abe3fa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
11 changes: 5 additions & 6 deletions lib/resty/checkups/base.lua
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ _M.cluster_status = cluster_status
_M.is_tab = function(t) return type(t) == "table" end
_M.is_str = function(t) return type(t) == "string" end
_M.is_num = function(t) return type(t) == "number" end
_M.is_nul = function(t) return t == nil or t == ngx.null end


local function _gen_key(skey, srv)
Expand Down Expand Up @@ -218,8 +219,8 @@ end

function _M.get_peer_status(skey, srv)
local peer_key = PEER_STATUS_PREFIX .. _gen_key(skey, srv)
local peer_status = cjson.decode(state:get(peer_key))
return peer_status
local peer_status = state:get(peer_key)
return not _M.is_nul(peer_status) and cjson.decode(peer_status) or nil
end


Expand All @@ -236,10 +237,8 @@ function _M.get_upstream_status(skey)
ups_status[level] = {}
if servers and type(servers) == "table" and #servers > 0 then
for _, srv in ipairs(servers) do
local peer_key = _gen_key(skey, srv)
local peer_status = cjson.decode(state:get(PEER_STATUS_PREFIX ..
peer_key)) or {}
peer_status.server = peer_key
local peer_status = _M.get_peer_status(skey, srv) or {}
peer_status.server = _gen_key(skey, srv)
peer_status["weight"] = srv.weight
peer_status["max_fails"] = srv.max_fails
peer_status["fail_timeout"] = srv.fail_timeout
Expand Down
5 changes: 5 additions & 0 deletions lib/resty/checkups/try.lua
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ local function prepare_callbacks(skey, opts)
return false
end

if ups.enable == false or (ups.enable == nil
and base.upstream.default_heartbeat_enable == false) then
return base.get_srv_status(skey, srv) == base.STATUS_OK
end

local peer_status = base.get_peer_status(skey, srv)
if (not peer_status or peer_status.status ~= base.STATUS_ERR)
and base.get_srv_status(skey, srv) == base.STATUS_OK then
Expand Down

0 comments on commit 5abe3fa

Please sign in to comment.