-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BGS Healthcheck Implementation (#2246)
* add draft healthcheck.rb * rm steps pending healthcheck implementation * implement healthcheck * wait for healthy containers * increase timeout * change grep query
- Loading branch information
Showing
5 changed files
with
54 additions
and
49 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,45 +60,8 @@ jobs: | |
# Quit after 60 seconds | ||
retries: 30 | ||
|
||
# Temporary step added to avoid race condition. Currently, there is no health check in 'svc-bgs-api'; therefore, | ||
# at this step, it is unknown if svc-bgs-api has yet to create the 'bgs-api' exchange. | ||
- name: 'Create bgs-api exchange' | ||
uses: indiesdev/[email protected] | ||
with: | ||
url: 'http://localhost:15672/api/exchanges/%2f/bgs-api' | ||
method: 'PUT' | ||
basic-auth-token: '${{env.RABBITMQ_BASIC_AUTH}}' | ||
body: '{"type":"direct", "durable":true, "auto_delete":true}' | ||
accept: 201, 204 | ||
retries: 3 | ||
log-response: true | ||
|
||
# Temporary step added to avoid race condition. Currently, there is no health check in 'svc-bgs-api'; therefore, | ||
# at this step, it is unknown if svc-bgs-api has yet to create the 'add-note' queue. | ||
- name: 'Create add-note queue' | ||
uses: indiesdev/[email protected] | ||
with: | ||
url: 'http://localhost:15672/api/queues/%2f/add-note' | ||
method: 'PUT' | ||
basic-auth-token: '${{env.RABBITMQ_BASIC_AUTH}}' | ||
body: '{"durable":true, "auto_delete":true}' | ||
accept: 201, 204 | ||
retries: 3 | ||
log-response: true | ||
|
||
# Temporary step added to avoid race condition. Currently, there is no health check in 'svc-bgs-api'; therefore, | ||
# at this step, it is unknown if svc-bgs-api has yet to create the binding from 'bgs-api' exchange to 'add-note' | ||
# queue. | ||
- name: 'Create binding for add-note queue to bgs-api exchange' | ||
uses: indiesdev/[email protected] | ||
with: | ||
url: 'http://localhost:15672/api/bindings/%2f/e/bgs-api/q/add-note' | ||
method: 'POST' | ||
basic-auth-token: '${{env.RABBITMQ_BASIC_AUTH}}' | ||
body: '{"routing_key":"add-note","arguments":{}}' | ||
accept: 201, 204 | ||
retries: 3 | ||
log-response: true | ||
- name: 'Check for healthy BGS container' | ||
run: timeout 180s sh -c 'until docker ps | grep ".*svc-bgs-api.*" | grep -q healthy; do echo "Waiting for container to be healthy..."; sleep 2; done' | ||
|
||
- name: 'Create add-note-response queue' | ||
uses: indiesdev/[email protected] | ||
|
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,15 @@ | ||
# Contains constant definitions for queues, exchanges, and fields | ||
|
||
BUNNY_ARGS = { | ||
host: ENV['RABBITMQ_PLACEHOLDERS_HOST'] || "localhost", | ||
user: ENV['RABBITMQ_USERNAME'] || "guest", | ||
password: ENV['RABBITMQ_PASSWORD'] || "guest" | ||
} | ||
|
||
CAMEL_MQ_PROPERTIES = { durable: true, auto_delete: true } | ||
|
||
BGS_EXCHANGE_NAME = "bgs-api" | ||
|
||
HEALTHCHECK_REPLY_QUEUE = "healthcheck-reply" | ||
HEALTHCHECK_QUEUE = "healthcheck" | ||
ADD_NOTE_QUEUE = "add-note" |
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,23 @@ | ||
# Inspired by the README at https://github.com/ruby-amqp/bunny | ||
|
||
require 'bunny' | ||
require 'json' | ||
|
||
require_relative '../config/constants' | ||
|
||
conn = Bunny.new(BUNNY_ARGS) | ||
conn.start | ||
|
||
ch = conn.create_channel | ||
x = ch.direct(BGS_EXCHANGE_NAME, CAMEL_MQ_PROPERTIES) | ||
|
||
r = ch.queue(HEALTHCHECK_REPLY_QUEUE, CAMEL_MQ_PROPERTIES).bind(x, :routing_key => HEALTHCHECK_REPLY_QUEUE) | ||
|
||
q = ch.queue(HEALTHCHECK_QUEUE, CAMEL_MQ_PROPERTIES).bind(x, :routing_key => HEALTHCHECK_QUEUE) | ||
q.publish('{"health": "check"}', :reply_to => HEALTHCHECK_REPLY_QUEUE) | ||
|
||
delivery_info, properties, payload = r.pop | ||
|
||
if JSON.parse(payload)["statusCode"] != 200 then | ||
raise "svc-bgs-api healthcheck failed" | ||
end |
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