Skip to content

Commit

Permalink
Merge pull request #26 from huangnauh/add_info
Browse files Browse the repository at this point in the history
get upstreams info
  • Loading branch information
yejingx authored Sep 6, 2017
2 parents b1d922c + ee6730e commit b36cf18
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/resty/checkups/api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,21 @@ local function gen_upstream(skey, upstream)
end


function _M.get_upstream(skey)
local ups, err
if skey then
ups, err = dyconfig.do_get_upstream(skey)
else
ups, err = dyconfig.do_get_upstreams()
end

if err then
return nil, err
end
return ups
end


function _M.update_upstream(skey, upstream)
if not upstream or not next(upstream) then
return false, "can not set empty upstream"
Expand Down
20 changes: 20 additions & 0 deletions lib/resty/checkups/dyconfig.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ local INFO = ngx.INFO

local str_format = string.format
local type = type
local pairs = pairs


local get_shm = subsystem.get_shm
Expand Down Expand Up @@ -166,6 +167,25 @@ function _M.do_get_upstream(skey)
end


function _M.do_get_upstreams()
local skeys = shd_config:get(base.SKEYS_KEY)
if not skeys then
return nil, "no skeys found from shm"
end
local upstreams = {}
skeys = cjson.decode(skeys)
for skey, _ in pairs(skeys) do
local shd_servers, err = shd_config:get(_gen_shd_key(skey))
log(INFO, "get ", skey, " from shm: ", shd_servers)
if shd_servers then
upstreams[skey] = cjson.decode(shd_servers)
elseif err then
log(WARN, "failed to get from shm: ", err)
end
end
return upstreams
end


function _M.do_update_upstream(skey, upstream)
local skeys = shd_config:get(base.SKEYS_KEY)
Expand Down

0 comments on commit b36cf18

Please sign in to comment.