Skip to content

Commit

Permalink
Add XDS keepalives (#1747)
Browse files Browse the repository at this point in the history
* Add XDS keepalives

Fixes #1746

Signed-off-by: Jack Kleeman <[email protected]>

* Use instead http2 keepalives

Signed-off-by: Jack Kleeman <[email protected]>

* Permit keepalives on server side

Signed-off-by: Jack Kleeman <[email protected]>

---------

Signed-off-by: Jack Kleeman <[email protected]>
  • Loading branch information
jackkleeman authored Aug 9, 2023
1 parent 85a2db8 commit 6b8268f
Show file tree
Hide file tree
Showing 22 changed files with 101 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@
"clusters": [
{
"connectTimeout": "10s",
"http2ProtocolOptions": {
"connectionKeepalive": {
"interval": "30s",
"timeout": "5s"
}
},
"loadAssignment": {
"clusterName": "xds_cluster",
"endpoints": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ xds:
staticResources:
clusters:
- connectTimeout: 10s
http2ProtocolOptions:
connectionKeepalive:
interval: 30s
timeout: 5s
loadAssignment:
clusterName: xds_cluster
endpoints:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ xds:
staticResources:
clusters:
- connectTimeout: 10s
http2ProtocolOptions:
connectionKeepalive:
interval: 30s
timeout: 5s
loadAssignment:
clusterName: xds_cluster
endpoints:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ envoyProxy:
http2_protocol_options: {}
name: xds_cluster
type: STRICT_DNS
http2_protocol_options:
connection_keepalive:
interval: 30s
timeout: 5s
transport_socket:
name: envoy.transport_sockets.tls
typed_config:
Expand Down Expand Up @@ -460,6 +464,10 @@ xds:
staticResources:
clusters:
- connectTimeout: 10s
http2ProtocolOptions:
connectionKeepalive:
interval: 30s
timeout: 5s
loadAssignment:
clusterName: xds_cluster
endpoints:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ xds:
staticResources:
clusters:
- connectTimeout: 10s
http2ProtocolOptions:
connectionKeepalive:
interval: 30s
timeout: 5s
loadAssignment:
clusterName: xds_cluster
endpoints:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@
"clusters": [
{
"connectTimeout": "10s",
"http2ProtocolOptions": {
"connectionKeepalive": {
"interval": "30s",
"timeout": "5s"
}
},
"loadAssignment": {
"clusterName": "xds_cluster",
"endpoints": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ xds:
staticResources:
clusters:
- connectTimeout: 10s
http2ProtocolOptions:
connectionKeepalive:
interval: 30s
timeout: 5s
loadAssignment:
clusterName: xds_cluster
endpoints:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ xds:
staticResources:
clusters:
- connectTimeout: 10s
http2ProtocolOptions:
connectionKeepalive:
interval: 30s
timeout: 5s
loadAssignment:
clusterName: xds_cluster
endpoints:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@
"clusters": [
{
"connectTimeout": "10s",
"http2ProtocolOptions": {
"connectionKeepalive": {
"interval": "30s",
"timeout": "5s"
}
},
"loadAssignment": {
"clusterName": "xds_cluster",
"endpoints": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ xds:
staticResources:
clusters:
- connectTimeout: 10s
http2ProtocolOptions:
connectionKeepalive:
interval: 30s
timeout: 5s
loadAssignment:
clusterName: xds_cluster
endpoints:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ xds:
staticResources:
clusters:
- connectTimeout: 10s
http2ProtocolOptions:
connectionKeepalive:
interval: 30s
timeout: 5s
loadAssignment:
clusterName: xds_cluster
endpoints:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ spec:
http2_protocol_options: {}
name: xds_cluster
type: STRICT_DNS
http2_protocol_options:
connection_keepalive:
interval: 30s
timeout: 5s
transport_socket:
name: envoy.transport_sockets.tls
typed_config:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ spec:
http2_protocol_options: {}
name: xds_cluster
type: STRICT_DNS
http2_protocol_options:
connection_keepalive:
interval: 30s
timeout: 5s
transport_socket:
name: envoy.transport_sockets.tls
typed_config:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ spec:
http2_protocol_options: {}
name: xds_cluster
type: STRICT_DNS
http2_protocol_options:
connection_keepalive:
interval: 30s
timeout: 5s
transport_socket:
name: envoy.transport_sockets.tls
typed_config:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ spec:
http2_protocol_options: {}
name: xds_cluster
type: STRICT_DNS
http2_protocol_options:
connection_keepalive:
interval: 30s
timeout: 5s
transport_socket:
name: envoy.transport_sockets.tls
typed_config:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ spec:
http2_protocol_options: {}
name: xds_cluster
type: STRICT_DNS
http2_protocol_options:
connection_keepalive:
interval: 30s
timeout: 5s
transport_socket:
name: envoy.transport_sockets.tls
typed_config:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ spec:
http2_protocol_options: {}
name: xds_cluster
type: STRICT_DNS
http2_protocol_options:
connection_keepalive:
interval: 30s
timeout: 5s
transport_socket:
name: envoy.transport_sockets.tls
typed_config:
Expand Down
4 changes: 4 additions & 0 deletions internal/xds/bootstrap/bootstrap.yaml.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ static_resources:
http2_protocol_options: {}
name: xds_cluster
type: STRICT_DNS
http2_protocol_options:
connection_keepalive:
interval: 30s
timeout: 5s
transport_socket:
name: envoy.transport_sockets.tls
typed_config:
Expand Down
4 changes: 4 additions & 0 deletions internal/xds/bootstrap/testdata/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ static_resources:
http2_protocol_options: {}
name: xds_cluster
type: STRICT_DNS
http2_protocol_options:
connection_keepalive:
interval: 30s
timeout: 5s
transport_socket:
name: envoy.transport_sockets.tls
typed_config:
Expand Down
4 changes: 4 additions & 0 deletions internal/xds/bootstrap/testdata/enable-prometheus.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ static_resources:
http2_protocol_options: {}
name: xds_cluster
type: STRICT_DNS
http2_protocol_options:
connection_keepalive:
interval: 30s
timeout: 5s
transport_socket:
name: envoy.transport_sockets.tls
typed_config:
Expand Down
4 changes: 4 additions & 0 deletions internal/xds/bootstrap/testdata/otel-metrics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ static_resources:
http2_protocol_options: {}
name: xds_cluster
type: STRICT_DNS
http2_protocol_options:
connection_keepalive:
interval: 30s
timeout: 5s
transport_socket:
name: envoy.transport_sockets.tls
typed_config:
Expand Down
8 changes: 7 additions & 1 deletion internal/xds/server/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import (
"net"
"os"
"strconv"
"time"

"google.golang.org/grpc/keepalive"

clusterv3 "github.com/envoyproxy/go-control-plane/envoy/service/cluster/v3"
discoveryv3 "github.com/envoyproxy/go-control-plane/envoy/service/discovery/v3"
Expand Down Expand Up @@ -75,7 +78,10 @@ func (r *Runner) Start(ctx context.Context) error {
// Create SnapshotCache before start subscribeAndTranslate,
// prevent panics in case cache is nil.
cfg := r.tlsConfig(xdsTLSCertFilename, xdsTLSKeyFilename, xdsTLSCaFilename)
r.grpc = grpc.NewServer(grpc.Creds(credentials.NewTLS(cfg)))
r.grpc = grpc.NewServer(grpc.Creds(credentials.NewTLS(cfg)), grpc.KeepaliveEnforcementPolicy(keepalive.EnforcementPolicy{
MinTime: 15 * time.Second,
PermitWithoutStream: true,
}))

r.cache = cache.NewSnapshotCache(false, r.Logger)
registerServer(serverv3.NewServer(ctx, r.cache, r.cache), r.grpc)
Expand Down

0 comments on commit 6b8268f

Please sign in to comment.