Skip to content

Commit

Permalink
Change l4 healthcheck timeout
Browse files Browse the repository at this point in the history
According to l4 healthcheck constants
the default set up has timeout = 8 seconds
and threshold = 3 times. As result it can
lead to 24 (8*3) seconds of lost requests.
This change is supposed to decrease this
time to only 6 seconds for sharedHc=false.

Signed-off-by: Elina Akhmanova <elinka@google.com>
  • Loading branch information
code-elinka committed Oct 3, 2022
1 parent 0d703c9 commit 0367e93
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 32 deletions.
29 changes: 22 additions & 7 deletions pkg/healthchecksl4/healthchecksl4.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,13 @@ import (

const (
// L4 Load Balancer parameters
gceHcCheckIntervalSeconds = int64(8)
gceHcTimeoutSeconds = int64(1)
gceSharedHcCheckIntervalSeconds = int64(8) // Shared Health check Interval
gceLocalHcCheckIntervalSeconds = int64(3) // Local Health check Interval
gceHcTimeoutSeconds = int64(1)
// Start sending requests as soon as one healthcheck succeeds.
gceHcHealthyThreshold = int64(1)
// Defaults to 3 * 8 = 24 seconds before the LB will steer traffic away.
gceHcUnhealthyThreshold = int64(3)
gceHcHealthyThreshold = int64(1)
gceSharedHcUnhealthyThreshold = int64(3) // 3 * 8 = 24 seconds before the LB will steer traffic away
gceLocalHcUnhealthyThreshold = int64(2) // 2 * 3 = 6 seconds before the LB will steer traffic away
)

var (
Expand Down Expand Up @@ -302,12 +303,26 @@ func newL4HealthCheck(name string, svcName types.NamespacedName, shared bool, pa
if err != nil {
klog.Warningf("Failed to generate description for L4HealthCheck %s, err %v", name, err)
}

// Default time for LB to move the traffic differs for shared/local external traffic policies
var (
hcCheckIntervalSeconds int64
hcUnhealthyThreshold int64
)
if shared {
hcCheckIntervalSeconds = gceSharedHcCheckIntervalSeconds
hcUnhealthyThreshold = gceSharedHcUnhealthyThreshold
} else {
hcCheckIntervalSeconds = gceLocalHcCheckIntervalSeconds
hcUnhealthyThreshold = gceLocalHcUnhealthyThreshold
}

return &composite.HealthCheck{
Name: name,
CheckIntervalSec: gceHcCheckIntervalSeconds,
CheckIntervalSec: hcCheckIntervalSeconds,
TimeoutSec: gceHcTimeoutSeconds,
HealthyThreshold: gceHcHealthyThreshold,
UnhealthyThreshold: gceHcUnhealthyThreshold,
UnhealthyThreshold: hcUnhealthyThreshold,
HttpHealthCheck: &httpSettings,
Type: "HTTP",
Description: desc,
Expand Down
88 changes: 63 additions & 25 deletions pkg/healthchecksl4/healthchecksl4_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func TestMergeHealthChecks(t *testing.T) {
t.Parallel()
for _, tc := range []struct {
desc string
shared bool
checkIntervalSec int64
timeoutSec int64
healthyThreshold int64
Expand All @@ -38,19 +39,24 @@ func TestMergeHealthChecks(t *testing.T) {
wantHealthyThreshold int64
wantUnhealthyThreshold int64
}{
{"unchanged", gceHcCheckIntervalSeconds, gceHcTimeoutSeconds, gceHcHealthyThreshold, gceHcUnhealthyThreshold, gceHcCheckIntervalSeconds, gceHcTimeoutSeconds, gceHcHealthyThreshold, gceHcUnhealthyThreshold},
{"interval - too small - should reconcile", gceHcCheckIntervalSeconds - 1, gceHcTimeoutSeconds, gceHcHealthyThreshold, gceHcUnhealthyThreshold, gceHcCheckIntervalSeconds, gceHcTimeoutSeconds, gceHcHealthyThreshold, gceHcUnhealthyThreshold},
{"timeout - too small - should reconcile", gceHcCheckIntervalSeconds, gceHcTimeoutSeconds - 1, gceHcHealthyThreshold, gceHcUnhealthyThreshold, gceHcCheckIntervalSeconds, gceHcTimeoutSeconds, gceHcHealthyThreshold, gceHcUnhealthyThreshold},
{"healthy threshold - too small - should reconcile", gceHcCheckIntervalSeconds, gceHcTimeoutSeconds, gceHcHealthyThreshold - 1, gceHcUnhealthyThreshold, gceHcCheckIntervalSeconds, gceHcTimeoutSeconds, gceHcHealthyThreshold, gceHcUnhealthyThreshold},
{"unhealthy threshold - too small - should reconcile", gceHcCheckIntervalSeconds, gceHcTimeoutSeconds, gceHcHealthyThreshold, gceHcUnhealthyThreshold - 1, gceHcCheckIntervalSeconds, gceHcTimeoutSeconds, gceHcHealthyThreshold, gceHcUnhealthyThreshold},
{"interval - user configured - should keep", gceHcCheckIntervalSeconds + 1, gceHcTimeoutSeconds, gceHcHealthyThreshold, gceHcUnhealthyThreshold, gceHcCheckIntervalSeconds + 1, gceHcTimeoutSeconds, gceHcHealthyThreshold, gceHcUnhealthyThreshold},
{"timeout - user configured - should keep", gceHcCheckIntervalSeconds, gceHcTimeoutSeconds + 1, gceHcHealthyThreshold, gceHcUnhealthyThreshold, gceHcCheckIntervalSeconds, gceHcTimeoutSeconds + 1, gceHcHealthyThreshold, gceHcUnhealthyThreshold},
{"healthy threshold - user configured - should keep", gceHcCheckIntervalSeconds, gceHcTimeoutSeconds, gceHcHealthyThreshold + 1, gceHcUnhealthyThreshold, gceHcCheckIntervalSeconds, gceHcTimeoutSeconds, gceHcHealthyThreshold + 1, gceHcUnhealthyThreshold},
{"unhealthy threshold - user configured - should keep", gceHcCheckIntervalSeconds, gceHcTimeoutSeconds, gceHcHealthyThreshold, gceHcUnhealthyThreshold + 1, gceHcCheckIntervalSeconds, gceHcTimeoutSeconds, gceHcHealthyThreshold, gceHcUnhealthyThreshold + 1},
{"unchanged (sharedHc)", true, gceSharedHcCheckIntervalSeconds, gceHcTimeoutSeconds, gceHcHealthyThreshold, gceSharedHcUnhealthyThreshold, gceSharedHcCheckIntervalSeconds, gceHcTimeoutSeconds, gceHcHealthyThreshold, gceSharedHcUnhealthyThreshold},
{"unchanged (localHc)", false, gceLocalHcCheckIntervalSeconds, gceHcTimeoutSeconds, gceHcHealthyThreshold, gceLocalHcUnhealthyThreshold, gceLocalHcCheckIntervalSeconds, gceHcTimeoutSeconds, gceHcHealthyThreshold, gceLocalHcUnhealthyThreshold},
{"interval - too small - should reconcile (sharedHc)", true, gceSharedHcCheckIntervalSeconds - 1, gceHcTimeoutSeconds, gceHcHealthyThreshold, gceSharedHcUnhealthyThreshold, gceSharedHcCheckIntervalSeconds, gceHcTimeoutSeconds, gceHcHealthyThreshold, gceSharedHcUnhealthyThreshold},
{"interval - too small - should reconcile (localHc)", false, gceLocalHcCheckIntervalSeconds - 1, gceHcTimeoutSeconds, gceHcHealthyThreshold, gceLocalHcUnhealthyThreshold, gceLocalHcCheckIntervalSeconds, gceHcTimeoutSeconds, gceHcHealthyThreshold, gceLocalHcUnhealthyThreshold},
{"timeout - too small - should reconcile (sharedHc)", true, gceSharedHcCheckIntervalSeconds, gceHcTimeoutSeconds - 1, gceHcHealthyThreshold, gceSharedHcUnhealthyThreshold, gceSharedHcCheckIntervalSeconds, gceHcTimeoutSeconds, gceHcHealthyThreshold, gceSharedHcUnhealthyThreshold},
{"healthy threshold - too small - should reconcile (sharedHc)", true, gceSharedHcCheckIntervalSeconds, gceHcTimeoutSeconds, gceHcHealthyThreshold - 1, gceSharedHcUnhealthyThreshold, gceSharedHcCheckIntervalSeconds, gceHcTimeoutSeconds, gceHcHealthyThreshold, gceSharedHcUnhealthyThreshold},
{"unhealthy threshold - too small - should reconcile (sharedHc)", true, gceSharedHcCheckIntervalSeconds, gceHcTimeoutSeconds, gceHcHealthyThreshold, gceSharedHcUnhealthyThreshold - 1, gceSharedHcCheckIntervalSeconds, gceHcTimeoutSeconds, gceHcHealthyThreshold, gceSharedHcUnhealthyThreshold},
{"unhealthy threshold - too small - should reconcile (localHc)", false, gceLocalHcCheckIntervalSeconds, gceHcTimeoutSeconds, gceHcHealthyThreshold, gceLocalHcUnhealthyThreshold - 1, gceLocalHcCheckIntervalSeconds, gceHcTimeoutSeconds, gceHcHealthyThreshold, gceLocalHcUnhealthyThreshold},
{"interval - user configured - should keep (sharedHc)", true, gceSharedHcCheckIntervalSeconds + 1, gceHcTimeoutSeconds, gceHcHealthyThreshold, gceSharedHcUnhealthyThreshold, gceSharedHcCheckIntervalSeconds + 1, gceHcTimeoutSeconds, gceHcHealthyThreshold, gceSharedHcUnhealthyThreshold},
{"interval - user configured - should keep (localHc)", false, gceLocalHcCheckIntervalSeconds + 1, gceHcTimeoutSeconds, gceHcHealthyThreshold, gceLocalHcUnhealthyThreshold, gceLocalHcCheckIntervalSeconds + 1, gceHcTimeoutSeconds, gceHcHealthyThreshold, gceLocalHcUnhealthyThreshold},
{"timeout - user configured - should keep", true, gceSharedHcCheckIntervalSeconds, gceHcTimeoutSeconds + 1, gceHcHealthyThreshold, gceSharedHcUnhealthyThreshold, gceSharedHcCheckIntervalSeconds, gceHcTimeoutSeconds + 1, gceHcHealthyThreshold, gceSharedHcUnhealthyThreshold},
{"healthy threshold - user configured - should keep (sharedHc)", true, gceSharedHcCheckIntervalSeconds, gceHcTimeoutSeconds, gceHcHealthyThreshold + 1, gceSharedHcUnhealthyThreshold, gceSharedHcCheckIntervalSeconds, gceHcTimeoutSeconds, gceHcHealthyThreshold + 1, gceSharedHcUnhealthyThreshold},
{"unhealthy threshold - user configured - should keep (sharedHc)", true, gceSharedHcCheckIntervalSeconds, gceHcTimeoutSeconds, gceHcHealthyThreshold, gceSharedHcUnhealthyThreshold + 1, gceSharedHcCheckIntervalSeconds, gceHcTimeoutSeconds, gceHcHealthyThreshold, gceSharedHcUnhealthyThreshold + 1},
{"unhealthy threshold - user configured - should keep (localHc)", false, gceLocalHcCheckIntervalSeconds, gceHcTimeoutSeconds, gceHcHealthyThreshold, gceLocalHcUnhealthyThreshold + 1, gceLocalHcCheckIntervalSeconds, gceHcTimeoutSeconds, gceHcHealthyThreshold, gceLocalHcUnhealthyThreshold + 1},
} {
t.Run(tc.desc, func(t *testing.T) {
// healthcheck intervals and thresholds are common for Global and Regional healthchecks. Hence testing only Global case.
wantHC := newL4HealthCheck("hc", types.NamespacedName{Name: "svc", Namespace: "default"}, false, "/", 12345, utils.ILB, meta.Global, "")
wantHC := newL4HealthCheck("hc", types.NamespacedName{Name: "svc", Namespace: "default"}, tc.shared, "/", 12345, utils.ILB, meta.Global, "")
hc := &composite.HealthCheck{
CheckIntervalSec: tc.checkIntervalSec,
TimeoutSec: tc.timeoutSec,
Expand Down Expand Up @@ -78,27 +84,33 @@ func TestCompareHealthChecks(t *testing.T) {
t.Parallel()
for _, tc := range []struct {
desc string
shared bool
modifier func(*composite.HealthCheck)
wantChanged bool
}{
{"unchanged", nil, false},
{"nil HttpHealthCheck", func(hc *composite.HealthCheck) { hc.HttpHealthCheck = nil }, true},
{"desc does not match", func(hc *composite.HealthCheck) { hc.Description = "bad-desc" }, true},
{"port does not match", func(hc *composite.HealthCheck) { hc.HttpHealthCheck.Port = 54321 }, true},
{"requestPath does not match", func(hc *composite.HealthCheck) { hc.HttpHealthCheck.RequestPath = "/anotherone" }, true},
{"interval needs update", func(hc *composite.HealthCheck) { hc.CheckIntervalSec = gceHcCheckIntervalSeconds - 1 }, true},
{"timeout needs update", func(hc *composite.HealthCheck) { hc.TimeoutSec = gceHcTimeoutSeconds - 1 }, true},
{"healthy threshold needs update", func(hc *composite.HealthCheck) { hc.HealthyThreshold = gceHcHealthyThreshold - 1 }, true},
{"unhealthy threshold needs update", func(hc *composite.HealthCheck) { hc.UnhealthyThreshold = gceHcUnhealthyThreshold - 1 }, true},
{"interval does not need update", func(hc *composite.HealthCheck) { hc.CheckIntervalSec = gceHcCheckIntervalSeconds + 1 }, false},
{"timeout does not need update", func(hc *composite.HealthCheck) { hc.TimeoutSec = gceHcTimeoutSeconds + 1 }, false},
{"healthy threshold does not need update", func(hc *composite.HealthCheck) { hc.HealthyThreshold = gceHcHealthyThreshold + 1 }, false},
{"unhealthy threshold does not need update", func(hc *composite.HealthCheck) { hc.UnhealthyThreshold = gceHcUnhealthyThreshold + 1 }, false},
{"unchanged (sharedHc)", true, nil, false},
{"unchanged (localHc)", false, nil, false},
{"nil HttpHealthCheck (sharedHc)", true, func(hc *composite.HealthCheck) { hc.HttpHealthCheck = nil }, true},
{"desc does not match (sharedHc)", true, func(hc *composite.HealthCheck) { hc.Description = "bad-desc" }, true},
{"port does not match (sharedHc)", true, func(hc *composite.HealthCheck) { hc.HttpHealthCheck.Port = 54321 }, true},
{"requestPath does not match (sharedHc)", true, func(hc *composite.HealthCheck) { hc.HttpHealthCheck.RequestPath = "/anotherone" }, true},
{"interval needs update (sharedHc)", true, func(hc *composite.HealthCheck) { hc.CheckIntervalSec = gceSharedHcCheckIntervalSeconds - 1 }, true},
{"interval needs update (localHc)", false, func(hc *composite.HealthCheck) { hc.CheckIntervalSec = gceLocalHcCheckIntervalSeconds - 1 }, true},
{"timeout needs update (sharedHc)", true, func(hc *composite.HealthCheck) { hc.TimeoutSec = gceHcTimeoutSeconds - 1 }, true},
{"healthy threshold needs update (sharedHc)", true, func(hc *composite.HealthCheck) { hc.HealthyThreshold = gceHcHealthyThreshold - 1 }, true},
{"unhealthy threshold needs update (sharedHc)", true, func(hc *composite.HealthCheck) { hc.UnhealthyThreshold = gceSharedHcUnhealthyThreshold - 1 }, true},
{"unhealthy threshold needs update (localHc)", false, func(hc *composite.HealthCheck) { hc.UnhealthyThreshold = gceLocalHcUnhealthyThreshold - 1 }, true},
{"interval does not need update (sharedHc)", true, func(hc *composite.HealthCheck) { hc.CheckIntervalSec = gceSharedHcCheckIntervalSeconds + 1 }, false},
{"interval does not need update (localHc)", false, func(hc *composite.HealthCheck) { hc.CheckIntervalSec = gceLocalHcCheckIntervalSeconds + 1 }, false},
{"timeout does not need update (sharedHc)", true, func(hc *composite.HealthCheck) { hc.TimeoutSec = gceHcTimeoutSeconds + 1 }, false},
{"healthy threshold does not need update (sharedHc)", true, func(hc *composite.HealthCheck) { hc.HealthyThreshold = gceHcHealthyThreshold + 1 }, false},
{"unhealthy threshold does not need update (sharedHc)", true, func(hc *composite.HealthCheck) { hc.UnhealthyThreshold = gceSharedHcUnhealthyThreshold + 1 }, false},
{"unhealthy threshold does not need update (localHc)", false, func(hc *composite.HealthCheck) { hc.UnhealthyThreshold = gceLocalHcUnhealthyThreshold + 1 }, false},
} {
t.Run(tc.desc, func(t *testing.T) {
// healthcheck intervals and thresholds are common for Global and Regional healthchecks. Hence testing only Global case.
hc := newL4HealthCheck("hc", types.NamespacedName{Name: "svc", Namespace: "default"}, false, "/", 12345, utils.ILB, meta.Global, "")
wantHC := newL4HealthCheck("hc", types.NamespacedName{Name: "svc", Namespace: "default"}, false, "/", 12345, utils.ILB, meta.Global, "")
hc := newL4HealthCheck("hc", types.NamespacedName{Name: "svc", Namespace: "default"}, tc.shared, "/", 12345, utils.ILB, meta.Global, "")
wantHC := newL4HealthCheck("hc", types.NamespacedName{Name: "svc", Namespace: "default"}, tc.shared, "/", 12345, utils.ILB, meta.Global, "")
if tc.modifier != nil {
tc.modifier(hc)
}
Expand All @@ -109,6 +121,32 @@ func TestCompareHealthChecks(t *testing.T) {
}
}

// Checks that correct health check constants used for different traffic policies types (local/shared)
func TestSharedHealthChecks(t *testing.T) {
t.Parallel()
for _, tc := range []struct {
desc string
shared bool
wantCheckIntervalSec int64
wantUnhealthyThreshold int64
}{
{"shared", true, gceSharedHcCheckIntervalSeconds, gceSharedHcUnhealthyThreshold},
{"local", false, gceLocalHcCheckIntervalSeconds, gceLocalHcUnhealthyThreshold},
} {
t.Run(tc.desc, func(t *testing.T) {
// healthcheck intervals and thresholds are common for Global and Regional healthchecks. Hence testing only Global case.
gotHC := newL4HealthCheck("hc", types.NamespacedName{Name: "svc", Namespace: "default"}, tc.shared, "/", 12345, utils.ILB, meta.Global, "")

if gotHC.CheckIntervalSec != tc.wantCheckIntervalSec {
t.Errorf("gotHC.CheckIntervalSec = %d; want %d", gotHC.CheckIntervalSec, tc.wantCheckIntervalSec)
}
if gotHC.UnhealthyThreshold != tc.wantUnhealthyThreshold {
t.Errorf("gotHC.UnhealthyThreshold = %d; want %d", gotHC.UnhealthyThreshold, tc.wantUnhealthyThreshold)
}
})
}
}

func TestNewHealthCheck(t *testing.T) {
t.Parallel()
namespaceName := types.NamespacedName{Name: "svc", Namespace: "default"}
Expand Down

0 comments on commit 0367e93

Please sign in to comment.