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 2022/09/06 01:22:26 UTC

[apisix] branch master updated: fix: don't enable passive healthcheck by default (#7850)

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 b48d02051 fix: don't enable passive healthcheck by default (#7850)
b48d02051 is described below

commit b48d02051a87abcf2ab6ea7c8cc2286db40ef6e6
Author: 罗泽轩 <sp...@gmail.com>
AuthorDate: Tue Sep 6 09:22:16 2022 +0800

    fix: don't enable passive healthcheck by default (#7850)
---
 apisix/schema_def.lua             |  14 ----
 rockspec/apisix-master-0.rockspec |   2 +-
 t/node/healthcheck-passive.t      | 170 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 171 insertions(+), 15 deletions(-)

diff --git a/apisix/schema_def.lua b/apisix/schema_def.lua
index 6169cc16e..59e23542d 100644
--- a/apisix/schema_def.lua
+++ b/apisix/schema_def.lua
@@ -277,20 +277,6 @@ 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 = 0,
-                },
-                unhealthy = {
-                    http_statuses = { 429, 500, 503 },
-                    tcp_failures = 0,
-                    timeouts = 0,
-                    http_failures = 0,
-                },
-            }
         }
     },
     anyOf = {
diff --git a/rockspec/apisix-master-0.rockspec b/rockspec/apisix-master-0.rockspec
index 7949735b2..a42d5207e 100644
--- a/rockspec/apisix-master-0.rockspec
+++ b/rockspec/apisix-master-0.rockspec
@@ -39,7 +39,7 @@ dependencies = {
     "lua-resty-balancer = 0.04",
     "lua-resty-ngxvar = 0.5.2",
     "lua-resty-jit-uuid = 0.0.7",
-    "lua-resty-healthcheck-api7 = 2.2.0",
+    "lua-resty-healthcheck-api7 = 2.2.1",
     "api7-lua-resty-jwt = 0.2.4",
     "lua-resty-hmac-ffi = 0.05",
     "lua-resty-cookie = 0.1.0",
diff --git a/t/node/healthcheck-passive.t b/t/node/healthcheck-passive.t
index be85ecc9d..f3f694b9f 100644
--- a/t/node/healthcheck-passive.t
+++ b/t/node/healthcheck-passive.t
@@ -165,3 +165,173 @@ GET /t
 --- error_code: 400
 --- response_body
 {"error_msg":"invalid configuration: property \"upstream\" validation failed: property \"checks\" validation failed: object matches none of the required: [\"active\"] or [\"active\",\"passive\"]"}
+
+
+
+=== TEST 4: set route(only active + active & passive)
+--- config
+    location /t {
+        content_by_lua_block {
+            local t = require("lib.test_admin").test
+            local code, body = t('/apisix/admin/routes/1',
+                ngx.HTTP_PUT,
+                [[{
+                    "uri": "/hello",
+                    "upstream": {
+                        "type": "roundrobin",
+                        "nodes": {
+                            "127.0.0.1:1980": 0,
+                            "127.0.0.1:1": 1
+                        },
+                        "retries": 0,
+                        "checks": {
+                            "active": {
+                                "http_path": "/status",
+                                "host": "foo.com",
+                                "healthy": {
+                                    "interval": 100,
+                                    "successes": 1
+                                },
+                                "unhealthy": {
+                                    "interval": 100,
+                                    "http_failures": 2
+                                }
+                            }
+                        }
+                    }
+                }]]
+                )
+
+            if code >= 300 then
+                ngx.status = code
+                ngx.say(body)
+                return
+            end
+
+            local code, body = t('/apisix/admin/routes/2',
+                ngx.HTTP_PUT,
+                [[{
+                    "uri": "/hello_",
+                    "upstream": {
+                        "type": "roundrobin",
+                        "nodes": {
+                            "127.0.0.1:1980": 0,
+                            "127.0.0.1:1": 1
+                        },
+                        "retries": 0,
+                        "checks": {
+                            "active": {
+                                "http_path": "/status",
+                                "host": "foo.com",
+                                "healthy": {
+                                    "interval": 100,
+                                    "successes": 1
+                                },
+                                "unhealthy": {
+                                    "interval": 100,
+                                    "http_failures": 2
+                                }
+                            },]] .. [[
+                            "passive": {
+                                "healthy": {
+                                    "http_statuses": [200, 201],
+                                    "successes": 3
+                                },
+                                "unhealthy": {
+                                    "http_statuses": [502],
+                                    "http_failures": 1,
+                                    "tcp_failures": 1
+                                }
+                            }
+                        }
+                    }
+                }]]
+                )
+
+            if code >= 300 then
+                ngx.status = code
+            end
+            ngx.say(body)
+        }
+    }
+--- request
+GET /t
+--- response_body
+passed
+
+
+
+=== TEST 5: only one route should have passive healthcheck
+--- config
+    location /t {
+        content_by_lua_block {
+            local t = require("lib.test_admin").test
+            local json_sort = require("toolkit.json")
+            local http = require("resty.http")
+            local uri = "http://127.0.0.1:" .. ngx.var.server_port
+
+            local ports_count = {}
+            local httpc = http.new()
+            local res, err = httpc:request_uri(uri .. "/hello_")
+            if not res then
+                ngx.say(err)
+                return
+            end
+            ngx.say(res.status)
+
+            -- only /hello_ has passive healthcheck
+            local res, err = httpc:request_uri(uri .. "/hello")
+            if not res then
+                ngx.say(err)
+                return
+            end
+            ngx.say(res.status)
+        }
+    }
+--- request
+GET /t
+--- response_body
+502
+502
+--- grep_error_log eval
+qr/enabled healthcheck passive/
+--- grep_error_log_out
+enabled healthcheck passive
+
+
+
+=== TEST 6: make sure passive healthcheck works (conf is not corrupted by the default value)
+--- config
+    location /t {
+        content_by_lua_block {
+            local t = require("lib.test_admin").test
+            local json_sort = require("toolkit.json")
+            local http = require("resty.http")
+            local uri = "http://127.0.0.1:" .. ngx.var.server_port
+
+            local ports_count = {}
+            local httpc = http.new()
+            local res, err = httpc:request_uri(uri .. "/hello")
+            if not res then
+                ngx.say(err)
+                return
+            end
+            ngx.say(res.status)
+
+            local res, err = httpc:request_uri(uri .. "/hello_")
+            if not res then
+                ngx.say(err)
+                return
+            end
+            ngx.say(res.status)
+        }
+    }
+--- request
+GET /t
+--- response_body
+502
+502
+--- grep_error_log eval
+qr/\[healthcheck\] \([^)]+\) unhealthy HTTP increment/
+--- grep_error_log_out
+[healthcheck] (upstream#/apisix/routes/2) unhealthy HTTP increment