membphis commented on code in PR #12426:
URL: https://github.com/apache/apisix/pull/12426#discussion_r2224148181
##########
apisix/balancer.lua:
##########
@@ -27,7 +27,7 @@ local get_last_failure = balancer.get_last_failure
local set_timeouts = balancer.set_timeouts
local ngx_now = ngx.now
local str_byte = string.byte
-
+local healthcheck_manager = require("apisix.healthcheck_manager")
Review Comment:
<img width="874" height="433" alt="image"
src="https://github.com/user-attachments/assets/efebd474-f34f-4e31-9a7b-3b8eba3f0e80"
/>
##########
apisix/healthcheck_manager.lua:
##########
@@ -0,0 +1,298 @@
+--
+-- Licensed to the Apache Software Foundation (ASF) under one or more
+-- contributor license agreements. See the NOTICE file distributed with
+-- this work for additional information regarding copyright ownership.
+-- The ASF licenses this file to You under the Apache License, Version 2.0
+-- (the "License"); you may not use this file except in compliance with
+-- the License. You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+local require = require
+local ipairs = ipairs
+local pcall = pcall
+local exiting = ngx.worker.exiting
+local pairs = pairs
+local tostring = tostring
+local core = require("apisix.core")
+local config_local = require("apisix.core.config_local")
+local healthcheck
+local events = require("apisix.events")
+local tab_clone = core.table.clone
+local timer_every = ngx.timer.every
+local _M = {
+ working_pool = {}, -- resource_path -> {version = ver, checker =
checker}
+ waiting_pool = {} -- resource_path -> resource_ver
+}
+local DELAYED_CLEAR_TIMEOUT = 10
+local healthcheck_shdict_name = "upstream-healthcheck"
+local is_http = ngx.config.subsystem == "http"
+if not is_http then
+ healthcheck_shdict_name = healthcheck_shdict_name .. "-" ..
ngx.config.subsystem
+end
+
+
+local function get_healthchecker_name(value)
+ return "upstream#" .. (value.resource_key or value.upstream.resource_key)
+end
+_M.get_healthchecker_name = get_healthchecker_name
+
+
+local function fetch_latest_conf(resource_path)
+ local resource_type, id
+ -- Handle both formats:
+ -- 1. /apisix/<resource_type>/<id>
+ -- 2. /<resource_type>/<id>
+ if resource_path:find("^/apisix/") then
Review Comment:
this is the prefix:
<img width="873" height="186" alt="image"
src="https://github.com/user-attachments/assets/9321e07c-353f-4e10-a0ea-0adffd4e1473"
/>
##########
apisix/healthcheck_manager.lua:
##########
@@ -0,0 +1,298 @@
+--
+-- Licensed to the Apache Software Foundation (ASF) under one or more
+-- contributor license agreements. See the NOTICE file distributed with
+-- this work for additional information regarding copyright ownership.
+-- The ASF licenses this file to You under the Apache License, Version 2.0
+-- (the "License"); you may not use this file except in compliance with
+-- the License. You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+local require = require
+local ipairs = ipairs
+local pcall = pcall
+local exiting = ngx.worker.exiting
+local pairs = pairs
+local tostring = tostring
+local core = require("apisix.core")
+local config_local = require("apisix.core.config_local")
+local healthcheck
+local events = require("apisix.events")
+local tab_clone = core.table.clone
+local timer_every = ngx.timer.every
+local _M = {
Review Comment:
it is not safe to export `working_pool` and `waiting_pool`.
We will never allow the "working_pool" or "waiting_pool" to be destroyed.
they only can be use in this lua module
##########
apisix/balancer.lua:
##########
@@ -75,7 +75,8 @@ local function fetch_health_nodes(upstream, checker)
local port = upstream.checks and upstream.checks.active and
upstream.checks.active.port
local up_nodes = core.table.new(0, #nodes)
for _, node in ipairs(nodes) do
- local ok, err = checker:get_target_status(node.host, port or
node.port, host)
+ local ok, err = healthcheck_manager.fetch_node_status(checker,
Review Comment:
we can cache `healthcheck_manager.fetch_node_status`, a short local function
--
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]