Skip to content
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

PLAT-200 jsr config importing #44

Merged
merged 31 commits into from
Apr 28, 2022
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
626a66d
Introduce config-importing service
Mark-Labuschagne Apr 14, 2022
c001db6
Update JSR to use new config importing strategy
Mark-Labuschagne Apr 14, 2022
bd07458
Add config compose file and base export file
Mark-Labuschagne Apr 14, 2022
2b933c4
Remove unnecessary code from compose file
Mark-Labuschagne Apr 14, 2022
f139632
Code changes to swarm.sh
Mark-Labuschagne Apr 14, 2022
505e1b4
Update JSR to remove config importer and configs
Mark-Labuschagne Apr 14, 2022
37a94fd
Introduce timeout check as library
Mark-Labuschagne Apr 19, 2022
d487ae9
Update config::timeout_check docs
Mark-Labuschagne Apr 19, 2022
9bdc2f1
Remove config importer service from platform
Mark-Labuschagne Apr 19, 2022
0de61d7
Add SSL env var to .env.dev
Mark-Labuschagne Apr 19, 2022
24ef18f
Update SSL default value
Mark-Labuschagne Apr 19, 2022
397c271
Update SSL env var name
Mark-Labuschagne Apr 20, 2022
25d69d2
Remove missed testing code
Mark-Labuschagne Apr 20, 2022
906e216
Update config importer compose file
Mark-Labuschagne Apr 21, 2022
4b6b71a
Update docker-compose.config.yml
Mark-Labuschagne Apr 21, 2022
3e8d0f4
Updated default value for SSL env var
Mark-Labuschagne Apr 21, 2022
21afae4
Added default values for timeout_check
Mark-Labuschagne Apr 21, 2022
c4d19f3
Update default times for timeout_check
Mark-Labuschagne Apr 21, 2022
0fadd38
Update defaults for timeout_check
Mark-Labuschagne Apr 22, 2022
c7f9e9a
Removed overriding values for timeout_check
Mark-Labuschagne Apr 22, 2022
f3de70b
Fixed documentation for timeout_check
Mark-Labuschagne Apr 22, 2022
4a37fbe
Updated package-metadata.json for jsreport
Mark-Labuschagne Apr 25, 2022
3cfa3be
Updated JSR-config-importer image tag
Mark-Labuschagne Apr 25, 2022
c0c2255
Update metadata.json file in JSR
Mark-Labuschagne Apr 25, 2022
22d8054
Updated variable name to match env vars
Mark-Labuschagne Apr 26, 2022
9512b9a
Update vars names to match
Mark-Labuschagne Apr 26, 2022
0befd53
Update compose file
Mark-Labuschagne Apr 26, 2022
323db1a
Update JSR env vars
Mark-Labuschagne Apr 26, 2022
4d30fe1
Merge branch 'main' into PLAT-200-jsr-config-importing
tumbledwyer Apr 26, 2022
b64b8bc
Corrected mispelling of ES package
Mark-Labuschagne Apr 28, 2022
b82bcb1
Updated package-metadata.json to include correct name
Mark-Labuschagne Apr 28, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .env.dev
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,11 @@ LS_JAVA_OPTS=-Xmx2g -Xms2g

JS_REPORT_INSTANCES=1
JS_REPORT=dev_password_only
JS_REPORT_USERNAME=admin
JS_REPORT_SECRET=dev_secret_only
JS_REPORT_CPU_LIMIT=0.3
JS_REPORT_CPU_RESERVE=0.15
JS_REPORT_MEMORY_LIMIT=6G
JS_REPORT_MEMORY_RESERVE=2G
JS_REPORT_SSL=true
JS_REPORT_CONFIG_FILE=export.jsrexport
10 changes: 10 additions & 0 deletions dashboard-visualiser-jsreport/docker-compose.await-helper.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: '3.9'

services:
await-helper:
image: jembi/await-helper:1.0.0
deploy:
replicas: 1
restart_policy:
condition: none
command: 'http://dashboard-visualiser-jsreport:5488/'
6 changes: 3 additions & 3 deletions dashboard-visualiser-jsreport/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ services:
replicas: ${JS_REPORT_INSTANCES:-1}
resources:
limits:
cpus: ${JS_REPORT_CPU_LIMIT:-0.25}
memory: ${JS_REPORT_MEMORY_LIMIT:-4G}
cpus: ${JS_REPORT_CPU_LIMIT:-0.15}
memory: ${JS_REPORT_MEMORY_LIMIT:-3G}
reservations:
cpus: ${JS_REPORT_CPU_RESERVE:-0.1}
cpus: ${JS_REPORT_CPU_RESERVE:-0.05}
memory: ${JS_REPORT_MEMORY_RESERVE:-1G}
labels:
co.elastic.metrics/module: 'docker'
Expand Down
29 changes: 29 additions & 0 deletions dashboard-visualiser-jsreport/importer/docker-compose.config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
version: '3.9'

