Commit 64d7268e authored by Tobias Schmidt's avatar Tobias Schmidt Committed by Miek Gieben

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.
parent 841e1a44
...@@ -212,6 +212,10 @@ func (u *HealthCheck) Select() *UpstreamHost { ...@@ -212,6 +212,10 @@ func (u *HealthCheck) Select() *UpstreamHost {
// normalizeCheckURL creates a proper URL for the health check. // normalizeCheckURL creates a proper URL for the health check.
func (u *HealthCheck) normalizeCheckURL(name string) string { func (u *HealthCheck) normalizeCheckURL(name string) string {
if u.Path == "" {
return ""
}
// The DNS server might be an HTTP server. If so, extract its name. // The DNS server might be an HTTP server. If so, extract its name.
hostName := name hostName := name
ret, err := url.Parse(name) ret, err := url.Parse(name)
......
...@@ -52,17 +52,16 @@ func TestRegisterPolicy(t *testing.T) { ...@@ -52,17 +52,16 @@ func TestRegisterPolicy(t *testing.T) {
func TestHealthCheck(t *testing.T) { func TestHealthCheck(t *testing.T) {
u := &HealthCheck{ u := &HealthCheck{
Hosts: testPool(), Hosts: testPool(),
Path: "/",
FailTimeout: 10 * time.Second, FailTimeout: 10 * time.Second,
MaxFails: 1, MaxFails: 1,
} }
for i, h := range u.Hosts { for i, h := range u.Hosts {
u.Hosts[i].Fails = 1
u.Hosts[i].CheckURL = u.normalizeCheckURL(h.Name) u.Hosts[i].CheckURL = u.normalizeCheckURL(h.Name)
} }
u.healthCheck() u.healthCheck()
time.Sleep(time.Duration(1 * time.Second)) // sleep a bit, it's async now time.Sleep(time.Duration(1 * time.Second)) // sleep a bit, it's async now
if u.Hosts[0].Down() { if u.Hosts[0].Down() {
...@@ -73,6 +72,27 @@ func TestHealthCheck(t *testing.T) { ...@@ -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) { func TestRoundRobinPolicy(t *testing.T) {
pool := testPool() pool := testPool()
rrPolicy := &RoundRobin{} rrPolicy := &RoundRobin{}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment