Skip to content

Commit

Permalink
fix: Switch to an immediate drain strategy (#4230)
Browse files Browse the repository at this point in the history
Switch to a immediate drain strategy

* Ensures clients immediately receive a `connection: close` / `GOAWAY`
instead of a probabilistic approach of receiving one b/w drain start and
drain end (defaults to 600s). This should speed up shutdown with clients
reconnecting to newer upgraded proxies.

Fixes: #4205

Signed-off-by: Arko Dasgupta <[email protected]>
  • Loading branch information
arkodg committed Sep 13, 2024
1 parent 6b8e37a commit 14f687f
Show file tree
Hide file tree
Showing 163 changed files with 42 additions and 178 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -923,7 +923,6 @@ xds:
statPrefix: http-10080
useRemoteAddress: true
name: default/eg/http
drainType: MODIFY_ONLY
name: default/eg/http
perConnectionBufferLimitBytes: 32768
- activeState:
Expand Down Expand Up @@ -991,7 +990,6 @@ xds:
statPrefix: http-8080
useRemoteAddress: true
name: default/eg/grpc
drainType: MODIFY_ONLY
name: default/eg/grpc
perConnectionBufferLimitBytes: 32768
- activeState:
Expand All @@ -1014,7 +1012,6 @@ xds:
socketAddress:
address: 0.0.0.0
portValue: 1234
drainType: MODIFY_ONLY
filterChains:
- filters:
- name: envoy.filters.network.tcp_proxy
Expand Down Expand Up @@ -1054,7 +1051,6 @@ xds:
socketAddress:
address: 0.0.0.0
portValue: 8443
drainType: MODIFY_ONLY
filterChains:
- filterChainMatch:
serverNames:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,6 @@
],
"name": "default/eg/http"
},
"drainType": "MODIFY_ONLY",
"name": "default/eg/http",
"perConnectionBufferLimitBytes": 32768
}
Expand Down Expand Up @@ -797,7 +796,6 @@
],
"name": "default/eg/grpc"
},
"drainType": "MODIFY_ONLY",
"name": "default/eg/grpc",
"perConnectionBufferLimitBytes": 32768
}
Expand Down Expand Up @@ -834,7 +832,6 @@
"portValue": 1234
}
},
"drainType": "MODIFY_ONLY",
"filterChains": [
{
"filters": [
Expand Down Expand Up @@ -900,7 +897,6 @@
"portValue": 8443
}
},
"drainType": "MODIFY_ONLY",
"filterChains": [
{
"filterChainMatch": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,6 @@ xds:
statPrefix: http-10080
useRemoteAddress: true
name: default/eg/http
drainType: MODIFY_ONLY
name: default/eg/http
perConnectionBufferLimitBytes: 32768
- activeState:
Expand Down Expand Up @@ -472,7 +471,6 @@ xds:
statPrefix: http-8080
useRemoteAddress: true
name: default/eg/grpc
drainType: MODIFY_ONLY
name: default/eg/grpc
perConnectionBufferLimitBytes: 32768
- activeState:
Expand All @@ -495,7 +493,6 @@ xds:
socketAddress:
address: 0.0.0.0
portValue: 1234
drainType: MODIFY_ONLY
filterChains:
- filters:
- name: envoy.filters.network.tcp_proxy
Expand Down Expand Up @@ -535,7 +532,6 @@ xds:
socketAddress:
address: 0.0.0.0
portValue: 8443
drainType: MODIFY_ONLY
filterChains:
- filterChainMatch:
serverNames:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ xds:
statPrefix: http-10080
useRemoteAddress: true
name: default/eg/http
drainType: MODIFY_ONLY
name: default/eg/http
perConnectionBufferLimitBytes: 32768
- activeState:
Expand Down Expand Up @@ -127,7 +126,6 @@ xds:
statPrefix: http-8080
useRemoteAddress: true
name: default/eg/grpc
drainType: MODIFY_ONLY
name: default/eg/grpc
perConnectionBufferLimitBytes: 32768
- activeState:
Expand All @@ -150,7 +148,6 @@ xds:
socketAddress:
address: 0.0.0.0
portValue: 1234
drainType: MODIFY_ONLY
filterChains:
- filters:
- name: envoy.filters.network.tcp_proxy
Expand Down Expand Up @@ -190,7 +187,6 @@ xds:
socketAddress:
address: 0.0.0.0
portValue: 8443
drainType: MODIFY_ONLY
filterChains:
- filterChainMatch:
serverNames:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,6 @@
],
"name": "envoy-gateway-system/eg/http"
},
"drainType": "MODIFY_ONLY",
"name": "envoy-gateway-system/eg/http",
"perConnectionBufferLimitBytes": 32768
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,6 @@ xds:
statPrefix: http-10080
useRemoteAddress: true
name: envoy-gateway-system/eg/http
drainType: MODIFY_ONLY
name: envoy-gateway-system/eg/http
perConnectionBufferLimitBytes: 32768
- '@type': type.googleapis.com/envoy.admin.v3.RoutesConfigDump
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,5 @@ xds:
statPrefix: http-10080
useRemoteAddress: true
name: envoy-gateway-system/eg/http
drainType: MODIFY_ONLY
name: envoy-gateway-system/eg/http
perConnectionBufferLimitBytes: 32768
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,6 @@ xds:
statPrefix: http-10080
useRemoteAddress: true
name: envoy-gateway-system/eg/http
drainType: MODIFY_ONLY
name: envoy-gateway-system/eg/http
perConnectionBufferLimitBytes: 32768
- '@type': type.googleapis.com/envoy.admin.v3.RoutesConfigDump
Expand Down
13 changes: 4 additions & 9 deletions internal/cmd/envoy/shutdown_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func shutdownReadyHandler(w http.ResponseWriter, readyTimeout time.Duration, rea
}

// Shutdown is called from a preStop hook on the shutdown-manager container where
// it will initiate a graceful drain sequence on the Envoy proxy and block until
// it will initiate a drain sequence on the Envoy proxy and block until
// connections are drained or a timeout is exceeded.
func Shutdown(drainTimeout time.Duration, minDrainDuration time.Duration, exitAtConnections int) error {
startTime := time.Now()
Expand All @@ -125,19 +125,14 @@ func Shutdown(drainTimeout time.Duration, minDrainDuration time.Duration, exitAt
logger = logging.FileLogger("/proc/1/fd/1", "shutdown-manager", egv1a1.LogLevelInfo)
}

logger.Info(fmt.Sprintf("initiating graceful drain with %.0f second minimum drain period and %.0f second timeout",
logger.Info(fmt.Sprintf("initiating drain with %.0f second minimum drain period and %.0f second timeout",
minDrainDuration.Seconds(), drainTimeout.Seconds()))

// Start failing active health checks
if err := postEnvoyAdminAPI("healthcheck/fail"); err != nil {
logger.Error(err, "error failing active health checks")
}

// Initiate graceful drain sequence
if err := postEnvoyAdminAPI("drain_listeners?graceful&skip_exit"); err != nil {
logger.Error(err, "error initiating graceful drain")
}

// Poll total connections from Envoy admin API until minimum drain period has
// been reached and total connections reaches threshold or timeout is exceeded
for {
Expand All @@ -154,10 +149,10 @@ func Shutdown(drainTimeout time.Duration, minDrainDuration time.Duration, exitAt
}

if elapsedTime > drainTimeout {
logger.Info("graceful drain sequence timeout exceeded")
logger.Info("drain sequence timeout exceeded")
break
} else if allowedToExit && conn != nil && *conn <= exitAtConnections {
logger.Info("graceful drain sequence completed")
logger.Info("drain sequence completed")
break
}

Expand Down
1 change: 1 addition & 0 deletions internal/infrastructure/kubernetes/proxy/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ func expectedProxyContainers(infra *ir.ProxyInfra,
fmt.Sprintf("--config-yaml %s", bootstrapConfigurations),
fmt.Sprintf("--log-level %s", logging.DefaultEnvoyProxyLoggingLevel()),
"--cpuset-threads",
"--drain-strategy immediate",
}

if infra.Config != nil &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ spec:
- --config-yaml test bootstrap config
- --log-level error
- --cpuset-threads
- --drain-strategy immediate
- --component-log-level filter:info
command:
- envoy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ spec:
value: 0.98
- --log-level warn
- --cpuset-threads
- --drain-strategy immediate
command:
- envoy
env:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ spec:
value: 0.98
- --log-level warn
- --cpuset-threads
- --drain-strategy immediate
command:
- envoy
env:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ spec:
max_active_downstream_connections: 50000
- --log-level warn
- --cpuset-threads
- --drain-strategy immediate
command:
- envoy
env:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ spec:
max_active_downstream_connections: 50000
- --log-level warn
- --cpuset-threads
- --drain-strategy immediate
command:
- envoy
env:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ spec:
value: 0.98
- --log-level warn
- --cpuset-threads
- --drain-strategy immediate
command:
- envoy
env:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ spec:
max_active_downstream_connections: 50000
- --log-level warn
- --cpuset-threads
- --drain-strategy immediate
command:
- envoy
env:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ spec:
max_active_downstream_connections: 50000
- --log-level warn
- --cpuset-threads
- --drain-strategy immediate
command:
- envoy
env:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ spec:
max_active_downstream_connections: 50000
- --log-level warn
- --cpuset-threads
- --drain-strategy immediate
- --drain-time-s 30
command:
- envoy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ spec:
value: 0.98
- --log-level warn
- --cpuset-threads
- --drain-strategy immediate
command:
- envoy
env:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ spec:
max_active_downstream_connections: 50000
- --log-level warn
- --cpuset-threads
- --drain-strategy immediate
command:
- envoy
env:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ spec:
- --config-yaml test bootstrap config
- --log-level warn
- --cpuset-threads
- --drain-strategy immediate
- --concurrency 4
command:
- envoy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ spec:
max_active_downstream_connections: 50000
- --log-level warn
- --cpuset-threads
- --drain-strategy immediate
- --key1 val1
- --key2 val2
command:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ spec:
max_active_downstream_connections: 50000
- --log-level warn
- --cpuset-threads
- --drain-strategy immediate
command:
- envoy
env:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ spec:
max_active_downstream_connections: 50000
- --log-level warn
- --cpuset-threads
- --drain-strategy immediate
command:
- envoy
env:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ spec:
max_active_downstream_connections: 50000
- --log-level warn
- --cpuset-threads
- --drain-strategy immediate
command:
- envoy
env:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ spec:
max_active_downstream_connections: 50000
- --log-level warn
- --cpuset-threads
- --drain-strategy immediate
command:
- envoy
env:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ spec:
- --config-yaml test bootstrap config
- --log-level warn
- --cpuset-threads
- --drain-strategy immediate
command:
- envoy
env:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ spec:
- --config-yaml test bootstrap config
- --log-level error
- --cpuset-threads
- --drain-strategy immediate
- --component-log-level filter:info
command:
- envoy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ spec:
value: 0.98
- --log-level warn
- --cpuset-threads
- --drain-strategy immediate
command:
- envoy
env:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ spec:
value: 0.98
- --log-level warn
- --cpuset-threads
- --drain-strategy immediate
command:
- envoy
env:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ spec:
value: 0.98
- --log-level warn
- --cpuset-threads
- --drain-strategy immediate
command:
- envoy
env:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ spec:
max_active_downstream_connections: 50000
- --log-level warn
- --cpuset-threads
- --drain-strategy immediate
command:
- envoy
env:
Expand Down
Loading

0 comments on commit 14f687f

Please sign in to comment.