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

change: the timeout of healthcheck should be number type. #1892

Merged
merged 4 commits into from
Jul 27, 2020
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
2 changes: 1 addition & 1 deletion apisix/schema_def.lua
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ local health_checker = {
enum = {"http", "https", "tcp"},
default = "http"
},
timeout = {type = "integer", default = 1},
timeout = {type = "number", default = 1},
concurrency = {type = "integer", default = 10},
host = host_def,
http_path = {type = "string", default = "/"},
Expand Down
3 changes: 3 additions & 0 deletions doc/health-check.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f13
"retries": 2,
"checks": {
"active": {
"timeout": 5,
"http_path": "/status",
"host": "foo.com",
"healthy": {
Expand Down Expand Up @@ -78,6 +79,8 @@ contains: `active` or `passive`.

* `active`: To enable active health checks, you need to specify the configuration items under `checks.active` in the Upstream object configuration.

* `active.timeout`: Socket timeout for active checks (in seconds), support decimals. For example `1.01` means `1010` milliseconds, `2` means `2000` milliseconds.

* `active.http_path`: The HTTP GET request path used to detect if the upstream is healthy.
* `active.host`: The HTTP request host used to detect if the upstream is healthy.

Expand Down
3 changes: 3 additions & 0 deletions doc/zh-cn/health-check.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f13
"retries": 2,
"checks": {
"active": {
"timeout": 5,
"http_path": "/status",
"host": "foo.com",
"healthy": {
Expand Down Expand Up @@ -78,6 +79,8 @@ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f13

* `active`: 要启动探活健康检查,需要在upstream配置中的 `checks.active` 添加如下配置项。

* `active.timeout`: 主动健康检查 socket 超时时间(秒为单位),支持小数点。比如 `1.01` 代表 `1010` 毫秒,`2` 代表 `2000` 毫秒。

* `active.http_path`: 用于发现upstream节点健康可用的HTTP GET请求路径。
* `active.host`: 用于发现upstream节点健康可用的HTTP请求主机名。

Expand Down
42 changes: 42 additions & 0 deletions t/admin/health-check.t
Original file line number Diff line number Diff line change
Expand Up @@ -476,3 +476,45 @@ GET /t
{"error_msg":"invalid configuration: property \"upstream\" validation failed: property \"checks\" validation failed: object matches none of the requireds: [\"active\"] or [\"active\",\"passive\"]"}
--- no_error_log
[error]



=== TEST 13: number type timeout
--- config
location /t {
content_by_lua_block {
local t = require("lib.test_admin").test

req_data.upstream.checks = json.decode([[{
"active": {
"http_path": "/status",
"host": "foo.com",
"timeout": 1.01,
"healthy": {
"interval": 2,
"successes": 1
},
"unhealthy": {
"interval": 1,
"http_failures": 2
}
}
}]])
exp_data.node.value.upstream.checks = req_data.upstream.checks

local code, body = t('/apisix/admin/routes/1',
ngx.HTTP_PUT,
req_data,
exp_data
)

ngx.status = code
ngx.say(body)
}
}
--- request
GET /t
--- response_body
passed
--- no_error_log
[error]