Support 3xx HTTP status codes for health check
This commit is contained in:
parent
c09febfffc
commit
d6d795e286
3 changed files with 12 additions and 4 deletions
|
@ -454,12 +454,12 @@ The deprecated way:
|
||||||
|
|
||||||
#### Health Check
|
#### Health Check
|
||||||
|
|
||||||
A health check can be configured in order to remove a backend from LB rotation as long as it keeps returning HTTP status codes other than `2xx` to HTTP GET requests periodically carried out by Traefik.
|
A health check can be configured in order to remove a backend from LB rotation as long as it keeps returning HTTP status codes other than `2xx` or `3xx` to HTTP GET requests periodically carried out by Traefik.
|
||||||
The check is defined by a path appended to the backend URL and an interval (given in a format understood by [time.ParseDuration](https://golang.org/pkg/time/#ParseDuration)) specifying how often the health check should be executed (the default being 30 seconds).
|
The check is defined by a path appended to the backend URL and an interval (given in a format understood by [time.ParseDuration](https://golang.org/pkg/time/#ParseDuration)) specifying how often the health check should be executed (the default being 30 seconds).
|
||||||
Each backend must respond to the health check within 5 seconds.
|
Each backend must respond to the health check within 5 seconds.
|
||||||
By default, the port of the backend server is used, however, this may be overridden.
|
By default, the port of the backend server is used, however, this may be overridden.
|
||||||
|
|
||||||
A recovering backend returning `2xx` responses again is being returned to the LB rotation pool.
|
A recovering backend returning `2xx` or `3xx` responses again is being returned to the LB rotation pool.
|
||||||
|
|
||||||
For example:
|
For example:
|
||||||
```toml
|
```toml
|
||||||
|
|
|
@ -203,8 +203,8 @@ func checkHealth(serverURL *url.URL, backend *BackendHealthCheck) error {
|
||||||
|
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
if resp.StatusCode < http.StatusOK || resp.StatusCode >= http.StatusMultipleChoices {
|
if resp.StatusCode < http.StatusOK || resp.StatusCode >= http.StatusBadRequest {
|
||||||
return fmt.Errorf("received non-2xx status code: %v", resp.StatusCode)
|
return fmt.Errorf("received error status code: %v", resp.StatusCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -47,6 +47,14 @@ func TestSetBackendsConfiguration(t *testing.T) {
|
||||||
expectedNumUpsertedServers: 0,
|
expectedNumUpsertedServers: 0,
|
||||||
expectedGaugeValue: 1,
|
expectedGaugeValue: 1,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
desc: "healthy server staying healthy (StatusPermanentRedirect)",
|
||||||
|
startHealthy: true,
|
||||||
|
healthSequence: []int{http.StatusPermanentRedirect},
|
||||||
|
expectedNumRemovedServers: 0,
|
||||||
|
expectedNumUpsertedServers: 0,
|
||||||
|
expectedGaugeValue: 1,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
desc: "healthy server becoming sick",
|
desc: "healthy server becoming sick",
|
||||||
startHealthy: true,
|
startHealthy: true,
|
||||||
|
|
Loading…
Reference in a new issue