From 44cb58380654925e9ba044c3c9b041a80441ba0b Mon Sep 17 00:00:00 2001 From: Janko Date: Tue, 23 Nov 2021 16:55:45 +0800 Subject: [PATCH 1/3] fix: invalid error after passive health check is changed --- apisix/schema_def.lua | 14 +++++ t/admin/health-check.t | 114 ++++++++++++++++++++++------------------- 2 files changed, 75 insertions(+), 53 deletions(-) diff --git a/apisix/schema_def.lua b/apisix/schema_def.lua index adddf155d8bf..4c50e89a32fe 100644 --- a/apisix/schema_def.lua +++ b/apisix/schema_def.lua @@ -277,6 +277,20 @@ local health_checker = { }, } } + }, + 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 = 5, + }, + unhealthy = { + http_statuses = { 429, 500, 503 }, + tcp_failures = 2, + timeouts = 7, + http_failures = 5, + }, } } }, diff --git a/t/admin/health-check.t b/t/admin/health-check.t index 22d0e5e75979..d113e444d161 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 = 5, + }, + unhealthy = { + http_statuses = { 429, 500, 503 }, + tcp_failures = 2, + timeouts = 7, + http_failures = 5, + } + } + + 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] From 839b61110270d0d4c5d1f2d2d008e96ee1d71557 Mon Sep 17 00:00:00 2001 From: Janko Date: Tue, 23 Nov 2021 18:16:36 +0800 Subject: [PATCH 2/3] chore: update schema defined --- apisix/schema_def.lua | 16 ++++++++-------- t/admin/health-check.t | 8 ++++---- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/apisix/schema_def.lua b/apisix/schema_def.lua index 4c50e89a32fe..62b0836a6264 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,19 +259,19 @@ 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 }, @@ -283,13 +283,13 @@ local health_checker = { healthy = { http_statuses = { 200, 201, 202, 203, 204, 205, 206, 207, 208, 226, 300, 301, 302, 303, 304, 305, 306, 307, 308 }, - successes = 5, + successes = 0, }, unhealthy = { http_statuses = { 429, 500, 503 }, - tcp_failures = 2, - timeouts = 7, - http_failures = 5, + tcp_failures = 0, + timeouts = 0, + http_failures = 0, }, } } diff --git a/t/admin/health-check.t b/t/admin/health-check.t index d113e444d161..f4246f371b52 100644 --- a/t/admin/health-check.t +++ b/t/admin/health-check.t @@ -466,13 +466,13 @@ passed healthy = { http_statuses = { 200, 201, 202, 203, 204, 205, 206, 207, 208, 226, 300, 301, 302, 303, 304, 305, 306, 307, 308 }, - successes = 5, + successes = 0, }, unhealthy = { http_statuses = { 429, 500, 503 }, - tcp_failures = 2, - timeouts = 7, - http_failures = 5, + tcp_failures = 0, + timeouts = 0, + http_failures = 0, } } From 8cad3e6f2c5fe79e47e15a3910fa1f322f38da09 Mon Sep 17 00:00:00 2001 From: Janko Date: Wed, 24 Nov 2021 09:48:21 +0800 Subject: [PATCH 3/3] chore: update health-check document parameter range --- docs/en/latest/health-check.md | 8 ++++---- docs/zh/latest/health-check.md | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/en/latest/health-check.md b/docs/en/latest/health-check.md index dc53096ec31b..850a96e60e2d 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 4e3f9928bb4d..a6d2ecd4e4e1 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 类型检查时,确定节点非健康的次数。 | ### 配置示例: