|
| 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 |
0 commit comments