Skip to content

Commit

Permalink
fix: don't enable passive healthcheck by default
Browse files Browse the repository at this point in the history
This issue is introduced in the bugfix:
apache#5589

This PR fixes the bug added by that bugfix, and also
introduce a new test (TEST 6) to cover issue
apache#4077.

The fix of that issue is submitted in
api7/lua-resty-healthcheck#5
which fixes the bug in an appropriate way.

Signed-off-by: spacewander <spacewanderlzx@gmail.com>
  • Loading branch information
spacewander committed Sep 2, 2022
1 parent 3a795f6 commit f99ba05
Show file tree
Hide file tree
Showing 2 changed files with 170 additions and 14 deletions.
14 changes: 0 additions & 14 deletions apisix/schema_def.lua
Expand Up @@ -277,20 +277,6 @@ local health_checker = {
}
}
},
default = {
type = "http",
healthy = {
http_statuses = { 200, 201, 202, 203, 204, 205, 206, 207, 208, 226,
300, 301, 302, 303, 304, 305, 306, 307, 308 },
successes = 0,
},
unhealthy = {
http_statuses = { 429, 500, 503 },
tcp_failures = 0,
timeouts = 0,
http_failures = 0,
},
}
}
},
anyOf = {
Expand Down
170 changes: 170 additions & 0 deletions t/node/healthcheck-passive.t
Expand Up @@ -165,3 +165,173 @@ GET /t
--- error_code: 400
--- response_body
{"error_msg":"invalid configuration: property \"upstream\" validation failed: property \"checks\" validation failed: object matches none of the required: [\"active\"] or [\"active\",\"passive\"]"}
=== TEST 4: set route(only active + active & passive)
--- 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": "/hello",
"upstream": {
"type": "roundrobin",
"nodes": {
"127.0.0.1:1980": 0,
"127.0.0.1:1": 1
},
"retries": 0,
"checks": {
"active": {
"http_path": "/status",
"host": "foo.com",
"healthy": {
"interval": 100,
"successes": 1
},
"unhealthy": {
"interval": 100,
"http_failures": 2
}
}
}
}
}]]
)
if code >= 300 then
ngx.status = code
ngx.say(body)
return
end
local code, body = t('/apisix/admin/routes/2',
ngx.HTTP_PUT,
[[{
"uri": "/hello_",
"upstream": {
"type": "roundrobin",
"nodes": {
"127.0.0.1:1980": 0,
"127.0.0.1:1": 1
},
"retries": 0,
"checks": {
"active": {
"http_path": "/status",
"host": "foo.com",
"healthy": {
"interval": 100,
"successes": 1
},
"unhealthy": {
"interval": 100,
"http_failures": 2
}
},]] .. [[
"passive": {
"healthy": {
"http_statuses": [200, 201],
"successes": 3
},
"unhealthy": {
"http_statuses": [502],
"http_failures": 1,
"tcp_failures": 1
}
}
}
}
}]]
)
if code >= 300 then
ngx.status = code
end
ngx.say(body)
}
}
--- request
GET /t
--- response_body
passed
=== TEST 5: only one route should have passive healthcheck
--- config
location /t {
content_by_lua_block {
local t = require("lib.test_admin").test
local json_sort = require("toolkit.json")
local http = require("resty.http")
local uri = "http://127.0.0.1:" .. ngx.var.server_port
local ports_count = {}
local httpc = http.new()
local res, err = httpc:request_uri(uri .. "/hello_")
if not res then
ngx.say(err)
return
end
ngx.say(res.status)
-- only /hello_ has passive healthcheck
local res, err = httpc:request_uri(uri .. "/hello")
if not res then
ngx.say(err)
return
end
ngx.say(res.status)
}
}
--- request
GET /t
--- response_body
502
502
--- grep_error_log eval
qr/enabled healthcheck passive/
--- grep_error_log_out
enabled healthcheck passive
=== TEST 6: make sure passive healthcheck works (conf is not corrupted by the default value)
--- config
location /t {
content_by_lua_block {
local t = require("lib.test_admin").test
local json_sort = require("toolkit.json")
local http = require("resty.http")
local uri = "http://127.0.0.1:" .. ngx.var.server_port
local ports_count = {}
local httpc = http.new()
local res, err = httpc:request_uri(uri .. "/hello")
if not res then
ngx.say(err)
return
end
ngx.say(res.status)
local res, err = httpc:request_uri(uri .. "/hello_")
if not res then
ngx.say(err)
return
end
ngx.say(res.status)
}
}
--- request
GET /t
--- response_body
502
502
--- grep_error_log eval
qr/\[healthcheck\] \([^)]+\) unhealthy HTTP increment/
--- grep_error_log_out
[healthcheck] (upstream#/apisix/routes/2) unhealthy HTTP increment

0 comments on commit f99ba05

Please sign in to comment.