services:
jsreport-config-importer:
# TODO: Update image to use published version of jembi/config-importer
CastelloG marked this conversation as resolved.
Show resolved Hide resolved
image: jembi/api-config-importer:latest
environment:
SERVICE_NAME: 'dashboard-visualiser-jsreport'
SERVICE_API_PORT: 5488
API_USERNAME: ${JS_REPORT_USERNAME:-admin}
API_PASSWORD: ${JS_REPORT:-dev_password_only}
SSL: ${JS_REPORT_SSL:-true}
API_PATH: '/api/import'
MIME_TYPE: 'multipart/form-data'
CONFIG_FILE: ${JS_REPORT_CONFIG_FILE:-export.jsrexport}
deploy:
replicas: 1
restart_policy:
condition: none
configs:
- source: JSR-export.jsrexport
target: /export.jsrexport

configs:
JSR-export.jsrexport:
file: ./export.jsrexport
name: JSR-export.jsrexport-${JSR_export_jsrexport_DIGEST:?err}
labels:
name: jsreport
Binary file not shown.
19 changes: 12 additions & 7 deletions dashboard-visualiser-jsreport/package-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@
"description": "A dashboard to interpret data from ElasticSearch data store",
"type": "infrastructure",
"version": "v0.0.1",
"dependencies": [],
"dependencies": ["analytics-datastore-elasticsearch"],
tumbledwyer marked this conversation as resolved.
Show resolved Hide resolved
"environmentVariables": {
"allowLocalFilesAccess": "true",
"extensions_authentication_cookieSession_secret": "${JS_REPORT_SECRET:-dev_secret_only}",
"extensions_authentication_admin_username": "admin",
"extensions_authentication_admin_password": "${JS_REPORT:-dev_password_only}",
"ES_PASSWORD": "${ES_ELASTIC:-dev_password_only}",
"extensions_fs-store_dataDirectory": "jsreport/data"
"JS_REPORT_SECRET": "dev_secret_only",
"JS_REPORT": "dev_password_only",
"ES_PASSWORD": "dev_password_only",
"API_USERNAME": "admin",
"API_PASSWORD": "dev_password_only",
"SSL": "true",
tumbledwyer marked this conversation as resolved.
Show resolved Hide resolved
"JS_REPORT_CONFIG_FILE": "export.jsrexport",
"JS_REPORT_CPU_LIMIT": "0.15",
"JS_REPORT_MEMORY_LIMIT": "3G",
"JS_REPORT_CPU_RESERVE": "0.05",
"JS_REPORT_MEMORY_RESERVE": "1G"
}
}
77 changes: 67 additions & 10 deletions dashboard-visualiser-jsreport/swarm.sh
Original file line number Diff line number Diff line change
@@ -1,28 +1,85 @@
#!/bin/bash

Action=$1
Mode=$2

STATEFUL_NODES=${STATEFUL_NODES:-"cluster"}

