From cfb87394cb0daa8037108b99872f7dd4c4d00ff3 Mon Sep 17 00:00:00 2001 From: wangye <1031205858@qq.com> Date: Fri, 22 Dec 2023 17:04:20 +0800 Subject: [PATCH 1/4] [2023-12-22][add health-check schema check] --- apisix/schema_def.lua | 4 ++++ t/admin/health-check.t | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/apisix/schema_def.lua b/apisix/schema_def.lua index fa6852a948ca..f222b935d101 100644 --- a/apisix/schema_def.lua +++ b/apisix/schema_def.lua @@ -132,6 +132,10 @@ local health_checker = { enum = {"http", "https", "tcp"}, default = "http" }, + body_match_str = { + type = "string", + default = "" + }, timeout = {type = "number", default = 1}, concurrency = {type = "integer", default = 10}, host = host_def, diff --git a/t/admin/health-check.t b/t/admin/health-check.t index f48525698b16..df53e1946ae8 100644 --- a/t/admin/health-check.t +++ b/t/admin/health-check.t @@ -519,3 +519,41 @@ passed } --- response_body passed + + + +=== TEST 1: 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 + }, + "body_match_str": "pass" + } + }]]) + exp_data.value.upstream.checks = req_data.upstream.checks + + local code, body, res = t('/apisix/admin/routes/1', + ngx.HTTP_PUT, + req_data, + exp_data + ) + + ngx.status = code + ngx.say(body) + } + } +--- response_body +passed From adce66f41d026a9102fd609f523981423725e5ad Mon Sep 17 00:00:00 2001 From: wangye <1031205858@qq.com> Date: Fri, 22 Dec 2023 17:05:48 +0800 Subject: [PATCH 2/4] [2023-12-22][add health-check schema check] --- t/admin/health-check.t | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/admin/health-check.t b/t/admin/health-check.t index df53e1946ae8..88d44c27b0da 100644 --- a/t/admin/health-check.t +++ b/t/admin/health-check.t @@ -522,7 +522,7 @@ passed -=== TEST 1: active +=== TEST 15: test body_match_str --- config location /t { content_by_lua_block { From ef9b3de28bc6fd1617d47b0bdeab3c04dbcdbc46 Mon Sep 17 00:00:00 2001 From: wangye <1031205858@qq.com> Date: Mon, 29 Jan 2024 15:02:30 +0800 Subject: [PATCH 3/4] remove redundant code --- apisix/schema_def.lua | 4 ---- t/admin/health-check.t | 38 -------------------------------------- 2 files changed, 42 deletions(-) diff --git a/apisix/schema_def.lua b/apisix/schema_def.lua index f222b935d101..fa6852a948ca 100644 --- a/apisix/schema_def.lua +++ b/apisix/schema_def.lua @@ -132,10 +132,6 @@ local health_checker = { enum = {"http", "https", "tcp"}, default = "http" }, - body_match_str = { - type = "string", - default = "" - }, timeout = {type = "number", default = 1}, concurrency = {type = "integer", default = 10}, host = host_def, diff --git a/t/admin/health-check.t b/t/admin/health-check.t index 88d44c27b0da..f48525698b16 100644 --- a/t/admin/health-check.t +++ b/t/admin/health-check.t @@ -519,41 +519,3 @@ passed } --- response_body passed - - - -=== TEST 15: test body_match_str ---- 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 - }, - "body_match_str": "pass" - } - }]]) - exp_data.value.upstream.checks = req_data.upstream.checks - - local code, body, res = t('/apisix/admin/routes/1', - ngx.HTTP_PUT, - req_data, - exp_data - ) - - ngx.status = code - ngx.say(body) - } - } ---- response_body -passed From 9e608749c13358b73d1ab1a7190f575b1204d63d Mon Sep 17 00:00:00 2001 From: wangye <1031205858@qq.com> Date: Thu, 14 Mar 2024 17:43:55 +0800 Subject: [PATCH 4/4] Fix executing consul2.t before cluster already --- ci/pod/docker-compose.first.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/ci/pod/docker-compose.first.yml b/ci/pod/docker-compose.first.yml index 622360638a00..d203a967ddfc 100644 --- a/ci/pod/docker-compose.first.yml +++ b/ci/pod/docker-compose.first.yml @@ -66,6 +66,11 @@ services: - "8302:8302" - "9600:8600" command: [ "consul", "agent", "-server", "-bootstrap-expect=1", "-bind", "0.0.0.0", "-client", "0.0.0.0", "-node", "node-1", "-log-level", "info", "-data-dir=/consul/data", "-enable-script-checks" ] + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost:8500/"] + interval: 10s + timeout: 10s + retries: 5 networks: consul_cluster_net: aliases: @@ -79,6 +84,9 @@ services: ports: - "9501:8500" command: [ "consul", "agent", "-server", "-bind", "0.0.0.0", "-client", "0.0.0.0", "-retry-join", "consul.cluster", "-node", "node-2", "-log-level", "info", "-data-dir=/consul/data", "-enable-script-checks" ] + depends_on: + consul_node_1: + condition: service_healthy networks: consul_cluster_net: aliases: @@ -92,6 +100,9 @@ services: ports: - "9502:8500" command: [ "consul", "agent", "-server", "-bind", "0.0.0.0", "-client", "0.0.0.0", "-retry-join", "consul.cluster", "-node", "node-3", "-log-level", "info", "-data-dir=/consul/data", "-enable-script-checks" ] + depends_on: + consul_node_1: + condition: service_healthy networks: consul_cluster_net: aliases: