Skip to content

Commit

Permalink
fix(tcp failure) disabling tcp check on http(s) checks is not allowed (
Browse files Browse the repository at this point in the history
  • Loading branch information
Tieske authored and AlinsRan committed Jun 1, 2023
1 parent 973cffe commit 94524e1
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
16 changes: 16 additions & 0 deletions lib/resty/healthcheck.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1384,6 +1384,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
Expand Down
8 changes: 8 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,14 @@ Versioning is strictly based on [Semantic Versioning](https://semver.org/)

### Unreleased

* BREAKING: Bump `lua-resty-worker-events` dependency to `2.0.0`. This makes
a lot of the APIs in this library asynchronous as the worker events `post`
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)
* fix: makefile; make install
Expand Down
4 changes: 2 additions & 2 deletions t/07-report_tcp_failure.t
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ qq{
unhealthy = {
interval = 999, -- we don't want active checks
tcp_failures = 0,
http_failures = 5,
http_failures = 0,
}
},
passive = {
Expand Down Expand Up @@ -204,7 +204,7 @@ qq{
},
unhealthy = {
tcp_failures = 0,
http_failures = 5,
http_failures = 0,
}
}
}
Expand Down

0 comments on commit 94524e1

Please sign in to comment.