ComposeFilePath=$(
COMPOSE_FILE_PATH=$(
cd "$(dirname "${BASH_SOURCE[0]}")" || exit
pwd -P
)

if [[ "$2" == "dev" ]]; then
ROOT_PATH="${COMPOSE_FILE_PATH}/.."
. "${ROOT_PATH}/utils/config-utils.sh"

if [[ "$Mode" == "dev" ]]; then
printf "\nRunning JS Reports package in DEV mode\n"
JsReportDevComposeParam="-c ${ComposeFilePath}/docker-compose.dev.yml"
JsReportDevComposeParam="-c ${COMPOSE_FILE_PATH}/docker-compose.dev.yml"
else
printf "\nRunning JS Reports package in PROD mode\n"
JsReportDevComposeParam=""
fi

if [[ "$1" == "init" ]]; then
docker stack deploy -c "$ComposeFilePath"/docker-compose.yml $JsReportDevComposeParam instant
elif [[ "$1" == "up" ]]; then
docker stack deploy -c "$ComposeFilePath"/docker-compose.yml $JsReportDevComposeParam instant
elif [[ "$1" == "down" ]]; then
AwaitJsrRunning() {
local startTime=$(date +%s)
until [[ $(docker service ls -f name=instant_dashboard-visualiser-jsreport --format "{{.Replicas}}") == *"${JS_REPORT_INSTANCES}/${JS_REPORT_INSTANCES}"* ]]; do
config::timeout_check $startTime "dashboard-visualiser-jsreport to start"
sleep 1
done

local awaitHelperState=$(docker service ps instant_await-helper --format "{{.CurrentState}}")
until [[ $awaitHelperState == *"Complete"* ]]; do
config::timeout_check $startTime "dashboard-visualiser-jsreport status check"
sleep 1

awaitHelperState=$(docker service ps instant_await-helper --format "{{.CurrentState}}")
if [[ $awaitHelperState == *"Failed"* ]] || [[ $awaitHelperState == *"Rejected"* ]]; then
echo "Fatal: Received error when trying to verify state of dashboard-visualiser-jsreport. Error:
$(docker service ps instant_await-helper --no-trunc --format \"{{.Error}}\")"
exit 1
fi
done

docker service rm instant_await-helper
}

RemoveConfigImporter() {
local complete="false"
local startTime=$(date +%s)
local configImporterState=$(docker service ps instant_jsreport-config-importer --format "{{.CurrentState}}")
until [[ $configImporterState == *"Complete"* ]]; do
config::timeout_check $startTime "jsreport-config-importer to run"
sleep 1

configImporterState=$(docker service ps instant_jsreport-config-importer --format "{{.CurrentState}}")
if [[ $configImporterState == *"Failed"* ]] || [[ $configImporterState == *"Rejected"* ]]; then
echo "Fatal: JS Reports config importer failed with error:
$(docker service ps instant_jsreport-config-importer --no-trunc --format \"{{.Error}}\")"
exit 1
fi
done

docker service rm instant_jsreport-config-importer
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docker swarm has the concept of jobs. I know I'm mentioned this before, but maybe we should start using them. Then we might not need to remove the service once it's done as it gets marked as completed and it's easier to then see what has executed against the stack. Check the docs here - https://docs.docker.com/engine/reference/commandline/service_create/#running-as-a-job

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, so I've given this a go. There are a few reasons I don't really like it.

  1. We need to move our raft configs from the docker-compose.config.yml files to our base docker-compose for that service - this leads to a lack of separation-of-concerns
  2. We need to either specify a lot of env vars in the swarm.sh where we create the job, or we need to specify even more env vars in our .env files (which are already getting quite cluttered), whereas the compose.config.yml was a nice place to list the env vars needed for the api-config-importer to run.
  3. Reading env vars are proving to be a hassle (I've given it at least 35 minutes now and I'm still getting problems)

Overall, if it were my choice, I would keep it the way we have it. I think it's simpler and a bit cleaner, too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, ok cool. I thought you would be able to specify the mode in the docker compose which would make the change fairly simple. However it seems that isn't possible yet - docker/cli#2907

Seems job is only supported via the CLI, which is annoying.

}

if [[ "$Action" == "init" ]] || [[ "$Action" == "up" ]]; then
docker stack deploy -c "$COMPOSE_FILE_PATH"/docker-compose.yml $JsReportDevComposeParam instant
CastelloG marked this conversation as resolved.
Show resolved Hide resolved

docker stack deploy -c "${COMPOSE_FILE_PATH}"/docker-compose.await-helper.yml instant

echo "Verifying JS Reports service status"
AwaitJsrRunning

config::set_config_digests "$COMPOSE_FILE_PATH"/importer/docker-compose.config.yml
docker stack deploy -c "$COMPOSE_FILE_PATH"/importer/docker-compose.config.yml instant

RemoveConfigImporter
config::remove_stale_service_configs "$COMPOSE_FILE_PATH"/importer/docker-compose.config.yml "jsreport"
elif [[ "$Action" == "down" ]]; then
docker service scale instant_dashboard-visualiser-jsreport=0
elif [[ "$1" == "destroy" ]]; then
docker service rm instant_dashboard-visualiser-jsreport
elif [[ "$Action" == "destroy" ]]; then
docker service rm instant_dashboard-visualiser-jsreport instant_jsreport-config-importer instant_await-helper
else
echo "Valid options are: init, up, down, or destroy"
fi
17 changes: 9 additions & 8 deletions interoperability-layer-openhim/initiateReplicaSet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

echo 'Initiating the mongo replica set'

COMPOSE_FILE_PATH=$(
cd "$(dirname "${BASH_SOURCE[0]}")" || exit
pwd -P
)

ROOT_PATH="${COMPOSE_FILE_PATH}/.."
. "${ROOT_PATH}/utils/config-utils.sh"

MONGO_SET_COUNT=${MONGO_SET_COUNT:-3}
Config='{"_id":"mongo-set","members":['
Priority="1"
Expand All @@ -18,14 +26,7 @@ echo 'Waiting to ensure all the mongo instances for the replica set are up and r
RunningInstanceCount=0
StartTime=$(date +%s)
until [[ $RunningInstanceCount -eq $MONGO_SET_COUNT ]]; do
TimeDiff=$(($(date +%s) - $StartTime))
if [[ $TimeDiff -ge 60 ]] && [[ $TimeDiff -lt 61 ]]; then
echo "Warning: Waited 1 minute for mongo set to start. This is taking longer than it should..."
elif [[ $TimeDiff -ge 120 ]]; then
echo "Fatal: Waited 2 minutes for mongo set to start. Exiting..."
exit 1
fi

config::timeout_check $StartTime "mongo replica set to run"
sleep 1

RunningInstanceCount=0
Expand Down
21 changes: 5 additions & 16 deletions interoperability-layer-openhim/swarm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,20 @@ COMPOSE_FILE_PATH=$(
)

# Import libraries

ROOT_PATH="${COMPOSE_FILE_PATH}/.."
. "${ROOT_PATH}/utils/config-utils.sh"

VerifyCore() {
local startTime=$(date +%s)
until [[ $(docker service ls -f name=instant_openhim-core --format "{{.Replicas}}") == *"$OPENHIM_CORE_INSTANCES/$OPENHIM_CORE_INSTANCES"* ]]; do
TimeoutCheck $startTime "openhim-core to start"
config::timeout_check $startTime "openhim-core to start"
sleep 1
done

local awaitHelperState=$(docker service ps instant_await-helper --format "{{.CurrentState}}")
until [[ $awaitHelperState == *"Complete"* ]]; do
TimeoutCheck $startTime "openhim-core heartbeat check"
config::timeout_check $startTime "openhim-core heartbeat check"
sleep 1

awaitHelperState=$(docker service ps instant_await-helper --format "{{.CurrentState}}")
Expand All @@ -43,7 +44,7 @@ RemoveConfigImporter() {
local startTime=$(date +%s)
local configImporterState=$(docker service ps instant_interoperability-layer-openhim-config-importer --format "{{.CurrentState}}")
until [[ $configImporterState == *"Complete"* ]]; do
TimeoutCheck $startTime "interoperability-layer-openhim-config-importer to run"
config::timeout_check $startTime "interoperability-layer-openhim-config-importer to run"
sleep 1

configImporterState=$(docker service ps instant_interoperability-layer-openhim-config-importer --format "{{.CurrentState}}")
Expand All @@ -57,24 +58,12 @@ RemoveConfigImporter() {
docker service rm instant_interoperability-layer-openhim-config-importer
}

TimeoutCheck() {
local startTime=$(($1))
local message=$2
local timeDiff=$(($(date +%s) - $startTime))
if [[ $timeDiff -ge 60 ]] && [[ $timeDiff -lt 61 ]]; then
echo "Warning: Waited 1 minute for $message. This is taking longer than it should..."
elif [[ $timeDiff -ge 120 ]]; then
echo "Fatal: Waited 2 minutes for $message. Exiting..."
exit 1
fi
}

VerifyMongos() {
echo 'Waiting to ensure all the mongo instances for the replica set are up and running'
local runningInstanceCount=0
local startTime=$(date +%s)
until [[ $runningInstanceCount -eq $MONGO_SET_COUNT ]]; do
TimeoutCheck $startTime "mongo set to start"
config::timeout_check $startTime "mongo set to start"
sleep 1

runningInstanceCount=0
Expand Down
23 changes: 23 additions & 0 deletions utils/config-utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,26 @@ config::remove_stale_service_configs() {

docker config rm "${configsToRemove[@]}"
}

# A function that exists in a loop to see how long that loop has run for, providing a warning
# at the time specified in argument $3, and exits with code 124 after the time specified in argument $4.
#
# Arguments:
# $1 : start time of the timeout check
# $2 : a message containing reference to the loop that timed out
# $3 : timeout time in seconds, default is 300 seconds
# $4 : elapsed time to issue running-for-longer-than-expected warning (in seconds), default is 60 seconds
config::timeout_check() {
local startTime=$(($1))
local message=$2
local exitTime="${3:-300}"
local warningTime="${4:-60}"

local timeDiff=$(($(date +%s) - $startTime))
if [[ $timeDiff -ge $warningTime ]] && [[ $timeDiff -lt $(($warningTime + 1)) ]]; then
echo "Warning: Waited $warningTime seconds for $message. This is taking longer than it should..."
elif [[ $timeDiff -ge $exitTime ]]; then
echo "Fatal: Waited $exitTime seconds for $message. Exiting..."
exit 124
fi
}