Skip to content

Commit

Permalink
Add Failover service
Browse files Browse the repository at this point in the history
Co-authored-by: Kevin Pollet <pollet.kevin@gmail.com>
  • Loading branch information
tomMoulard and kevinpollet committed Mar 17, 2022
1 parent 6622027 commit 79aab5a
Show file tree
Hide file tree
Showing 12 changed files with 583 additions and 3 deletions.
6 changes: 6 additions & 0 deletions docs/content/reference/dynamic-configuration/file.toml
Expand Up @@ -95,6 +95,12 @@
secure = true
httpOnly = true
sameSite = "foobar"
[http.services.Service04]
[http.services.Service04.failover]
service = "foobar"
fallback = "foobar"

[http.services.Service04.failover.healthCheck]
[http.middlewares]
[http.middlewares.Middleware00]
[http.middlewares.Middleware00.addPrefix]
Expand Down
5 changes: 5 additions & 0 deletions docs/content/reference/dynamic-configuration/file.yaml
Expand Up @@ -95,6 +95,11 @@ http:
secure: true
httpOnly: true
sameSite: foobar
Service04:
failover:
service: foobar
fallback: foobar
healthCheck: {}
middlewares:
Middleware00:
addPrefix:
Expand Down
3 changes: 3 additions & 0 deletions docs/content/reference/dynamic-configuration/kv-ref.md
Expand Up @@ -228,6 +228,9 @@
| `traefik/http/services/Service03/weighted/sticky/cookie/name` | `foobar` |
| `traefik/http/services/Service03/weighted/sticky/cookie/sameSite` | `foobar` |
| `traefik/http/services/Service03/weighted/sticky/cookie/secure` | `true` |
| `traefik/http/services/Service04/failover/fallback` | `foobar` |
| `traefik/http/services/Service04/failover/healthCheck` | `` |
| `traefik/http/services/Service04/failover/service` | `foobar` |
| `traefik/tcp/middlewares/Middleware00/ipWhiteList/sourceRange/0` | `foobar` |
| `traefik/tcp/middlewares/Middleware00/ipWhiteList/sourceRange/1` | `foobar` |
| `traefik/tcp/routers/TCPRouter0/entryPoints/0` | `foobar` |
Expand Down
133 changes: 133 additions & 0 deletions docs/content/routing/services/index.md
Expand Up @@ -1212,6 +1212,139 @@ http:
url = "http://private-ip-server-2/"
```

### Failover (service)

A failover service job is to forward all requests to a fallback service when the main service becomes unreachable.

!!! info "Relation to HealthCheck"

The failover service relies on the HealthCheck system to get notified when its main service becomes unreachable,
which means HealthCheck needs to be enabled and functional on the main service.
However, HealthCheck does not need to be enabled on the failover service itself for it to be functional.
It is only required in order to propagate upwards the information when the failover itself becomes down
(i.e. both its main and its fallback are down too).

!!! info "Supported Providers"

This strategy can currently only be defined with the [File](../../providers/file.md) provider.

```yaml tab="YAML"
## Dynamic configuration
http:
services:
app:
failover:
service: main
fallback: backup

main:
loadBalancer:
healthCheck:
path: /status
interval: 10s
timeout: 3s
servers:
- url: "http://private-ip-server-1/"

backup:
loadBalancer:
servers:
- url: "http://private-ip-server-2/"
```

```toml tab="TOML"
## Dynamic configuration
[http.services]
[http.services.app]
[http.services.app.failover]
service = "main"
fallback = "backup"

[http.services.main]
[http.services.main.loadBalancer]
[http.services.main.loadBalancer.healthCheck]
path = "/health"
interval = "10s"
timeout = "3s"
[[http.services.main.loadBalancer.servers]]
url = "http://private-ip-server-1/"

[http.services.backup]
[http.services.backup.loadBalancer]
[[http.services.backup.loadBalancer.servers]]
url = "http://private-ip-server-2/"
```

#### Health Check

HealthCheck enables automatic self-healthcheck for this service,
i.e. if the main and the fallback services become unreachable,
the information is propagated upwards to its parent.

!!! info "All or nothing"

If HealthCheck is enabled for a given service, but any of its descendants does
not have it enabled, the creation of the service will fail.

HealthCheck on a Failover service can currently only be defined with the [File](../../providers/file.md) provider.

```yaml tab="YAML"
## Dynamic configuration
http:
services:
app:
failover:
healthCheck: {}
service: main
fallback: backup

main:
loadBalancer:
healthCheck:
path: /status
interval: 10s
timeout: 3s
servers:
- url: "http://private-ip-server-1/"

