mirror of
https://github.com/coredns/coredns.git
synced 2025-10-27 08:14:18 -04:00
plugin/proxy: Don't enable HTTP healthchecking if not configured (#1441)
HTTP healthchecking will be implicitely activated for proxy upstream hosts, even if not configured. The README states that not using the health_check directive will disable HTTP healthchecks though. It seems to me that the availability of the HealthCheck.Path attribute is used as indicator whether HTTP healthchecks should be used or not. The normalizeCheckURL() function didn't check that attribute though, always returning a CheckURL. This would increase the healthcheck failure on every third failure in plugin/proxy, without any possibility for the upstream host to be marked as healthy again. This would eventually remove all upstream hosts from the serving pool.
This commit is contained in:
committed by
Miek Gieben
parent
841e1a44ac
commit
64d7268ed6
@@ -212,6 +212,10 @@ func (u *HealthCheck) Select() *UpstreamHost {
|
||||
|
||||
// normalizeCheckURL creates a proper URL for the health check.
|
||||
func (u *HealthCheck) normalizeCheckURL(name string) string {
|
||||
if u.Path == "" {
|
||||
return ""
|
||||
}
|
||||
|
||||
// The DNS server might be an HTTP server. If so, extract its name.
|
||||
hostName := name
|
||||
ret, err := url.Parse(name)
|
||||
|
||||
@@ -52,17 +52,16 @@ func TestRegisterPolicy(t *testing.T) {
|
||||
func TestHealthCheck(t *testing.T) {
|
||||
u := &HealthCheck{
|
||||
Hosts: testPool(),
|
||||
Path: "/",
|
||||
FailTimeout: 10 * time.Second,
|
||||
MaxFails: 1,
|
||||
}
|
||||
|
||||
for i, h := range u.Hosts {
|
||||
u.Hosts[i].Fails = 1
|
||||
u.Hosts[i].CheckURL = u.normalizeCheckURL(h.Name)
|
||||
}
|
||||
|
||||
u.healthCheck()
|
||||
|
||||
time.Sleep(time.Duration(1 * time.Second)) // sleep a bit, it's async now
|
||||
|
||||
if u.Hosts[0].Down() {
|
||||
@@ -73,6 +72,27 @@ func TestHealthCheck(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestHealthCheckDisabled(t *testing.T) {
|
||||
u := &HealthCheck{
|
||||
Hosts: testPool(),
|
||||
FailTimeout: 10 * time.Second,
|
||||
MaxFails: 1,
|
||||
}
|
||||
|
||||
for i, h := range u.Hosts {
|
||||
u.Hosts[i].CheckURL = u.normalizeCheckURL(h.Name)
|
||||
}
|
||||
|
||||
u.healthCheck()
|
||||
time.Sleep(time.Duration(1 * time.Second)) // sleep a bit, it's async now
|
||||
|
||||
for i, h := range u.Hosts {
|
||||
if h.Down() {
|
||||
t.Errorf("Expected host %d in testpool to not be down with healthchecks disabled.", i+1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestRoundRobinPolicy(t *testing.T) {
|
||||
pool := testPool()
|
||||
rrPolicy := &RoundRobin{}
|
||||
|
||||
Reference in New Issue
Block a user