fix(api,task-processor): Close shutdown drain gap and name container ports#533
Open
germangarces wants to merge 3 commits into
Open
fix(api,task-processor): Close shutdown drain gap and name container ports#533germangarces wants to merge 3 commits into
germangarces wants to merge 3 commits into
Conversation
Signed-off-by: germangarces <german.garces@flagsmith.com>
The api and task-processor container ports were unnamed, so any PodMonitoring (or other) resource referencing them by name (e.g. `port: http`) could not resolve them and silently scraped nothing. Name the existing container port `http`, and declare the Prometheus port 9100 as `prom` when `prometheus.enabled` is true. Service and ServiceMonitor resources are unaffected: both reference ports by numeric value or by the Service's own port name.
Comment on lines
+77
to
+85
| # Container lifecycle hooks. Default preStop delays SIGTERM so the | ||
| # LB / endpoints controller has time to deregister the pod before | ||
| # gunicorn closes its listen socket. Without this, rolling deploys | ||
| # and HPA scale-down can cause a short 5xx spike on traffic that | ||
| # the LB routes to the pod after it has stopped accepting connections. | ||
| lifecycle: | ||
| preStop: | ||
| exec: | ||
| command: ["sleep", "20"] |
Contributor
There was a problem hiding this comment.
I don't quite understand if we're describing the default or the custom exec command we've added here?
Member
Author
There was a problem hiding this comment.
We're talking about the custom command we've added. But I have rephrased it so is more understandable: 0210430
| # Pod termination grace period in seconds. Must exceed the LB's | ||
| # connection-draining timeout so the kubelet does not SIGKILL | ||
| # the pod while the LB is still draining in-flight connections. | ||
| terminationGracePeriodSeconds: 75 |
Contributor
There was a problem hiding this comment.
Why did we land on 75?
Member
Author
There was a problem hiding this comment.
20s preStop + 30s gunicorn default graceful worker shutdown + 25s for possible in-flight requests
Signed-off-by: germangarces <german.garces@flagsmith.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two small, independent fixes to the api and task-processor deployment templates.
1. Close shutdown drain gap
Default
terminationGracePeriodSecondsto 75 and addpreStop sleep 20on the API container. Lets the load balancer finish deregistering the pod before gunicorn stops accepting connections, so rolling deploys and HPA scale-downs no longer cause a brief 5xx spike.2. Name container ports
The api and task-processor container ports were unnamed. PodMonitoring resources that reference them by name (
port: httporport: prom) silently scraped nothing as a result. Adding names fixes that. Existing Service and ServiceMonitor resources are unaffected — they reference ports numerically or via the Service name.Contributes to Flagsmith/infrastructure#317