-
Notifications
You must be signed in to change notification settings - Fork 109
Add cc uploader configurable drain timeout #562
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3c4e87b
Add cc uploader configurable drain timeout
kathap ae3cd55
Add test for cc uploader drain script rendering
kathap 821b3d5
Rename timeout, remove double default assignement
kathap a2555de
fix time comparison
kathap 030c9d6
pass minutes as integer instead of go duration format
kathap 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 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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| LOG_FILE="/var/vcap/sys/log/cc_uploader/drain.log" | ||
| PID_FILE="/var/vcap/sys/run/bpm/cc_uploader/cc_uploader.pid" | ||
|
|
||
| TIMEOUT_MINUTES="<%= p("capi.cc_uploader.cc_uploader_drain_timeout_in_minutes") %>" | ||
|
|
||
| DRAIN_TIMEOUT_IN_SECONDS=$(( TIMEOUT_MINUTES * 60 )) | ||
| START_TS=$(date +%s) | ||
|
|
||
| echo "$(date): cc_uploader drain starting (timeout ${DRAIN_TIMEOUT_IN_SECONDS}s)" >> "$LOG_FILE" | ||
|
|
||
| if [ -f "$PID_FILE" ]; then | ||
| kill -TERM "$(cat "$PID_FILE")" | ||
| while kill -0 "$(cat "$PID_FILE")" >/dev/null 2>&1; do | ||
| NOW_TS=$(date +%s) | ||
| ELAPSED=$(( NOW_TS - START_TS )) | ||
| if [ "$ELAPSED" -ge "$DRAIN_TIMEOUT_IN_SECONDS" ]; then | ||
| echo "$(date): drain timeout reached after ${DRAIN_TIMEOUT_IN_SECONDS}s" >> "$LOG_FILE" | ||
| break | ||
| fi | ||
| echo "$(date): waiting for cc_uploader (elapsed ${ELAPSED}s)" >> "$LOG_FILE" | ||
| sleep 1 | ||
| done | ||
| fi | ||
|
|
||
| echo "$(date): drain complete, returning 0 to BOSH" >> "$LOG_FILE" | ||
| echo 0 | ||
| exit 0 | ||
|
|
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require 'rspec' | ||
| require 'bosh/template/test' | ||
| require 'yaml' | ||
| require 'json' | ||
|
|
||
| module Bosh | ||
| module Template | ||
| module Test | ||
| describe 'cc_uploader drain script rendering' do | ||
| let(:release_path) { File.join(File.dirname(__FILE__), '../..') } | ||
| let(:release) { ReleaseDir.new(release_path) } | ||
| let(:job) { release.job('cc_uploader') } | ||
| let(:template) { job.template('bin/drain') } | ||
|
|
||
| context 'when capi.cc_uploader.cc_uploader_drain_timeout_in_minutes is provided' do | ||
| let(:properties) do | ||
| { | ||
| 'capi' => { | ||
| 'cc_uploader' => { | ||
| 'cc_uploader_drain_timeout_in_minutes' => '10' | ||
| } | ||
| } | ||
| } | ||
| end | ||
|
|
||
| it 'renders the drain script with correct timeout' do | ||
| rendered = template.render(properties) | ||
| expect(rendered).to include('TIMEOUT_MINUTES="10"') | ||
| expect(rendered).to include('DRAIN_TIMEOUT_IN_SECONDS=$(( TIMEOUT_MINUTES * 60 ))') | ||
| end | ||
| end | ||
|
|
||
| context 'when capi.cc_uploader.cc_uploader_drain_timeout_in_minutes is not provided' do | ||
| it 'defaults to 15 minutes' do | ||
| rendered = template.render({}) | ||
| expect(rendered).to include('TIMEOUT_MINUTES="15"') | ||
| end | ||
| end | ||
|
|
||
| it 'writes logs to the expected log file' do | ||
| rendered = template.render({}) | ||
| expect(rendered).to include('LOG_FILE="/var/vcap/sys/log/cc_uploader/drain.log"') | ||
| end | ||
|
|
||
| it 'uses the correct PID file location' do | ||
| rendered = template.render({}) | ||
| expect(rendered).to include('PID_FILE="/var/vcap/sys/run/bpm/cc_uploader/cc_uploader.pid"') | ||
| end | ||
|
|
||
| it 'safely attempts to terminate the cc_uploader process' do | ||
| rendered = template.render({}) | ||
| expect(rendered).to include('kill -TERM "$(cat "$PID_FILE")"') | ||
| expect(rendered).to include('kill -0 "$(cat "$PID_FILE")"') | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end |
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.
Uh oh!
There was an error while loading. Please reload this page.