Skip to content

Commit b36cf18

Browse files
authored
Merge pull request #26 from huangnauh/add_info
get upstreams info
2 parents b1d922c + ee6730e commit b36cf18

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

lib/resty/checkups/api.lua

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,21 @@ local function gen_upstream(skey, upstream)
268268
end
269269

270270

271+
function _M.get_upstream(skey)
272+
local ups, err
273+
if skey then
274+
ups, err = dyconfig.do_get_upstream(skey)
275+
else
276+
ups, err = dyconfig.do_get_upstreams()
277+
end
278+
279+
if err then
280+
return nil, err
281+
end
282+
return ups
283+
end
284+
285+
271286
function _M.update_upstream(skey, upstream)
272287
if not upstream or not next(upstream) then
273288
return false, "can not set empty upstream"

lib/resty/checkups/dyconfig.lua

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ local INFO = ngx.INFO
1414

1515
local str_format = string.format
1616
local type = type
17+
local pairs = pairs
1718

1819

1920
local get_shm = subsystem.get_shm
@@ -166,6 +167,25 @@ function _M.do_get_upstream(skey)
166167
end
167168

168169

170+
function _M.do_get_upstreams()
171+
local skeys = shd_config:get(base.SKEYS_KEY)
172+
if not skeys then
173+
return nil, "no skeys found from shm"
174+
end
175+
local upstreams = {}
176+
skeys = cjson.decode(skeys)
177+
for skey, _ in pairs(skeys) do
178+
local shd_servers, err = shd_config:get(_gen_shd_key(skey))
179+
log(INFO, "get ", skey, " from shm: ", shd_servers)
180+
if shd_servers then
181+
upstreams[skey] = cjson.decode(shd_servers)
182+
elseif err then
183+
log(WARN, "failed to get from shm: ", err)
184+
end
185+
end
186+
return upstreams
187+
end
188+
169189

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

0 commit comments

Comments
 (0)