Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(kds): allow to delay full resync when ticker #7782

Merged
merged 1 commit into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/generated/kuma-cp.md
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,8 @@ experimental:
flushInterval: 5s # ENV: KUMA_EXPERIMENTAL_KDS_EVENT_BASED_WATCHDOG_FLUSH_INTERVAL
# How often we schedule full KDS resync when experimental event based watchdog is used.
fullResyncInterval: 60s # ENV: KUMA_EXPERIMENTAL_KDS_EVENT_BASED_WATCHDOG_FULL_RESYNC_INTERVAL
# If true, then initial full resync is going to be delayed by 0 to FullResyncInterval.
delayFullResync: false # ENV: KUMA_EXPERIMENTAL_KDS_EVENT_BASED_WATCHDOG_DELAY_FULL_RESYNC

proxy:
gateway:
Expand Down
2 changes: 2 additions & 0 deletions docs/generated/raw/kuma-cp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,8 @@ experimental:
flushInterval: 5s # ENV: KUMA_EXPERIMENTAL_KDS_EVENT_BASED_WATCHDOG_FLUSH_INTERVAL
# How often we schedule full KDS resync when experimental event based watchdog is used.
fullResyncInterval: 60s # ENV: KUMA_EXPERIMENTAL_KDS_EVENT_BASED_WATCHDOG_FULL_RESYNC_INTERVAL
# If true, then initial full resync is going to be delayed by 0 to FullResyncInterval.
delayFullResync: false # ENV: KUMA_EXPERIMENTAL_KDS_EVENT_BASED_WATCHDOG_DELAY_FULL_RESYNC

proxy:
gateway:
Expand Down
3 changes: 3 additions & 0 deletions pkg/config/app/kuma-cp/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ var DefaultConfig = func() Config {
Enabled: false,
FlushInterval: config_types.Duration{Duration: 5 * time.Second},
FullResyncInterval: config_types.Duration{Duration: 1 * time.Minute},
DelayFullResync: false,
},
},
Proxy: xds.DefaultProxyConfig(),
Expand Down Expand Up @@ -408,6 +409,8 @@ type ExperimentalKDSEventBasedWatchdog struct {
FlushInterval config_types.Duration `json:"flushInterval" envconfig:"KUMA_EXPERIMENTAL_KDS_EVENT_BASED_WATCHDOG_FLUSH_INTERVAL"`
// How often we schedule full KDS resync when experimental event based watchdog is used.
FullResyncInterval config_types.Duration `json:"fullResyncInterval" envconfig:"KUMA_EXPERIMENTAL_KDS_EVENT_BASED_WATCHDOG_FULL_RESYNC_INTERVAL"`
// If true, then initial full resync is going to be delayed by 0 to FullResyncInterval.
DelayFullResync bool `json:"delayFullResync" envconfig:"KUMA_EXPERIMENTAL_KDS_EVENT_BASED_WATCHDOG_DELAY_FULL_RESYNC"`
}

func (e ExperimentalConfig) Validate() error {
Expand Down
2 changes: 2 additions & 0 deletions pkg/config/app/kuma-cp/kuma-cp.defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,8 @@ experimental:
flushInterval: 5s # ENV: KUMA_EXPERIMENTAL_KDS_EVENT_BASED_WATCHDOG_FLUSH_INTERVAL
# How often we schedule full KDS resync when experimental event based watchdog is used.
fullResyncInterval: 60s # ENV: KUMA_EXPERIMENTAL_KDS_EVENT_BASED_WATCHDOG_FULL_RESYNC_INTERVAL
# If true, then initial full resync is going to be delayed by 0 to FullResyncInterval.
delayFullResync: false # ENV: KUMA_EXPERIMENTAL_KDS_EVENT_BASED_WATCHDOG_DELAY_FULL_RESYNC

proxy:
gateway:
Expand Down
3 changes: 3 additions & 0 deletions pkg/config/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ var _ = Describe("Config loader", func() {
Expect(cfg.Experimental.KDSEventBasedWatchdog.Enabled).To(BeTrue())
Expect(cfg.Experimental.KDSEventBasedWatchdog.FlushInterval.Duration).To(Equal(10 * time.Second))
Expect(cfg.Experimental.KDSEventBasedWatchdog.FullResyncInterval.Duration).To(Equal(15 * time.Second))
Expect(cfg.Experimental.KDSEventBasedWatchdog.DelayFullResync).To(BeTrue())

Expect(cfg.Proxy.Gateway.GlobalDownstreamMaxConnections).To(BeNumerically("==", 1))
Expect(cfg.EventBus.BufferSize).To(Equal(uint(30)))
Expand Down Expand Up @@ -682,6 +683,7 @@ experimental:
enabled: true
flushInterval: 10s
fullResyncInterval: 15s
delayFullResync: true
proxy:
gateway:
globalDownstreamMaxConnections: 1
Expand Down Expand Up @@ -933,6 +935,7 @@ eventBus:
"KUMA_EXPERIMENTAL_KDS_EVENT_BASED_WATCHDOG_ENABLED": "true",
"KUMA_EXPERIMENTAL_KDS_EVENT_BASED_WATCHDOG_FLUSH_INTERVAL": "10s",
"KUMA_EXPERIMENTAL_KDS_EVENT_BASED_WATCHDOG_FULL_RESYNC_INTERVAL": "15s",
"KUMA_EXPERIMENTAL_KDS_EVENT_BASED_WATCHDOG_DELAY_FULL_RESYNC": "true",
"KUMA_PROXY_GATEWAY_GLOBAL_DOWNSTREAM_MAX_CONNECTIONS": "1",
"KUMA_TRACING_OPENTELEMETRY_ENDPOINT": "otel-collector:4317",
"KUMA_EVENT_BUS_BUFFER_SIZE": "30",
Expand Down
18 changes: 17 additions & 1 deletion pkg/kds/v2/server/components.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package server

import (
"context"
"math/rand"
"time"

envoy_core "github.com/envoyproxy/go-control-plane/envoy/config/core/v3"
Expand Down Expand Up @@ -104,7 +105,22 @@ func newSyncTracker(
return time.NewTicker(experimentalWatchdogCfg.FlushInterval.Duration)
},
NewFullResyncTicker: func() *time.Ticker {
return time.NewTicker(experimentalWatchdogCfg.FullResyncInterval.Duration)
if experimentalWatchdogCfg.DelayFullResync {
// To ensure an even distribution of connections over time, we introduce a random delay within
// the full resync interval. This prevents clustering connections within a short timeframe
// and spreads them evenly across the entire interval. After the initial trigger, we reset
// the ticker, returning it to its full resync interval.
// #nosec G404 - math rand is enough
delay := time.Duration(experimentalWatchdogCfg.FullResyncInterval.Duration.Seconds()*rand.Float64()) * time.Second
ticker := time.NewTicker(experimentalWatchdogCfg.FullResyncInterval.Duration + delay)
go func() {
<-time.After(delay)
ticker.Reset(experimentalWatchdogCfg.FullResyncInterval.Duration)
}()
return ticker
} else {
return time.NewTicker(experimentalWatchdogCfg.FullResyncInterval.Duration)
}
},
}, nil
}
Expand Down