1
0
Fork 0

Add unhealthy Interval to the health check configuration

This commit is contained in:
Swastik Sarkar 2025-04-09 13:40:05 +05:30 committed by GitHub
parent 6c3b099c25
commit d7d0017545
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
36 changed files with 701 additions and 295 deletions

View file

@ -9,6 +9,7 @@ import (
"strings"
"github.com/rs/zerolog/log"
ptypes "github.com/traefik/paerser/types"
"github.com/traefik/traefik/v3/pkg/config/dynamic"
"github.com/traefik/traefik/v3/pkg/logs"
"github.com/traefik/traefik/v3/pkg/provider"
@ -373,6 +374,17 @@ func (c configBuilder) buildServersLB(namespace string, svc traefikv1alpha1.Load
return nil, err
}
}
// If the UnhealthyInterval option is not set, we use the Interval option value,
// to check the unhealthy targets as often as the healthy ones.
if svc.HealthCheck.UnhealthyInterval == nil {
lb.HealthCheck.UnhealthyInterval = &lb.HealthCheck.Interval
} else {
var unhealthyInterval ptypes.Duration
if err := unhealthyInterval.Set(svc.HealthCheck.UnhealthyInterval.String()); err != nil {
return nil, err
}
lb.HealthCheck.UnhealthyInterval = &unhealthyInterval
}
if svc.HealthCheck.Timeout != nil {
if err := lb.HealthCheck.Timeout.Set(svc.HealthCheck.Timeout.String()); err != nil {
return nil, err

View file

@ -2647,10 +2647,11 @@ func TestLoadIngressRoutes(t *testing.T) {
FlushInterval: ptypes.Duration(100 * time.Millisecond),
},
HealthCheck: &dynamic.ServerHealthCheck{
Path: "/health",
Timeout: 5000000000,
Interval: 15000000000,
FollowRedirects: pointer(true),
Path: "/health",
Timeout: 5000000000,
Interval: 15000000000,
UnhealthyInterval: pointer(ptypes.Duration(15000000000)),
FollowRedirects: pointer(true),
},
},
},
@ -2712,10 +2713,11 @@ func TestLoadIngressRoutes(t *testing.T) {
FlushInterval: ptypes.Duration(100 * time.Millisecond),
},
HealthCheck: &dynamic.ServerHealthCheck{
Path: "/health1",
Timeout: 5000000000,
Interval: 15000000000,
FollowRedirects: pointer(true),
Path: "/health1",
Timeout: 5000000000,
Interval: 15000000000,
UnhealthyInterval: pointer(ptypes.Duration(15000000000)),
FollowRedirects: pointer(true),
},
},
},
@ -2732,10 +2734,11 @@ func TestLoadIngressRoutes(t *testing.T) {
FlushInterval: ptypes.Duration(100 * time.Millisecond),
},
HealthCheck: &dynamic.ServerHealthCheck{
Path: "/health2",
Timeout: 5000000000,
Interval: 20000000000,
FollowRedirects: pointer(true),
Path: "/health2",
Timeout: 5000000000,
Interval: 20000000000,
UnhealthyInterval: pointer(ptypes.Duration(20000000000)),
FollowRedirects: pointer(true),
},
},
},
@ -2776,10 +2779,11 @@ func TestLoadIngressRoutes(t *testing.T) {
FlushInterval: ptypes.Duration(100 * time.Millisecond),
},
HealthCheck: &dynamic.ServerHealthCheck{
Path: "/health1",
Timeout: 5000000000,
Interval: 15000000000,
FollowRedirects: pointer(true),
Path: "/health1",
Timeout: 5000000000,
Interval: 15000000000,
UnhealthyInterval: pointer(ptypes.Duration(15000000000)),
FollowRedirects: pointer(true),
},
},
},

View file

@ -170,9 +170,13 @@ type ServerHealthCheck struct {
Status int `json:"status,omitempty"`
// Port defines the server URL port for the health check endpoint.
Port int `json:"port,omitempty"`
// Interval defines the frequency of the health check calls.
// Interval defines the frequency of the health check calls for healthy targets.
// Default: 30s
Interval *intstr.IntOrString `json:"interval,omitempty"`
// UnhealthyInterval defines the frequency of the health check calls for unhealthy targets.
// When UnhealthyInterval is not defined, it defaults to the Interval value.
// Default: 30s
UnhealthyInterval *intstr.IntOrString `json:"unhealthyInterval,omitempty"`
// Timeout defines the maximum duration Traefik will wait for a health check request before considering the server unhealthy.
// Default: 5s
Timeout *intstr.IntOrString `json:"timeout,omitempty"`

View file

@ -1280,6 +1280,11 @@ func (in *ServerHealthCheck) DeepCopyInto(out *ServerHealthCheck) {
*out = new(intstr.IntOrString)
**out = **in
}
if in.UnhealthyInterval != nil {
in, out := &in.UnhealthyInterval, &out.UnhealthyInterval
*out = new(intstr.IntOrString)
**out = **in
}
if in.Timeout != nil {
in, out := &in.Timeout, &out.Timeout
*out = new(intstr.IntOrString)