backup:
loadBalancer:
healthCheck:
path: /status
interval: 10s
timeout: 3s
servers:
- url: "http://private-ip-server-2/"
```

```toml tab="TOML"
## Dynamic configuration
[http.services]
[http.services.app]
[http.services.app.failover.healthCheck]
[http.services.app.failover]
service = "main"
fallback = "backup"

[http.services.main]
[http.services.main.loadBalancer]
[http.services.main.loadBalancer.healthCheck]
path = "/health"
interval = "10s"
timeout = "3s"
[[http.services.main.loadBalancer.servers]]
url = "http://private-ip-server-1/"

[http.services.backup]
[http.services.backup.loadBalancer]
[http.services.backup.loadBalancer.healthCheck]
path = "/health"
interval = "10s"
timeout = "3s"
[[http.services.backup.loadBalancer.servers]]
url = "http://private-ip-server-2/"
```

## Configuring TCP Services

### General
Expand Down
12 changes: 11 additions & 1 deletion pkg/config/dynamic/http_config.go
Expand Up @@ -35,6 +35,7 @@ type Service struct {
LoadBalancer *ServersLoadBalancer `json:"loadBalancer,omitempty" toml:"loadBalancer,omitempty" yaml:"loadBalancer,omitempty" export:"true"`
Weighted *WeightedRoundRobin `json:"weighted,omitempty" toml:"weighted,omitempty" yaml:"weighted,omitempty" label:"-" export:"true"`
Mirroring *Mirroring `json:"mirroring,omitempty" toml:"mirroring,omitempty" yaml:"mirroring,omitempty" label:"-" export:"true"`
Failover *Failover `json:"failover,omitempty" toml:"failover,omitempty" yaml:"failover,omitempty" label:"-" export:"true"`
}

// +k8s:deepcopy-gen=true
Expand Down Expand Up @@ -76,6 +77,15 @@ func (m *Mirroring) SetDefaults() {

// +k8s:deepcopy-gen=true

// Failover holds the Failover configuration.
type Failover struct {
Service string `json:"service,omitempty" toml:"service,omitempty" yaml:"service,omitempty" export:"true"`
Fallback string `json:"fallback,omitempty" toml:"fallback,omitempty" yaml:"fallback,omitempty" export:"true"`
HealthCheck *HealthCheck `json:"healthCheck,omitempty" toml:"healthCheck,omitempty" yaml:"healthCheck,omitempty" label:"allowEmpty" file:"allowEmpty" export:"true"`
}

// +k8s:deepcopy-gen=true

// MirrorService holds the MirrorService configuration.
type MirrorService struct {
Name string `json:"name,omitempty" toml:"name,omitempty" yaml:"name,omitempty" export:"true"`
Expand All @@ -98,7 +108,7 @@ type WeightedRoundRobin struct {

// +k8s:deepcopy-gen=true

// WRRService is a reference to a service load-balanced with weighted round robin.
// WRRService is a reference to a service load-balanced with weighted round-robin.
type WRRService struct {
Name string `json:"name,omitempty" toml:"name,omitempty" yaml:"name,omitempty" export:"true"`
Weight *int `json:"weight,omitempty" toml:"weight,omitempty" yaml:"weight,omitempty" export:"true"`
Expand Down
26 changes: 26 additions & 0 deletions pkg/config/dynamic/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions pkg/provider/kv/kv_test.go
Expand Up @@ -69,6 +69,8 @@ func Test_buildConfiguration(t *testing.T) {
"traefik/http/services/Service03/weighted/services/0/weight": "42",
"traefik/http/services/Service03/weighted/services/1/name": "foobar",
"traefik/http/services/Service03/weighted/services/1/weight": "42",
"traefik/http/services/Service04/failover/service": "foobar",
"traefik/http/services/Service04/failover/fallback": "foobar",
"traefik/http/middlewares/Middleware08/forwardAuth/authResponseHeaders/0": "foobar",
"traefik/http/middlewares/Middleware08/forwardAuth/authResponseHeaders/1": "foobar",
"traefik/http/middlewares/Middleware08/forwardAuth/authRequestHeaders/0": "foobar",
Expand Down Expand Up @@ -688,6 +690,12 @@ func Test_buildConfiguration(t *testing.T) {
},
},
},
"Service04": {
Failover: &dynamic.Failover{
Service: "foobar",
Fallback: "foobar",
},
},
},
},
TCP: &dynamic.TCPConfiguration{
Expand Down

0 comments on commit 79aab5a

Please sign in to comment.