diff --git a/README.md b/README.md index 304e722a..11e2e97e 100644 --- a/README.md +++ b/README.md @@ -106,6 +106,8 @@ Versioning is strictly based on [Semantic Versioning](https://semver.org/) and `post_local` won't anymore call `poll` on a running worker automatically, for more information, see: https://github.com/Kong/lua-resty-worker-events#200-16-september-2020 +* BREAKING: tcp_failures can no longer be 0 on http(s) checks (unless http(s)_failures + are also set to 0) [#55](https://github.com/Kong/lua-resty-healthcheck/pull/55) * feature: Added support for https_sni [#49](https://github.com/Kong/lua-resty-healthcheck/pull/49) * fix: properly log line numbers by using tail calls [#29](https://github.com/Kong/lua-resty-healthcheck/pull/29) * fix: when not providing a hostname, use IP [#48](https://github.com/Kong/lua-resty-healthcheck/pull/48) diff --git a/lib/resty/healthcheck.lua b/lib/resty/healthcheck.lua index cb3800a6..5a4e4fce 100644 --- a/lib/resty/healthcheck.lua +++ b/lib/resty/healthcheck.lua @@ -1363,6 +1363,22 @@ function _M.new(opts) assert(self.checks.passive.unhealthy.http_failures < 255, "checks.passive.unhealthy.http_failures must be at most 254") assert(self.checks.passive.unhealthy.timeouts < 255, "checks.passive.unhealthy.timeouts must be at most 254") + -- since counter types are independent (tcp failure does not also increment http failure) + -- a TCP threshold of 0 is not allowed for enabled http checks. + -- It would make tcp failures go unnoticed because the http failure counter is not + -- incremented and a tcp threshold of 0 means disabled, and hence it would never trip. + -- See https://github.com/Kong/lua-resty-healthcheck/issues/30 + if self.checks.passive.type == "http" or self.checks.passive.type == "https" then + if self.checks.passive.unhealthy.http_failures > 0 then + assert(self.checks.passive.unhealthy.tcp_failures > 0, "self.checks.passive.unhealthy.tcp_failures must be >0 for http(s) checks with http_failures >0") + end + end + if self.checks.active.type == "http" or self.checks.active.type == "https" then + if self.checks.active.unhealthy.http_failures > 0 then + assert(self.checks.active.unhealthy.tcp_failures > 0, "self.checks.active.unhealthy.tcp_failures must be > 0 for http(s) checks with http_failures >0") + end + end + if opts.test then self.test_get_counter = test_get_counter end diff --git a/t/07-report_tcp_failure.t b/t/07-report_tcp_failure.t index 0478bf47..be82e72e 100644 --- a/t/07-report_tcp_failure.t +++ b/t/07-report_tcp_failure.t @@ -130,7 +130,7 @@ qq{ unhealthy = { interval = 999, -- we don't want active checks tcp_failures = 0, - http_failures = 5, + http_failures = 0, } }, passive = { @@ -208,7 +208,7 @@ qq{ }, unhealthy = { tcp_failures = 0, - http_failures = 5, + http_failures = 0, } } }