Skip to content

Commit

Permalink
change: the timeout of healthcheck should be number type. (#1892)
Browse files Browse the repository at this point in the history
  • Loading branch information
membphis authored Jul 27, 2020
1 parent 2d667ec commit 4015071
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 1 deletion.
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]

0 comments on commit 4015071

Please sign in to comment.