You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by sp...@apache.org on 2021/11/24 02:57:16 UTC
[apisix] branch master updated: fix: invalid error after passive health check is changed (#5589)
This is an automated email from the ASF dual-hosted git repository.
spacewander pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git
The following commit(s) were added to refs/heads/master by this push:
new 54a0e11 fix: invalid error after passive health check is changed (#5589)
54a0e11 is described below
commit 54a0e115e5d639406ddffa9b32edca31f3000733
Author: 帅进超 <sh...@gmail.com>
AuthorDate: Wed Nov 24 10:57:07 2021 +0800
fix: invalid error after passive health check is changed (#5589)
---
apisix/schema_def.lua | 22 ++++++--
docs/en/latest/health-check.md | 8 +--
docs/zh/latest/health-check.md | 8 +--
t/admin/health-check.t | 114 ++++++++++++++++++++++-------------------
4 files changed, 87 insertions(+), 65 deletions(-)
diff --git a/apisix/schema_def.lua b/apisix/schema_def.lua
index adddf15..62b0836 100644
--- a/apisix/schema_def.lua
+++ b/apisix/schema_def.lua
@@ -237,7 +237,7 @@ local health_checker = {
},
successes = {
type = "integer",
- minimum = 1,
+ minimum = 0,
maximum = 254,
default = 5
}
@@ -259,24 +259,38 @@ local health_checker = {
},
tcp_failures = {
type = "integer",
- minimum = 1,
+ minimum = 0,
maximum = 254,
default = 2
},
timeouts = {
type = "integer",
- minimum = 1,
+ minimum = 0,
maximum = 254,
default = 7
},
http_failures = {
type = "integer",
- minimum = 1,
+ minimum = 0,
maximum = 254,
default = 5
},
}
}
+ },
+ 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,
+ },
}
}
},
diff --git a/docs/en/latest/health-check.md b/docs/en/latest/health-check.md
index dc53096..850a96e 100644
--- a/docs/en/latest/health-check.md
+++ b/docs/en/latest/health-check.md
@@ -55,11 +55,11 @@ it whether this unique node is healthy or not.
| upstream.checks.active.unhealthy.tcp_failures | Active check (unhealthy node) | integer | `1` to `254` | 2 | Active check (unhealthy node) TCP type check, determine the number of times that the node is not healthy. |
| upstream.checks.active.unhealthy.timeouts | Active check (unhealthy node) | integer | `1` to `254` | 3 | Active check (unhealthy node) to determine the number of timeouts for unhealthy nodes. |
| upstream.checks.passive.healthy.http_statuses | Passive check (healthy node) | array | `200` to `599` | [200, 201, 202, 203, 204, 205, 206, 207, 208, 226, 300, 301, 302, 303, 304, 305, 306, 307, 308] | Passive check (healthy node) HTTP or HTTPS type check, the HTTP status code of the healthy node. |
-| upstream.checks.passive.healthy.successes | Passive check (healthy node) | integer | `1` to `254` | 5 | Passive checks (healthy node) determine the number of times a node is healthy. |
+| upstream.checks.passive.healthy.successes | Passive check (healthy node) | integer | `0` to `254` | 5 | Passive checks (healthy node) determine the number of times a node is healthy. |
| upstream.checks.passive.unhealthy.http_statuses | Passive check (unhealthy node) | array | `200` to `599` | [429, 500, 503] | Passive check (unhealthy node) HTTP or HTTPS type check, the HTTP status code of the non-healthy node. |
-| upstream.checks.passive.unhealthy.tcp_failures | Passive check (unhealthy node) | integer | `1` to `254` | 2 | Passive check (unhealthy node) When TCP type is checked, determine the number of times that the node is not healthy. |
-| upstream.checks.passive.unhealthy.timeouts | Passive check (unhealthy node) | integer | `1` to `254` | 7 | Passive checks (unhealthy node) determine the number of timeouts for unhealthy nodes. |
-| upstream.checks.passive.unhealthy.http_failures | Passive check (unhealthy node) | integer | `1` to `254` | 5 | Passive check (unhealthy node) The number of times that the node is not healthy during HTTP or HTTPS type checking. |
+| upstream.checks.passive.unhealthy.tcp_failures | Passive check (unhealthy node) | integer | `0` to `254` | 2 | Passive check (unhealthy node) When TCP type is checked, determine the number of times that the node is not healthy. |
+| upstream.checks.passive.unhealthy.timeouts | Passive check (unhealthy node) | integer | `0` to `254` | 7 | Passive checks (unhealthy node) determine the number of timeouts for unhealthy nodes. |
+| upstream.checks.passive.unhealthy.http_failures | Passive check (unhealthy node) | integer | `0` to `254` | 5 | Passive check (unhealthy node) The number of times that the node is not healthy during HTTP or HTTPS type checking. |
### Configuration example
diff --git a/docs/zh/latest/health-check.md b/docs/zh/latest/health-check.md
index 4e3f992..a6d2ecd 100644
--- a/docs/zh/latest/health-check.md
+++ b/docs/zh/latest/health-check.md
@@ -53,11 +53,11 @@ Apache APISIX 的健康检查使用 [lua-resty-healthcheck](https://github.com/K
| upstream.checks.active.unhealthy.tcp_failures | 主动检查(非健康节点) | integer | `1` 至 `254` | 2 | 主动检查(非健康节点)TCP 类型检查时,确定节点非健康的次数。 |
| upstream.checks.active.unhealthy.timeouts | 主动检查(非健康节点) | integer | `1` 至 `254` | 3 | 主动检查(非健康节点)确定节点非健康的超时次数。 |
| upstream.checks.passive.healthy.http_statuses | 被动检查(健康节点) | array | `200` 至 `599` | [200, 201, 202, 203, 204, 205, 206, 207, 208, 226, 300, 301, 302, 303, 304, 305, 306, 307, 308] | 被动检查(健康节点) HTTP 或 HTTPS 类型检查时,健康节点的HTTP状态码。 |
-| upstream.checks.passive.healthy.successes | 被动检查(健康节点) | integer | `1` 至 `254` | 5 | 被动检查(健康节点)确定节点健康的次数。 |
+| upstream.checks.passive.healthy.successes | 被动检查(健康节点) | integer | `0` 至 `254` | 5 | 被动检查(健康节点)确定节点健康的次数。 |
| upstream.checks.passive.unhealthy.http_statuses | 被动检查(非健康节点) | array | `200` 至 `599` | [429, 500, 503] | 被动检查(非健康节点) HTTP 或 HTTPS 类型检查时,非健康节点的HTTP状态码。 |
-| upstream.checks.passive.unhealthy.tcp_failures | 被动检查(非健康节点) | integer | `1` 至 `254` | 2 | 被动检查(非健康节点)TCP 类型检查时,确定节点非健康的次数。 |
-| upstream.checks.passive.unhealthy.timeouts | 被动检查(非健康节点) | integer | `1` 至 `254` | 7 | 被动检查(非健康节点)确定节点非健康的超时次数。 |
-| upstream.checks.passive.unhealthy.http_failures | 被动检查(非健康节点) | integer | `1` 至 `254` | 5 | 被动检查(非健康节点)HTTP 或 HTTPS 类型检查时,确定节点非健康的次数。 |
+| upstream.checks.passive.unhealthy.tcp_failures | 被动检查(非健康节点) | integer | `0` 至 `254` | 2 | 被动检查(非健康节点)TCP 类型检查时,确定节点非健康的次数。 |
+| upstream.checks.passive.unhealthy.timeouts | 被动检查(非健康节点) | integer | `0` 至 `254` | 7 | 被动检查(非健康节点)确定节点非健康的超时次数。 |
+| upstream.checks.passive.unhealthy.http_failures | 被动检查(非健康节点) | integer | `0` 至 `254` | 5 | 被动检查(非健康节点)HTTP 或 HTTPS 类型检查时,确定节点非健康的次数。 |
### 配置示例:
diff --git a/t/admin/health-check.t b/t/admin/health-check.t
index 22d0e5e..f4246f3 100644
--- a/t/admin/health-check.t
+++ b/t/admin/health-check.t
@@ -52,6 +52,15 @@ add_block_preprocessor(sub {
_EOC_
$block->set_value("init_by_lua_block", $init_by_lua_block);
+
+ if ((!defined $block->error_log) && (!defined $block->no_error_log)) {
+ $block->set_value("no_error_log", "[error]");
+ }
+
+ if (!defined $block->request) {
+ $block->set_value("request", "GET /t");
+ }
+
});
run_tests;
@@ -90,12 +99,8 @@ __DATA__
ngx.say(body)
}
}
---- request
-GET /t
--- response_body
passed
---- no_error_log
-[error]
@@ -137,12 +142,8 @@ passed
ngx.say(body)
}
}
---- request
-GET /t
--- response_body
passed
---- no_error_log
-[error]
@@ -166,13 +167,9 @@ passed
ngx.print(body)
}
}
---- request
-GET /t
--- error_code: 400
--- response_body
{"error_msg":"invalid configuration: property \"upstream\" validation failed: property \"checks\" validation failed: property \"active\" validation failed: property \"healthy\" validation failed: property \"successes\" validation failed: expected 255 to be smaller than 254"}
---- no_error_log
-[error]
@@ -196,13 +193,9 @@ GET /t
ngx.print(body)
}
}
---- request
-GET /t
--- error_code: 400
--- response_body
{"error_msg":"invalid configuration: property \"upstream\" validation failed: property \"checks\" validation failed: property \"active\" validation failed: property \"healthy\" validation failed: property \"successes\" validation failed: expected 0 to be greater than 1"}
---- no_error_log
-[error]
@@ -226,13 +219,9 @@ GET /t
ngx.print(body)
}
}
---- request
-GET /t
--- error_code: 400
--- response_body
{"error_msg":"invalid configuration: property \"upstream\" validation failed: property \"checks\" validation failed: property \"passive\" validation failed: property \"unhealthy\" validation failed: property \"http_statuses\" validation failed: failed to validate item 2: expected 600 to be smaller than 599"}
---- no_error_log
-[error]
@@ -254,13 +243,9 @@ GET /t
ngx.print(body)
}
}
---- request
-GET /t
--- error_code: 400
--- response_body
{"error_msg":"invalid configuration: property \"upstream\" validation failed: property \"checks\" validation failed: property \"active\" validation failed: property \"type\" validation failed: matches none of the enum values"}
---- no_error_log
-[error]
@@ -284,13 +269,9 @@ GET /t
ngx.print(body)
}
}
---- request
-GET /t
--- error_code: 400
--- response_body
{"error_msg":"invalid configuration: property \"upstream\" validation failed: property \"checks\" validation failed: property \"active\" validation failed: property \"healthy\" validation failed: property \"http_statuses\" validation failed: expected unique items but items 1 and 2 are equal"}
---- no_error_log
-[error]
@@ -314,13 +295,9 @@ GET /t
ngx.print(body)
}
}
---- request
-GET /t
--- error_code: 400
--- response_body
{"error_msg":"invalid configuration: property \"upstream\" validation failed: property \"checks\" validation failed: property \"active\" validation failed: property \"unhealthy\" validation failed: property \"http_failures\" validation failed: wrong type: expected integer, got number"}
---- no_error_log
-[error]
@@ -353,12 +330,8 @@ GET /t
ngx.say(body)
}
}
---- request
-GET /t
--- response_body
passed
---- no_error_log
-[error]
@@ -391,12 +364,8 @@ passed
ngx.say(body)
}
}
---- request
-GET /t
--- response_body
passed
---- no_error_log
-[error]
@@ -429,13 +398,9 @@ passed
ngx.print(body)
}
}
---- request
-GET /t
--- error_code: 400
--- response_body
{"error_msg":"invalid configuration: property \"upstream\" validation failed: property \"checks\" validation failed: property \"active\" validation failed: property \"req_headers\" validation failed: failed to validate item 2: wrong type: expected string, got number"}
---- no_error_log
-[error]
@@ -469,17 +434,64 @@ GET /t
ngx.print(body)
}
}
---- request
-GET /t
--- error_code: 400
--- response_body
{"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
+=== TEST 13: only active
+--- 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",
+ "healthy": {
+ "interval": 2,
+ "successes": 1
+ },
+ "unhealthy": {
+ "interval": 1,
+ "http_failures": 2
+ }
+ }
+ }]])
+ exp_data.node.value.upstream.checks.active = req_data.upstream.checks.active
+ exp_data.node.value.upstream.checks.passive = {
+ 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,
+ }
+ }
+
+ local code, body = t('/apisix/admin/routes/1',
+ ngx.HTTP_PUT,
+ req_data,
+ exp_data
+ )
+
+ ngx.status = code
+ ngx.say(body)
+ }
+ }
+--- response_body
+passed
+
+
+
+=== TEST 14: number type timeout
--- config
location /t {
content_by_lua_block {
@@ -512,9 +524,5 @@ GET /t
ngx.say(body)
}
}
---- request
-GET /t
--- response_body
passed
---- no_error_log
-[error]