summaryrefslogtreecommitdiff
path: root/modules/caddyhttp/reverseproxy/healthchecks.go
diff options
context:
space:
mode:
authorMatt Holt <mholt@users.noreply.github.com>2020-10-13 10:35:20 -0600
committerGitHub <noreply@github.com>2020-10-13 10:35:20 -0600
commitc7efb0307d425eb533885e314518c370a06763da (patch)
treedfebe5f16db89c4e8f458c7fdbef5d55cd768277 /modules/caddyhttp/reverseproxy/healthchecks.go
parente34d9f1244439a01a195febd966c7c5d88c98d33 (diff)
reverseproxy: Fix dial placeholders, SRV, active health checks (#3780)
* reverseproxy: Fix dial placeholders, SRV, active health checks Supercedes #3776 Partially reverts or updates #3756, #3693, and #3695 * reverseproxy: add integration tests Co-authored-by: Mohammed Al Sahaf <msaa1990@gmail.com>
Diffstat (limited to 'modules/caddyhttp/reverseproxy/healthchecks.go')
-rw-r--r--modules/caddyhttp/reverseproxy/healthchecks.go43
1 files changed, 31 insertions, 12 deletions
diff --git a/modules/caddyhttp/reverseproxy/healthchecks.go b/modules/caddyhttp/reverseproxy/healthchecks.go
index 410b9d4..4e93320 100644
--- a/modules/caddyhttp/reverseproxy/healthchecks.go
+++ b/modules/caddyhttp/reverseproxy/healthchecks.go
@@ -154,23 +154,42 @@ func (h *Handler) doActiveHealthCheckForAllHosts() {
}
}()
- portStr := strconv.Itoa(upstream.activeHealthCheckPort)
- hostAddr := net.JoinHostPort(upstream.networkAddress.Host, portStr)
- if upstream.networkAddress.IsUnixNetwork() {
+ networkAddr, err := caddy.NewReplacer().ReplaceOrErr(upstream.Dial, true, true)
+ if err != nil {
+ h.HealthChecks.Active.logger.Error("invalid use of placeholders in dial address for active health checks",
+ zap.String("address", networkAddr),
+ zap.Error(err),
+ )
+ return
+ }
+ addr, err := caddy.ParseNetworkAddress(networkAddr)
+ if err != nil {
+ h.HealthChecks.Active.logger.Error("bad network address",
+ zap.String("address", networkAddr),
+ zap.Error(err),
+ )
+ return
+ }
+ if hcp := uint(upstream.activeHealthCheckPort); hcp != 0 {
+ if addr.IsUnixNetwork() {
+ addr.Network = "tcp" // I guess we just assume TCP since we are using a port??
+ }
+ addr.StartPort, addr.EndPort = hcp, hcp
+ }
+ if upstream.LookupSRV == "" && addr.PortRangeSize() != 1 {
+ h.HealthChecks.Active.logger.Error("multiple addresses (upstream must map to only one address)",
+ zap.String("address", networkAddr),
+ )
+ return
+ }
+ hostAddr := addr.JoinHostPort(0)
+ if addr.IsUnixNetwork() {
// this will be used as the Host portion of a http.Request URL, and
// paths to socket files would produce an error when creating URL,
// so use a fake Host value instead; unix sockets are usually local
hostAddr = "localhost"
}
-
- dialInfo := DialInfo{
- Upstream: upstream,
- Network: upstream.networkAddress.Network,
- Host: upstream.networkAddress.Host,
- Port: portStr,
- Address: hostAddr,
- }
- err := h.doActiveHealthCheck(dialInfo, hostAddr, upstream.Host)
+ err = h.doActiveHealthCheck(DialInfo{Network: addr.Network, Address: hostAddr}, hostAddr, upstream.Host)
if err != nil {
h.HealthChecks.Active.logger.Error("active health check failed",
zap.String("address", hostAddr),