-
Notifications
You must be signed in to change notification settings - Fork 2.6k
refactor: add healthcheck manager to decouple upstream #12426
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
Changes from all commits
72634ba
2e114fb
588ea22
275d179
6a169a3
40f5a79
40b0f36
4d3736a
be15b46
ef9ded6
f2485ff
d65748b
342674b
5dd2f5a
a0e0f3d
af9a26c
562105a
c3fbdf1
e551bbc
9f19c2c
45bba02
d962d76
8c3a884
c717105
b724093
6404912
413fdb2
a4ee844
31198de
0efb277
2588a40
c110c51
3de4f23
68796dc
3b94bd9
4621bed
47a04c6
cc363da
9288707
98a65e5
66fc383
9a56f59
f11e391
30f12a5
17b7397
15979b3
e725ad5
da27e15
4359182
1dca2f1
90e993b
0a4e23f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ local plugin = require("apisix.plugin") | |
local get_routes = require("apisix.router").http_routes | ||
local get_services = require("apisix.http.service").services | ||
local upstream_mod = require("apisix.upstream") | ||
local healthcheck_manager = require("apisix.healthcheck_manager") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might make sense to put it in the same directory as the batch processor manager. The root directory isn't the right place for it. |
||
local get_upstreams = upstream_mod.upstreams | ||
local collectgarbage = collectgarbage | ||
local ipairs = ipairs | ||
|
@@ -66,14 +67,13 @@ function _M.schema() | |
return 200, schema | ||
end | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just a reminder, please try to avoid pointless formatting changes, this noise will affect review efficiency. |
||
local healthcheck | ||
local function extra_checker_info(value) | ||
if not healthcheck then | ||
healthcheck = require("resty.healthcheck") | ||
end | ||
|
||
local name = upstream_mod.get_healthchecker_name(value) | ||
local name = healthcheck_manager.get_healthchecker_name(value.value) | ||
local nodes, err = healthcheck.get_target_list(name, "upstream-healthcheck") | ||
if err then | ||
core.log.error("healthcheck.get_target_list failed: ", err) | ||
|
@@ -214,7 +214,6 @@ local function iter_and_find_healthcheck_info(values, src_type, src_id) | |
if not checks then | ||
return nil, str_format("no checker for %s[%s]", src_type, src_id) | ||
end | ||
|
||
local info = extra_checker_info(value) | ||
info.type = get_checker_type(checks) | ||
return info | ||
|
@@ -249,7 +248,6 @@ function _M.get_health_checker() | |
if not info then | ||
return 404, {error_msg = err} | ||
end | ||
|
||
local out, err = try_render_html({stats={info}}) | ||
if out then | ||
core.response.set_header("Content-Type", "text/html") | ||
|
@@ -266,9 +264,6 @@ local function iter_add_get_routes_info(values, route_id) | |
local infos = {} | ||
for _, route in core.config_util.iterate_values(values) do | ||
local new_route = core.table.deepcopy(route) | ||
if new_route.value.upstream and new_route.value.upstream.parent then | ||
new_route.value.upstream.parent = nil | ||
end | ||
-- remove healthcheck info | ||
new_route.checker = nil | ||
new_route.checker_idx = nil | ||
|
@@ -312,9 +307,6 @@ local function iter_add_get_upstream_info(values, upstream_id) | |
for _, upstream in core.config_util.iterate_values(values) do | ||
local new_upstream = core.table.deepcopy(upstream) | ||
core.table.insert(infos, new_upstream) | ||
if new_upstream.value and new_upstream.value.parent then | ||
new_upstream.value.parent = nil | ||
end | ||
-- check the upstream id | ||
if upstream_id and upstream.value.id == upstream_id then | ||
return new_upstream | ||
|
@@ -332,6 +324,7 @@ function _M.dump_all_upstreams_info() | |
return 200, infos | ||
end | ||
|
||
|
||
function _M.dump_upstream_info() | ||
local upstreams = get_upstreams() | ||
local uri_segs = core.utils.split_uri(ngx_var.uri) | ||
|
@@ -354,9 +347,6 @@ local function iter_add_get_services_info(values, svc_id) | |
local infos = {} | ||
for _, svc in core.config_util.iterate_values(values) do | ||
local new_svc = core.table.deepcopy(svc) | ||
if new_svc.value.upstream and new_svc.value.upstream.parent then | ||
new_svc.value.upstream.parent = nil | ||
end | ||
-- remove healthcheck info | ||
new_svc.checker = nil | ||
new_svc.checker_idx = nil | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can cache
healthcheck_manager.fetch_node_status
, a short local functionUh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you mean using the lrucache with
checker
as key?