membphis commented on code in PR #12852:
URL: https://github.com/apache/apisix/pull/12852#discussion_r2730476633
##########
apisix/discovery/kubernetes/init.lua:
##########
@@ -211,17 +211,21 @@ end
local function post_list(handle)
- if not handle.existing_keys or not handle.current_keys_hash then
- return
- end
- for _, key in ipairs(handle.existing_keys) do
- if not handle.current_keys_hash[key] then
- core.log.info("kubernetes discovery module find dirty data in
shared dict, key:", key)
- handle.endpoint_dict:delete(key)
+ if handle.existing_keys and handle.current_keys_hash then
+ for _, key in ipairs(handle.existing_keys) do
+ if not handle.current_keys_hash[key] then
+ core.log.info("kubernetes discovery module found dirty data in
shared dict, key: ",
+ key)
Review Comment:
bad indentation
<img width="785" height="200" alt="Image"
src="https://github.com/user-attachments/assets/c8dc8619-083d-47c6-be3f-ea04be7b08bf"
/>
##########
apisix/discovery/kubernetes/init.lua:
##########
@@ -715,4 +726,55 @@ function _M.dump_data()
end
+local function check_ready(id)
+ local endpoint_dict = get_endpoint_dict(id)
+ if not endpoint_dict then
+ core.log.error("failed to get lua_shared_dict:",
get_endpoint_dict_name(id),
+ ", please check your APISIX version")
Review Comment:
ditto
##########
apisix/init.lua:
##########
@@ -976,54 +976,74 @@ function _M.status()
core.response.exit(200, core.json.encode({ status = "ok" }))
end
-function _M.status_ready()
- local local_conf = core.config.local_conf()
- local role = core.table.try_read_attr(local_conf, "deployment", "role")
- local provider = core.table.try_read_attr(local_conf, "deployment",
"role_" ..
- role, "config_provider")
- if provider == "yaml" or provider == "etcd" then
- local status_shdict = ngx.shared["status-report"]
- local ids = status_shdict:get_keys()
- local error
- local worker_count = ngx.worker.count()
- if #ids ~= worker_count then
- core.log.warn("worker count: ", worker_count, " but status report
count: ", #ids)
- error = "worker count: " .. ngx.worker.count() ..
- " but status report count: " .. #ids
- end
- if error then
- core.response.exit(503, core.json.encode({
- status = "error",
- error = error
- }))
- return
- end
- for _, id in ipairs(ids) do
- local ready = status_shdict:get(id)
+
+local function discovery_ready_check()
+ local discovery_type = local_conf.discovery
+ if not discovery_type then
+ return true
+ end
+ for discovery_name, _ in pairs(discovery_type) do
+ local dis_module = discovery[discovery_name]
+ if dis_module.check_discovery_ready then
+ local ready, message = dis_module.check_discovery_ready()
if not ready then
- core.log.warn("worker id: ", id, " has not received
configuration")
- error = "worker id: " .. id ..
- " has not received configuration"
- break
+ return false, message
end
end
+ end
+ return true
+end
- if error then
- core.response.exit(503, core.json.encode({
- status = "error",
- error = error
- }))
- return
+local function config_ready_check()
+ local role = core.table.try_read_attr(local_conf, "deployment", "role")
+ local provider = core.table.try_read_attr(local_conf, "deployment",
"role_" ..
+ role, "config_provider")
+ if provider ~= "yaml" and provider ~= "etcd" then
+ return false, "unknown config provider: " .. tostring(provider)
+ end
+
+ local status_shdict = ngx.shared["status-report"]
+ local ids = status_shdict:get_keys()
+
+ local worker_count = ngx.worker.count()
+ if #ids ~= worker_count then
+ local error = "worker count: " .. worker_count .. " but status report
count: " .. #ids
+ core.log.warn(error)
Review Comment:
should we use `error` log level?
##########
apisix/init.lua:
##########
@@ -976,54 +976,74 @@ function _M.status()
core.response.exit(200, core.json.encode({ status = "ok" }))
end
-function _M.status_ready()
- local local_conf = core.config.local_conf()
- local role = core.table.try_read_attr(local_conf, "deployment", "role")
- local provider = core.table.try_read_attr(local_conf, "deployment",
"role_" ..
- role, "config_provider")
- if provider == "yaml" or provider == "etcd" then
- local status_shdict = ngx.shared["status-report"]
- local ids = status_shdict:get_keys()
- local error
- local worker_count = ngx.worker.count()
- if #ids ~= worker_count then
- core.log.warn("worker count: ", worker_count, " but status report
count: ", #ids)
- error = "worker count: " .. ngx.worker.count() ..
- " but status report count: " .. #ids
- end
- if error then
- core.response.exit(503, core.json.encode({
- status = "error",
- error = error
- }))
- return
- end
- for _, id in ipairs(ids) do
- local ready = status_shdict:get(id)
+
+local function discovery_ready_check()
+ local discovery_type = local_conf.discovery
+ if not discovery_type then
+ return true
+ end
+ for discovery_name, _ in pairs(discovery_type) do
+ local dis_module = discovery[discovery_name]
+ if dis_module.check_discovery_ready then
+ local ready, message = dis_module.check_discovery_ready()
if not ready then
- core.log.warn("worker id: ", id, " has not received
configuration")
- error = "worker id: " .. id ..
- " has not received configuration"
- break
+ return false, message
end
end
+ end
+ return true
+end
- if error then
- core.response.exit(503, core.json.encode({
- status = "error",
- error = error
- }))
- return
+local function config_ready_check()
+ local role = core.table.try_read_attr(local_conf, "deployment", "role")
+ local provider = core.table.try_read_attr(local_conf, "deployment",
"role_" ..
+ role, "config_provider")
+ if provider ~= "yaml" and provider ~= "etcd" then
+ return false, "unknown config provider: " .. tostring(provider)
+ end
+
+ local status_shdict = ngx.shared["status-report"]
Review Comment:
we may get `nil`, need to check it
##########
apisix/init.lua:
##########
@@ -976,54 +976,74 @@ function _M.status()
core.response.exit(200, core.json.encode({ status = "ok" }))
end
-function _M.status_ready()
- local local_conf = core.config.local_conf()
- local role = core.table.try_read_attr(local_conf, "deployment", "role")
- local provider = core.table.try_read_attr(local_conf, "deployment",
"role_" ..
- role, "config_provider")
- if provider == "yaml" or provider == "etcd" then
- local status_shdict = ngx.shared["status-report"]
- local ids = status_shdict:get_keys()
- local error
- local worker_count = ngx.worker.count()
- if #ids ~= worker_count then
- core.log.warn("worker count: ", worker_count, " but status report
count: ", #ids)
- error = "worker count: " .. ngx.worker.count() ..
- " but status report count: " .. #ids
- end
- if error then
- core.response.exit(503, core.json.encode({
- status = "error",
- error = error
- }))
- return
- end
- for _, id in ipairs(ids) do
- local ready = status_shdict:get(id)
+
+local function discovery_ready_check()
+ local discovery_type = local_conf.discovery
+ if not discovery_type then
+ return true
+ end
+ for discovery_name, _ in pairs(discovery_type) do
+ local dis_module = discovery[discovery_name]
+ if dis_module.check_discovery_ready then
+ local ready, message = dis_module.check_discovery_ready()
if not ready then
- core.log.warn("worker id: ", id, " has not received
configuration")
- error = "worker id: " .. id ..
- " has not received configuration"
- break
+ return false, message
end
end
+ end
+ return true
+end
- if error then
- core.response.exit(503, core.json.encode({
- status = "error",
- error = error
- }))
- return
+local function config_ready_check()
+ local role = core.table.try_read_attr(local_conf, "deployment", "role")
+ local provider = core.table.try_read_attr(local_conf, "deployment",
"role_" ..
Review Comment:
```
local provider = core.table.try_read_attr(local_conf, "deployment",
"role_" .. role, "config_provider")
##########
apisix/discovery/kubernetes/init.lua:
##########
@@ -436,7 +440,8 @@ local function start_fetch(handle)
ngx.timer.at(0, timer_runner)
end
-local function get_endpoint_dict(id)
+
+local function get_endpoint_dict_name(id)
Review Comment:
pls confirm the `id` is `string` object
##########
apisix/init.lua:
##########
@@ -976,54 +976,74 @@ function _M.status()
core.response.exit(200, core.json.encode({ status = "ok" }))
end
-function _M.status_ready()
- local local_conf = core.config.local_conf()
- local role = core.table.try_read_attr(local_conf, "deployment", "role")
- local provider = core.table.try_read_attr(local_conf, "deployment",
"role_" ..
- role, "config_provider")
- if provider == "yaml" or provider == "etcd" then
- local status_shdict = ngx.shared["status-report"]
- local ids = status_shdict:get_keys()
- local error
- local worker_count = ngx.worker.count()
- if #ids ~= worker_count then
- core.log.warn("worker count: ", worker_count, " but status report
count: ", #ids)
- error = "worker count: " .. ngx.worker.count() ..
- " but status report count: " .. #ids
- end
- if error then
- core.response.exit(503, core.json.encode({
- status = "error",
- error = error
- }))
- return
- end
- for _, id in ipairs(ids) do
- local ready = status_shdict:get(id)
+
+local function discovery_ready_check()
+ local discovery_type = local_conf.discovery
+ if not discovery_type then
+ return true
+ end
+ for discovery_name, _ in pairs(discovery_type) do
+ local dis_module = discovery[discovery_name]
+ if dis_module.check_discovery_ready then
+ local ready, message = dis_module.check_discovery_ready()
if not ready then
- core.log.warn("worker id: ", id, " has not received
configuration")
- error = "worker id: " .. id ..
- " has not received configuration"
- break
+ return false, message
end
end
+ end
+ return true
+end
- if error then
- core.response.exit(503, core.json.encode({
- status = "error",
- error = error
- }))
- return
+local function config_ready_check()
+ local role = core.table.try_read_attr(local_conf, "deployment", "role")
+ local provider = core.table.try_read_attr(local_conf, "deployment",
"role_" ..
+ role, "config_provider")
+ if provider ~= "yaml" and provider ~= "etcd" then
+ return false, "unknown config provider: " .. tostring(provider)
+ end
+
+ local status_shdict = ngx.shared["status-report"]
+ local ids = status_shdict:get_keys()
+
+ local worker_count = ngx.worker.count()
+ if #ids ~= worker_count then
+ local error = "worker count: " .. worker_count .. " but status report
count: " .. #ids
+ core.log.warn(error)
+ return false, error
+ end
+ for _, id in ipairs(ids) do
+ local ready = status_shdict:get(id)
+ if not ready then
+ local error = "worker id: " .. id .. " has not received
configuration"
+ core.log.warn(error)
Review Comment:
ditto
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]