mirror of
https://github.com/traefik/traefik
synced 2026-02-03 11:10:33 +00:00
Rename health check URL parameter to path.
Also improve documentation.
This commit is contained in:
+10
-4
@@ -236,16 +236,22 @@ For example:
|
||||
sticky = true
|
||||
```
|
||||
|
||||
Healthcheck URL can be configured with a relative URL for `healthcheck.URL`.
|
||||
Interval between healthcheck can be configured by using `healthcheck.interval`
|
||||
(default: 30s)
|
||||
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 200 OK 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). Each
|
||||
backend must respond to the health check within 5 seconds.
|
||||
|
||||
A recovering backend returning 200 OK responses again is being returned to the
|
||||
LB rotation pool.
|
||||
|
||||
For example:
|
||||
```toml
|
||||
[backends]
|
||||
[backends.backend1]
|
||||
[backends.backend1.healthcheck]
|
||||
URL = "/health"
|
||||
path = "/health"
|
||||
interval = "10s"
|
||||
```
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ func GetHealthCheck() *HealthCheck {
|
||||
|
||||
// BackendHealthCheck HealthCheck configuration for a backend
|
||||
type BackendHealthCheck struct {
|
||||
URL string
|
||||
Path string
|
||||
Interval time.Duration
|
||||
DisabledURLs []*url.URL
|
||||
lb loadBalancer
|
||||
@@ -81,7 +81,7 @@ func (hc *HealthCheck) execute(ctx context.Context) {
|
||||
enabledURLs := currentBackend.lb.Servers()
|
||||
var newDisabledURLs []*url.URL
|
||||
for _, url := range currentBackend.DisabledURLs {
|
||||
if checkHealth(url, currentBackend.URL) {
|
||||
if checkHealth(url, currentBackend.Path) {
|
||||
log.Debugf("HealthCheck is up [%s]: Upsert in server list", url.String())
|
||||
currentBackend.lb.UpsertServer(url, roundrobin.Weight(1))
|
||||
} else {
|
||||
@@ -91,7 +91,7 @@ func (hc *HealthCheck) execute(ctx context.Context) {
|
||||
currentBackend.DisabledURLs = newDisabledURLs
|
||||
|
||||
for _, url := range enabledURLs {
|
||||
if !checkHealth(url, currentBackend.URL) {
|
||||
if !checkHealth(url, currentBackend.Path) {
|
||||
log.Debugf("HealthCheck has failed [%s]: Remove from server list", url.String())
|
||||
currentBackend.lb.RemoveServer(url)
|
||||
currentBackend.DisabledURLs = append(currentBackend.DisabledURLs, url)
|
||||
@@ -104,12 +104,12 @@ func (hc *HealthCheck) execute(ctx context.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
func checkHealth(serverURL *url.URL, checkURL string) bool {
|
||||
func checkHealth(serverURL *url.URL, path string) bool {
|
||||
timeout := time.Duration(5 * time.Second)
|
||||
client := http.Client{
|
||||
Timeout: timeout,
|
||||
}
|
||||
resp, err := client.Get(serverURL.String() + checkURL)
|
||||
resp, err := client.Get(serverURL.String() + path)
|
||||
if err != nil || resp.StatusCode != 200 {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -666,7 +666,7 @@ func (server *Server) loadConfig(configurations configs, globalConfiguration Glo
|
||||
interval = time.Second * 30
|
||||
}
|
||||
}
|
||||
backendsHealthcheck[frontend.Backend] = healthcheck.NewBackendHealthCheck(configuration.Backends[frontend.Backend].HealthCheck.URL, interval, rebalancer)
|
||||
backendsHealthcheck[frontend.Backend] = healthcheck.NewBackendHealthCheck(configuration.Backends[frontend.Backend].HealthCheck.Path, interval, rebalancer)
|
||||
}
|
||||
}
|
||||
case types.Wrr:
|
||||
@@ -700,7 +700,7 @@ func (server *Server) loadConfig(configurations configs, globalConfiguration Glo
|
||||
interval = time.Second * 30
|
||||
}
|
||||
}
|
||||
backendsHealthcheck[frontend.Backend] = healthcheck.NewBackendHealthCheck(configuration.Backends[frontend.Backend].HealthCheck.URL, interval, rr)
|
||||
backendsHealthcheck[frontend.Backend] = healthcheck.NewBackendHealthCheck(configuration.Backends[frontend.Backend].HealthCheck.Path, interval, rr)
|
||||
}
|
||||
}
|
||||
maxConns := configuration.Backends[frontend.Backend].MaxConn
|
||||
|
||||
+1
-1
@@ -39,7 +39,7 @@ type CircuitBreaker struct {
|
||||
|
||||
// HealthCheck holds HealthCheck configuration
|
||||
type HealthCheck struct {
|
||||
URL string `json:"url,omitempty"`
|
||||
Path string `json:"path,omitempty"`
|
||||
Interval string `json:"interval,omitempty"`
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user