This is an automated email from the ASF dual-hosted git repository. ashishtiwari pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/apisix.git
The following commit(s) were added to refs/heads/master by this push: new 35a7bc399 feat: add a global switch to disable upstream health check (#12407) 35a7bc399 is described below commit 35a7bc39907769b89beb585226b2b787b5c76dce Author: Ashish Tiwari <ashishjaitiwari15112...@gmail.com> AuthorDate: Fri Jul 11 11:35:04 2025 +0530 feat: add a global switch to disable upstream health check (#12407) --- apisix/cli/schema.lua | 5 ++ apisix/upstream.lua | 6 ++ conf/config.yaml.example | 2 + t/node/healthcheck-global-switch.t | 142 +++++++++++++++++++++++++++++++++++++ 4 files changed, 155 insertions(+) diff --git a/apisix/cli/schema.lua b/apisix/cli/schema.lua index 36d758ca8..b7a8b0fc0 100644 --- a/apisix/cli/schema.lua +++ b/apisix/cli/schema.lua @@ -254,6 +254,11 @@ local config_schema = { }, } }, + disable_upstream_healthcheck = { + type = "boolean", + default = false, + description = "a global switch to disable upstream health checks", + }, } }, nginx_config = { diff --git a/apisix/upstream.lua b/apisix/upstream.lua index ffd5e3986..3d3b6b426 100644 --- a/apisix/upstream.lua +++ b/apisix/upstream.lua @@ -16,6 +16,7 @@ -- local require = require local core = require("apisix.core") +local config_local = require("apisix.core.config_local") local discovery = require("apisix.discovery.init").discovery local upstream_util = require("apisix.utils.upstream") local apisix_ssl = require("apisix.ssl") @@ -103,6 +104,11 @@ _M.get_healthchecker_name = get_healthchecker_name local function create_checker(upstream) + local local_conf = config_local.local_conf() + if local_conf and local_conf.apisix and local_conf.apisix.disable_upstream_healthcheck then + core.log.info("healthchecker won't be created: disabled upstream healthcheck") + return nil + end if healthcheck == nil then healthcheck = require("resty.healthcheck") end diff --git a/conf/config.yaml.example b/conf/config.yaml.example index 6f2f8319b..1d52f6e41 100644 --- a/conf/config.yaml.example +++ b/conf/config.yaml.example @@ -136,6 +136,8 @@ apisix: # ip: 127.0.0.1 # /status endpoint will return 200 status code if APISIX has successfully started and running correctly # port: 7085 # /status/ready endpoint will return 503 status code if any of the workers do not receive config from etcd # or (standalone mode) the config isn't loaded yet either via file or Admin API. + # disable_upstream_healthcheck: false # A global switch for healthcheck. Defaults to false. + # When set to true, it overrides all upstream healthcheck configurations and globally disabling healthchecks. nginx_config: # Config for render the template to generate nginx.conf # user: root # Set the execution user of the worker process. This is only # effective if the master process runs with super-user privileges. diff --git a/t/node/healthcheck-global-switch.t b/t/node/healthcheck-global-switch.t new file mode 100644 index 000000000..75c3780f3 --- /dev/null +++ b/t/node/healthcheck-global-switch.t @@ -0,0 +1,142 @@ +# +# 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. +# + +use t::APISIX 'no_plan'; + +repeat_each(1); +log_level('info'); +no_root_location(); +no_shuffle(); +worker_connections(256); + +run_tests(); + +__DATA__ + +=== TEST 1: set route(two upstream node: one healthy + one unhealthy) +--- yaml_config +apisix: + disable_upstream_healthcheck: true +--- config + location /t { + content_by_lua_block { + local t = require("lib.test_admin").test + local code, body = t('/apisix/admin/routes/1', + ngx.HTTP_PUT, + [[{ + "uri": "/server_port", + "upstream": { + "retries": 0, + "type": "roundrobin", + "nodes": { + "127.0.0.1:1980": 1, + "127.0.0.1:1970": 1 + }, + "checks": { + "active": { + "http_path": "/status", + "host": "foo.com", + "healthy": { + "interval": 1, + "successes": 1 + }, + "unhealthy": { + "interval": 1, + "http_failures": 2 + } + } + } + } + }]] + ) + + if code >= 300 then + ngx.status = code + end + ngx.say(body) + } + } +--- request +GET /t +--- response_body +passed +--- grep_error_log eval +qr/^.*?\[error\](?!.*process exiting).*/ +--- grep_error_log_out + + + +=== TEST 2: switch on disable_upstream_healthcheck and hit routes +--- yaml_config +apisix: + disable_upstream_healthcheck: true +--- config + location /t { + content_by_lua_block { + local http = require "resty.http" + local uri = "http://127.0.0.1:" .. ngx.var.server_port + .. "/server_port" + + do + local httpc = http.new() + local res, err = httpc:request_uri(uri, {method = "GET", keepalive = false}) + end + + ngx.sleep(2.5) + + local get_port = function(body) + if body == "1980" then + return "1980" + end + return "1970" + end + + local ports_count = {} + for i = 1, 12 do + local httpc = http.new() + local res, err = httpc:request_uri(uri, {method = "GET", keepalive = false}) + if not res then + ngx.say(err) + return + end + ports_count[get_port(res.body)] = (ports_count[get_port(res.body)] or 0) + 1 + end + + local ports_arr = {} + for port, count in pairs(ports_count) do + table.insert(ports_arr, {port = port, count = count}) + end + + local function cmd(a, b) + return a.port > b.port + end + table.sort(ports_arr, cmd) + + ngx.say(require("toolkit.json").encode(ports_arr)) + ngx.exit(200) + } + } +--- request +GET /t +--- response_body +[{"count":6,"port":"1980"},{"count":6,"port":"1970"}] +--- error_log +disabled upstream healthcheck +--- no_error_log +(upstream#/apisix/routes/1) unhealthy TCP increment (1/2) for 'foo.com(127.0.0.1:1970)' +(upstream#/apisix/routes/1) unhealthy TCP increment (2/2) for 'foo.com(127.0.0.1:1970)' +--- timeout: 6