From 631a41f5f8b50e7b4a0c082e1515cc6e1db5afdf Mon Sep 17 00:00:00 2001 From: Yuansheng Date: Thu, 23 Jul 2020 14:47:23 +0800 Subject: [PATCH 1/4] change: the timeout of `healthcheck` should be number type. --- apisix/schema_def.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apisix/schema_def.lua b/apisix/schema_def.lua index d580be6982ed..813395371a6b 100644 --- a/apisix/schema_def.lua +++ b/apisix/schema_def.lua @@ -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 = "/"}, From 479d3d40046c3638a92f327889c9f7885435bd1a Mon Sep 17 00:00:00 2001 From: Yuansheng Date: Thu, 23 Jul 2020 14:51:32 +0800 Subject: [PATCH 2/4] test: add new case. --- t/admin/health-check.t | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/t/admin/health-check.t b/t/admin/health-check.t index 8680768e75cd..698d69d11b92 100644 --- a/t/admin/health-check.t +++ b/t/admin/health-check.t @@ -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] From 3086210adee582010872169ae5848e5ede51406a Mon Sep 17 00:00:00 2001 From: Yuansheng Date: Thu, 23 Jul 2020 14:55:01 +0800 Subject: [PATCH 3/4] doc --- doc/health-check.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/health-check.md b/doc/health-check.md index 1b78831e9570..ff41c16814fe 100644 --- a/doc/health-check.md +++ b/doc/health-check.md @@ -78,6 +78,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). + * `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. From 564e5915a1fcad08f8e99f5ff3c4d144304d7009 Mon Sep 17 00:00:00 2001 From: Yuansheng Date: Sun, 26 Jul 2020 20:32:27 +0800 Subject: [PATCH 4/4] doc: support decimals --- doc/health-check.md | 3 ++- doc/zh-cn/health-check.md | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/doc/health-check.md b/doc/health-check.md index ff41c16814fe..81e35a5e3a5b 100644 --- a/doc/health-check.md +++ b/doc/health-check.md @@ -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": { @@ -78,7 +79,7 @@ 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). + * `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. diff --git a/doc/zh-cn/health-check.md b/doc/zh-cn/health-check.md index 6be4691c98b3..c77ae6aaa195 100644 --- a/doc/zh-cn/health-check.md +++ b/doc/zh-cn/health-check.md @@ -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": { @@ -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请求主机名。