From d4ad4259e6dbfa6c0ee38cfd44010e0dbfa5d436 Mon Sep 17 00:00:00 2001 From: binoue Date: Sun, 27 Dec 2020 18:35:38 +0900 Subject: [PATCH] internal/envoy/v3/bootstrap: Make configurble about keepalive settings This change allows users to tune envoy's keepalive settings. Fixes #2652 Fixes #3214 Signed-off-by: binoue --- cmd/contour/bootstrap.go | 3 +++ internal/envoy/bootstrap.go | 25 +++++++++++++++++++++++++ internal/envoy/v3/bootstrap.go | 6 +++--- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/cmd/contour/bootstrap.go b/cmd/contour/bootstrap.go index 82e03e48517..cf1324ae66b 100644 --- a/cmd/contour/bootstrap.go +++ b/cmd/contour/bootstrap.go @@ -35,5 +35,8 @@ func registerBootstrap(app *kingpin.Application) (*kingpin.CmdClause, *envoy.Boo bootstrap.Flag("envoy-key-file", "Client key filename for Envoy secure xDS gRPC communication.").Envar("ENVOY_KEY_FILE").StringVar(&config.GrpcClientKey) bootstrap.Flag("namespace", "The namespace the Envoy container will run in.").Envar("CONTOUR_NAMESPACE").Default("projectcontour").StringVar(&config.Namespace) bootstrap.Flag("xds-resource-version", "The versions of the xDS resources to request from Contour.").Default("v3").StringVar((*string)(&config.XDSResourceVersion)) + bootstrap.Flag("tcp-keepalive-probe", "Maximum number of keepalive probes to send without response.").Uint32Var(&config.KeepaliveProbe) + bootstrap.Flag("tcp-keepalive-time", "The number of seconds a connection needs to be idle before keep-alive probes start being sent.").Uint32Var(&config.KeepaliveTime) + bootstrap.Flag("tcp-keepalive-interval", "The number of seconds between keep-alive probes.").Uint32Var(&config.KeepaliveInterval) return bootstrap, &config } diff --git a/internal/envoy/bootstrap.go b/internal/envoy/bootstrap.go index f229878687a..bbd441107f5 100644 --- a/internal/envoy/bootstrap.go +++ b/internal/envoy/bootstrap.go @@ -84,6 +84,15 @@ type BootstrapConfig struct { // referenced in the configuration actually exist. This option is for // testing only. SkipFilePathCheck bool + + // KeepaliveProbe is the maximum number of keepalive probes to send without response. + KeepaliveProbe uint32 + + // KeepaliveTime is the number of seconds a connection needs to be idle before keep-alive probes start being sent. + KeepaliveTime uint32 + + // KeepaliveInterval is the number of seconds between keep-alive probes. + KeepaliveInterval uint32 } func (c *BootstrapConfig) GetXdsAddress() string { return stringOrDefault(c.XDSAddress, "127.0.0.1") } @@ -95,6 +104,15 @@ func (c *BootstrapConfig) GetAdminPort() int { return intOrDefault(c.AdminPort, func (c *BootstrapConfig) GetAdminAccessLogPath() string { return stringOrDefault(c.AdminAccessLogPath, "/dev/null") } +func (c *BootstrapConfig) GetKeepaliveProbe() uint32 { + return uint32OrDefault(c.KeepaliveProbe, 3) +} +func (c *BootstrapConfig) GetKeepaliveTime() uint32 { + return uint32OrDefault(c.KeepaliveTime, 30) +} +func (c *BootstrapConfig) GetKeepaliveInterval() uint32 { + return uint32OrDefault(c.KeepaliveInterval, 5) +} func stringOrDefault(s, def string) string { if s == "" { @@ -110,6 +128,13 @@ func intOrDefault(i, def int) int { return i } +func uint32OrDefault(i, def uint32) uint32 { + if i == 0 { + return def + } + return i +} + func WriteConfig(filename string, config proto.Message) (err error) { var out *os.File diff --git a/internal/envoy/v3/bootstrap.go b/internal/envoy/v3/bootstrap.go index 58516b3ec6e..ac5d1992a50 100644 --- a/internal/envoy/v3/bootstrap.go +++ b/internal/envoy/v3/bootstrap.go @@ -168,9 +168,9 @@ func bootstrapConfig(c *envoy.BootstrapConfig) *envoy_bootstrap_v3.Bootstrap { }, UpstreamConnectionOptions: &envoy_cluster_v3.UpstreamConnectionOptions{ TcpKeepalive: &envoy_core_v3.TcpKeepalive{ - KeepaliveProbes: protobuf.UInt32(3), - KeepaliveTime: protobuf.UInt32(30), - KeepaliveInterval: protobuf.UInt32(5), + KeepaliveProbes: protobuf.UInt32(c.GetKeepaliveProbe()), + KeepaliveTime: protobuf.UInt32(c.GetKeepaliveTime()), + KeepaliveInterval: protobuf.UInt32(c.GetKeepaliveInterval()), }, }, Http2ProtocolOptions: new(envoy_core_v3.Http2ProtocolOptions), // enables http2