-
Notifications
You must be signed in to change notification settings - Fork 13
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
add whisper to autoscaler #652
Open
rpurdel
wants to merge
5
commits into
main
Choose a base branch
from
add-whisper-to-autoscaler-role
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
86c0812
add whisper to autoscaler
rpurdel 475f562
Renamed the role to whisper
rpurdel b3146a9
fix state url host
aaronkvanmeerten d6cac1e
updates just because
aaronkvanmeerten 5dfedc8
support cloud_instance_id var in autoscaler-sidecar
aaronkvanmeerten File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
- name: Copy graceful shutdown script | ||
ansible.builtin.template: | ||
src: whisper-graceful-shutdown.sh.j2 | ||
dest: /usr/local/bin/whisper-graceful-shutdown.sh | ||
mode: 0755 | ||
owner: root |
48 changes: 48 additions & 0 deletions
48
ansible/roles/whisper/templates/whisper-graceful-shutdown.sh.j2
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Sets the server to drain mode and waits for all the connections to be closed before exiting | ||
# with code 0 (clean shutdown). If the connections are not closed within the specified time, | ||
# the script will exit with code 1 (dirty) and the autoscaler will shut down the instance anyway. | ||
|
||
# It takes two parameters: WAIT_SECONDS and STATE_URL | ||
# WAIT_SECONDS: Seconds to wait for the server to enter drain mode and close all connections. | ||
# Defaults to 100. | ||
# STATE_URL: The URL of the whisper state endpoint. Defaults to http://localhost:8003/state. | ||
|
||
# Example usage: ./shutdown_script.sh 100 http://<local ip>:8003/state | ||
|
||
|
||
WAIT_SECONDS=100 | ||
STATE_URL="http://{{ ansible_default_ipv4.address }}:8003/state" | ||
|
||
[[ -z $1 ]] && echo "Parameter WAIT_SECONDS not set, using default $WAIT_SECONDS" || WAIT_SECONDS=$1 | ||
[[ -z $2 ]] && echo "Parameter STATE_URL not set, using default $STATE_URL" || STATE_URL=$2 | ||
|
||
echo "Waiting for $WAIT_SECONDS seconds for the server to enter drain mode and close all connections." | ||
|
||
START_TIME=$(date +%s) | ||
|
||
while true; do | ||
RESPONSE=$(curl -s $STATE_URL) | ||
WHISPER_STATE=$(echo $RESPONSE | jq -r '.state') | ||
ACTIVE_CONNECTIONS=$(echo $RESPONSE | jq -r '.connections') | ||
if [[ $WHISPER_STATE != "drain" ]]; then | ||
echo "Setting server in drain mode." | ||
curl -s -XPOST $STATE_URL -d '{"state": "drain"}' | jq -r '.request_status' | ||
else | ||
echo "Server is in drain mode. Waiting for $ACTIVE_CONNECTIONS connections to be closed before shutting down" | ||
if [[ $ACTIVE_CONNECTIONS -eq 0 ]]; then | ||
echo "All connections are closed. Shutting down the instance." | ||
exit 0 | ||
fi | ||
fi | ||
CURRENT_TIME=$(date +%s) | ||
ELAPSED_TIME=$((CURRENT_TIME - START_TIME)) | ||
if [[ $ELAPSED_TIME -gt $WAIT_SECONDS ]]; then | ||
break | ||
fi | ||
sleep 2 | ||
done | ||
|
||
echo "Server did not close all connections within $WAIT_SECONDS seconds. Shutting down anyway." | ||
exit 1 |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is totally unrelated and will breake existing deployments if it's not supported in live whisper.