mirror of
https://github.com/caddyserver/caddy.git
synced 2026-05-21 14:26:30 -04:00
reverseproxy: Correct alternate port for active health checks (#3693)
* reverseproxy: construct active health-check transport from scratch (Fixes #3691) * reverseproxy: do upstream health-check on the correct alternative port * reverseproxy: add integration test for health-check on alternative port * reverseproxy: put back the custom transport for health-check http client * reverseproxy: cleanup health-check integration test * reverseproxy: fix health-check of unix socket upstreams * reverseproxy: skip unix socket tests on Windows * tabs > spaces Co-authored-by: Francis Lavoie <lavofr@gmail.com> * make the linter (and @francislavoie) happy Co-authored-by: Francis Lavoie <lavofr@gmail.com> * One more lint fix Co-authored-by: Francis Lavoie <lavofr@gmail.com> Co-authored-by: Francis Lavoie <lavofr@gmail.com>
This commit is contained in:
committed by
GitHub
parent
e3324aa6de
commit
bc453fa6ae
@@ -208,9 +208,13 @@ func (h *Handler) Provision(ctx caddy.Context) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if addr.PortRangeSize() != 1 {
|
||||
return fmt.Errorf("multiple addresses (upstream must map to only one address): %v", addr)
|
||||
}
|
||||
|
||||
upstream.networkAddress = addr
|
||||
|
||||
// create or get the host representation for this upstream
|
||||
var host Host = new(upstreamHost)
|
||||
existingHost, loaded := hosts.LoadOrStore(upstream.String(), host)
|
||||
@@ -267,6 +271,16 @@ func (h *Handler) Provision(ctx caddy.Context) error {
|
||||
Transport: h.Transport,
|
||||
}
|
||||
|
||||
for _, upstream := range h.Upstreams {
|
||||
// if there's an alternative port for health-check provided in the config,
|
||||
// then use it, otherwise use the port of upstream.
|
||||
if h.HealthChecks.Active.Port != 0 {
|
||||
upstream.activeHealthCheckPort = h.HealthChecks.Active.Port
|
||||
} else {
|
||||
upstream.activeHealthCheckPort = int(upstream.networkAddress.StartPort)
|
||||
}
|
||||
}
|
||||
|
||||
if h.HealthChecks.Active.Interval == 0 {
|
||||
h.HealthChecks.Active.Interval = caddy.Duration(30 * time.Second)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user