Skip to content

Commit 06a8037

Browse files
authored
Merge pull request #64 from SAFEHR-data/jeremy/docs
Deployment docs
2 parents 27746bd + 7c584af commit 06a8037

4 files changed

Lines changed: 174 additions & 4 deletions

File tree

README.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ separate to the Emap project root.
4646

4747
### Expected top-level dir structure
4848
```
49-
├── PIXL
50-
├── config
51-
├── waveform-controller
52-
└── waveform-export
49+
├── PIXL (repo root of the PIXL repo)
50+
├── config (config files for the waveform project)
51+
├── waveform-controller (repo root for this repo)
52+
└── waveform-export (bind mounted by the containers, this is the main working directory for the waveform project)
5353
```
5454

5555
### Instructions for achieving this structure
@@ -59,6 +59,11 @@ separate to the Emap project root.
5959
Clone this repo (`waveform-controller`) and [PIXL](https://github.com/SAFEHR-data/PIXL),
6060
both inside your root directory.
6161

62+
If on a system that has access to sensitive data, disable push remotes on all cloned repos as follows:
63+
```
64+
git remote set-url --push origin no_push.example.com
65+
```
66+
6267
#### make config files
6368
Set up the config files as follows:
6469
```
@@ -112,6 +117,9 @@ docker compose build
112117
docker compose up -d
113118
```
114119

120+
For more complex deployment scenarios, such as where there is existing data you need to preserve,
121+
see the more advanced [deployment doc](docs/deployment.md)
122+
115123
## 3 Check if it's working
116124

117125
Running the controller will save (to `../waveform-export`) waveform messages

docs/azure_hashing.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ There is a one-off (per key vault) step that needs to be performed manually.
2626

2727
First, install the Azure CLI tools in the usual way for your OS.
2828

29+
On the GAE you can run the AZ CLI in a container like so:
30+
```
31+
docker run --rm -e HTTPS_PROXY=$HTTPS_PROXY -it mcr.microsoft.com/azure-cli:azurelinux3.0
32+
```
33+
as per https://learn.microsoft.com/en-us/cli/azure/run-azure-cli-docker?view=azure-cli-latest
34+
35+
2936
Log in using the service principal.
3037
Do not include password on command line; let it prompt you and then paste it in.
3138
```

docs/deployment.md

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
# Notes on deployment into production
2+
3+
# About
4+
5+
This document is intended for deployers of the Waveform export pipeline,
6+
who likely overlap with its developers.
7+
8+
It describes how to deploy the system into production, and especially how to
9+
"upgrade", ie. re-deploy in an environment where some processing has already taken place.
10+
11+
Because this project required changes to Emap (mainly the waveform-reader),
12+
it also covers when that might need to be upgraded.
13+
14+
## Background
15+
The current situation is that we are running an instance
16+
of Emap on `star_dev` that is independent of the "live" versions
17+
on `star_a` and `star_b`, because the waveform export pipeline
18+
is dependent on software changes to Emap and we don't have time
19+
to deploy those changes into Emap main on our schedule —
20+
rebuilding the database takes ~12 weeks now.
21+
22+
Although the waveform controller queries `star_[ab]`, not `star_dev`, we still keep
23+
a full Emap system running on `star_dev` so that the streamlit visualisation
24+
can run.
25+
26+
This document should be read in conjunction with the
27+
[pipeline diagram](https://github.com/SAFEHR-data/emap/blob/develop/docs/technical_overview/waveforms/pipeline.md)
28+
29+
## How to rebuild the system
30+
31+
It depends on what you have changed! You could take the
32+
sledgehammer approach which is rather similar to
33+
[the initial setup in the main README](../README.md):
34+
* Emap: `emap docker down --volumes` to take down the containers and delete the rabbitmq data
35+
* Delete all Emap tables in `star_dev` as per Emap deployment instructions.
36+
* Waveform: `docker compose down` to bring everything down
37+
* git pull and rebuild containers for the two repos.
38+
* Change config if necessary
39+
* Bring it all up again
40+
41+
This is mostly going to be unnecessary though, because eg. the
42+
Emap ADT processing is unlikely to have changed.
43+
44+
Let's go for a more granular approach. Each step is potentially
45+
optional, so read carefully.
46+
47+
### Stop the Emap waveform-reader
48+
> ![TIP]
49+
> Refer to the Emap deployment guide at
50+
> https://github.com/SAFEHR-data/emap/blob/main/docs/SOP/release_procedure.md
51+
52+
If you have made changes to the way we receive waveform HL7
53+
messages, you should stop this container with `emap docker stop waveform-reader`.
54+
55+
This can take a while, because it will flush out any HL7
56+
data in memory to disk.
57+
58+
This will stop listening on port 7777, and in the absence of buffering
59+
on the Smartlinx server, we are now losing waveform data forever, so
60+
try to minimise the amount of time it's in this state.
61+
See https://github.com/SAFEHR-data/emap/issues/135 re buffering.
62+
63+
Checkout the code you wish to deploy with eg. `(cd emap && git pull)`.
64+
65+
Build the new version of the waveform-reader image with
66+
`emap docker build waveform-reader`.
67+
68+
Does any config need updating? See if any config params
69+
have been added/removed
70+
from the Emap global config, and re-run `emap setup -g` as appropriate.
71+
72+
### Drain the rabbitmq queues
73+
Observe the `waveform_emap` and `waveform_export` queues in rabbitmq.
74+
They are consumed by Emap core and waveform-controller respectively.
75+
76+
We stopped incoming messages in the previous step, but the queues
77+
probably still contain messages that were generated with the old version of
78+
waveform-reader, so we must decide what to do with them.
79+
80+
One option is to wait for those consumers to finish their jobs and empty the queues.
81+
82+
If for some reason the consumers are not running or are malfunctioning (perhaps
83+
they are rejecting and requeueing the messages), then another option is to purge one
84+
or both queues in the rabbitmq admin console.
85+
86+
If the rabbitmq topology has changed, you might consider bringing down the entire
87+
rabbitmq container and deleting its data volume.
88+
89+
90+
### Emap DB and core processor
91+
Less likely, you may have changed the Emap core processor or the
92+
Emap star database.
93+
94+
If so, you will want to stop and rebuild the `core` service:
95+
```
96+
emap docker stop core
97+
emap docker build core
98+
```
99+
(we will bring it back up later)
100+
101+
We don't have a framework for doing migrations when the database schema has changed, so
102+
any migrations would have to be done on an ad hoc basis.
103+
That's why we tend to delete the entire database and rebuild it.
104+
105+
However, because no other tables depend on the `waveform` table
106+
(ie. it is a "leaf" of the database schema),
107+
it would be relatively easy to delete only that table and let hibernate rebuild it,
108+
thus avoiding a full rebuild.
109+
When the core service comes back up, it would continue to update the non-waveform data.
110+
111+
### Waveform controller/exporter (ie. this repo)
112+
113+
You may need to delete files in the host directory `waveform-export`, which
114+
is bind mounted by the `waveform-controller` and `waveform-exporter` containers.
115+
116+
Snakemake won't regenerate files if the timestamps of upstream
117+
files suggest they don't need updating. Therefore, if you have made
118+
a change that would affect the contents of those files and wish to
119+
force a re-processing, you will need to manually delete those files.
120+
121+
To force a re-upload only, delete files in `ftps-logs`.
122+
123+
To force a reconversion from CSV to parquet (which includes pseudonymisation),
124+
delete files in `pseudonymised` and `hash-lookups`.
125+
126+
Files in `original-csv` are produced by the waveform-controller.
127+
If you need to regenerate those,
128+
you will need to replay HL7 messages (see later section).
129+
130+
### Bring it all back up
131+
It shouldn't matter what order things are brought back up in, so let's do it in the same order
132+
it was brought down.
133+
134+
Bring up any Emap services that we brought down:
135+
Emap repo: `emap docker up -d`
136+
137+
Bring up the waveform controller/export if you brought them down.
138+
Waveform repo: `docker compose up -d`
139+
140+
### Replay old HL7 data
141+
142+
Not yet supported, see https://github.com/SAFEHR-data/emap/issues/139

docs/develop.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,19 @@ git commit -m "Making pre-commit pass."
7070
git push
7171
```
7272

73+
## Dev tips
74+
75+
`waveform-exporter` normally runs via cron once per 24 hours. This is not very convenient for dev!
76+
You can either set the cron frequency to every minute (`* * * * *`) and bring up the service in
77+
the normal way, or manually run the one-shot command below when required.
78+
79+
```
80+
# make sure hasher is up first
81+
docker compose up -d waveform-hasher
82+
# run
83+
docker compose run --build --entrypoint /app/exporter-scripts/scheduled-script.sh waveform-exporter
84+
```
85+
7386
## Testing
7487

7588
Even though we are largely running in docker, you may wish to let your IDE have access to a venv for running tests in.

0 commit comments

Comments
 (0)