Skip to content
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

fix: don't enable passive healthcheck by default #7850

Merged
merged 2 commits into from
Sep 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions apisix/schema_def.lua
Original file line number Diff line number Diff line change
Expand Up @@ -277,20 +277,6 @@ local health_checker = {
}
}
},
leslie-tsang marked this conversation as resolved.
Show resolved Hide resolved
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
2 changes: 1 addition & 1 deletion rockspec/apisix-master-0.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ dependencies = {
"lua-resty-balancer = 0.04",
"lua-resty-ngxvar = 0.5.2",
"lua-resty-jit-uuid = 0.0.7",
"lua-resty-healthcheck-api7 = 2.2.0",
"lua-resty-healthcheck-api7 = 2.2.1",
"api7-lua-resty-jwt = 0.2.4",
"lua-resty-hmac-ffi = 0.05",
"lua-resty-cookie = 0.1.0",
Expand Down
170 changes: 170 additions & 0 deletions t/node/healthcheck-passive.t
Original file line number Diff line number Diff line change
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