Skip to content

get upstreams info #26

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

Merged
merged 1 commit into from
Sep 6, 2017
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
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