Run a trial Server on AWS

scripts/trial-ec2.sh makes one throwaway Linux machine on AWS for trying a Server, and deletes it again afterwards. Use it when a trial needs real Linux, for example a Server whose Warehouse is a DuckDB file (see Run stage and prod on a Mac for why that can't run on a Mac).

It is a helper for trials in this repository, not a supported way to set up a Server. It is not part of the adops package.

What up makes:

Resource Details
Machine m7i-flex.large (2 cores, 8 GB), Ubuntu 24.04, named and tagged adops-trial
Disk 20 GB gp3, deleted when the machine is deleted
Security group adops-trial: SSH only, only from your public IP at the time you ran up
Key pair adops-trial; the private key is saved at ~/.ssh/adops-trial.pem
Budget alert (optional) adops-trial: emails you once usage passes $15

Everything except the Budget carries the tag Project=adops-trial. That tag is how down finds what to delete.

Before you start

To use a different profile, region or key location, set these before running the script:

Variable Default
AWS_PROFILE adops-trial
AWS_REGION eu-north-1
TRIAL_KEY_PATH ~/.ssh/adops-trial.pem

Step 1 — Create the machine

From the repository root:

scripts/trial-ec2.sh up

up does these in order and stops at the first problem, before anything is created:

  1. Checks your login, your vCPU quota and that m7i-flex.large is free-tier eligible.
  2. Refuses to start if a previous adops-trial machine, security group, key pair or local key is still there. Run down first.
  3. Asks whether to create the $15 Budget alert, and asks for an email address if you say yes. The address goes straight to AWS and is not saved anywhere. The alert counts usage before credits, because on the Free plan credits cover the bill and an alert on the net amount would never go off.

Then it creates the key pair, the security group and the machine, waits for the machine to start, and prints the command to connect:

  ssh -i ~/.ssh/adops-trial.pem ubuntu@<machine address>

Step 2 — Wait for Docker to finish installing

The machine installs Docker, the Docker Compose plugin and git on its first boot, which takes a few minutes. Connect, then wait for it:

cloud-init status --wait

When it prints status: done, docker and git are ready. If you connected before the install finished, disconnect and connect again so that docker works without sudo.

From here, set up the Server as in Promotion. Before you delete a machine whose state you want to keep, back it up as in Back up and restore a Server.

Soak a Server under Faults

A soak runs a stage Server on the Postgres Warehouse for a day or two with two scheduled Pipelines, and breaks it on purpose at the moments that are hardest to get right. Each break is a Fault. After every Fault, the Invariant Checker reads the Server's stores and says whether anything was lost, duplicated or left unreported. The harness lives in scripts/soak/ and is meant to be rerun on every later release. It is a trial tool, not a CI job, and not part of the adops package.

File What it does
setup.sh Turns the fresh machine into the soak Server: two Pipelines (shop_sync every 10 minutes, events_sync every 7), a Source writer every 30 s, an alert receiver, a resource sampler, and a deploy checkout at ~/soak/checkout. Safe to rerun.
faults.sh Injects one Fault, undoes its own damage, then runs the checker.
check_invariants.py The Invariant Checker. faults.sh runs it; you can run it alone with faults.sh check.
plant_failures.sh Proves the checker can fail, by planting each broken Invariant in a scratch copy.

Set up, or move to a later release

  1. Build a wheel of the release to soak, on the Mac. It must carry a new version number, because setup.sh installs it with pip and pip skips a version it already has:

    uv build --wheel
    
  2. Copy scripts/ and the wheel to the machine, then run setup.sh there:

    scp -i ~/.ssh/adops-trial.pem -r scripts dist/adops-<version>-py3-none-any.whl ubuntu@<machine address>:
    ssh -i ~/.ssh/adops-trial.pem ubuntu@<machine address>
    bash scripts/soak/setup.sh --wheel adops-<version>-py3-none-any.whl
    

    On a later release, copy the new scripts/ and wheel and run setup.sh again. It rebuilds the Server image from the new wheel and restarts the Server on it; the data, the soak state and the deploy checkout stay.

faults.sh must stay at ~/scripts/soak/faults.sh next to check_invariants.py, because the Faults started from the Mac send the script over SSH and the machine then looks for the checker there.

Run the Faults

Run them from the Mac and keep each one's output in soak-evidence/ (Git ignores it, because the output names hosts and addresses). Add Host adops-trial with its HostName, User ubuntu and IdentityFile ~/.ssh/adops-trial.pem to ~/.ssh/config, so that ssh adops-trial works:

mkdir -p soak-evidence
ssh adops-trial 'bash -s' -- source-stop < scripts/soak/faults.sh > soak-evidence/source-stop.txt 2>&1
echo "exit $?" >> soak-evidence/source-stop.txt

Two Faults run on the Mac itself, because they need a hand from outside the machine:

bash scripts/soak/faults.sh reboot-in-retry --host adops-trial > soak-evidence/reboot-in-retry.txt 2>&1

Don't pipe the output through tee without set -o pipefail: the exit code is the result.

Exit code Meaning
0 Every Invariant passed.
1 An Invariant failed (named on a FAIL line), or the Fault's own check failed (a FAULT FAIL: line).
2 Setup error: a store could not be reached, or a bad argument. Nothing was judged.
3 No Invariant failed, but one was not checked (a DuckDB Warehouse stayed locked).
4 The Fault could not reach its moment within 15 minutes, undid what it had changed, and injected nothing else. Run it again.

In this order, on the Postgres Server:

Fault What it does Pass
source-stop Holds the events_sync Pipeline Lock until a scheduled run waits for it, stops the shop Source, lets the run in, waits until it is in its 300 s retry wait, then starts the Source again. A shop_sync run that reaches its Reverse Sync while shop is stopped fails, because shop is also its Target; that failure and its one alert are expected. The retry succeeds; the checker passes.
kill-worker --stretch 300000 Adds 300,000 orders so the Sync takes a while, then kill -9s the shop_sync run worker while its dlt package is still pending. It finds the worker from the run's Started process for run (pid: N) event, checks in pg_stat_activity (application_name adops-warehouse-lock) that the run holds its Pipeline Lock and with ss -tnp that the process is connected to the Warehouse. It refuses to kill if no package is pending. The next run finishes the pending package; the failed run has exactly one alert.
backfill-overlap Runs adops backfill shop_sync orders while a scheduled run holds the Pipeline Lock, then lets a schedule tick come while a backfill holds it. A backfill is itself a run of the Pipeline, so that tick is skipped, not queued. It holds the dbt Lock to keep each holder inside the lock long enough. The first backfill waits and passes; the tick during the second is skipped and no scheduled run starts; the second backfill passes.
backfill-kill Adds 300,000 orders, starts a backfill and docker kills it as soon as its cursor rewind is written. The cursor is not left below where it was before the backfill, and the killed backfill's Dagster run is not left STARTED. A STARTED run makes the Schedule skip the Pipeline until dagster_daemon restarts, so the Fault restarts it once no other run is going (its server-recover marks the run failed and sends one alert).
overlap-old-release Holds the dbt Lock so a scheduled shop_sync run of the old release waits at its Transform, makes 3 releases from the deploy checkout and replays the deploy (adops server-release, the reload, adops run --all --changed). The old run's release folder is kept while it runs (3 newer releases would otherwise remove it), and the saved Step Fingerprints match the new release.
overlap-queued-run Holds the Pipeline Lock so a scheduled run of the old code waits, replays the deploy, then lets the old run go first and the deploy's run after it. The saved Step Fingerprints match the new release, and the next tick carries the new adops/release tag.
reboot-in-retry (Mac) Puts an events_sync run in its retry wait with the Source stopped, reboots the machine, waits one schedule tick, then restarts the Server. See the reboot caution below.
backup-under-load Dumps the Warehouse and the Dagster database while runs go on (it skips the "stop the Server" step of Back up and restore a Server on purpose), restores them into a separate compose project adops-soak-restore on ports +100, compares, and removes the copy. Needs 2 GB free. Every restored table and Load Record is also in the live Warehouse; the live Warehouse lost no rows; only the live compose project is left.
disk-full (Mac) Fills the root disk with /var/tmp/adops-soak-fill for 11 minutes, so a scheduled tick hits a full disk, then deletes it. The disk has space again and the next tick succeeds.

Then switch stage to a DuckDB Warehouse (the commented warehouse: block in ~/soak/server/adops.yaml) and run duckdb-deploy-while-running --stretch 2000000. It adds 2,000,000 customers so a run takes minutes, replays the deploy during that run, and records whether the deploy's run waited for the DuckDB lock or refused. It removes the added customers afterwards.

Options: --pipeline <name> (default shop_sync, or events_sync for source-stop and reboot-in-retry), --table <incremental table> (default orders), --stretch <rows>, --from <date> (backfill start, default today), --releases <n>, --hold <minutes>. scripts/soak/faults.sh --help lists them all.

Cautions:

To rehearse against a local stage Server, set SOAK_SERVER_DIR, SOAK_CHECKOUT, SOAK_STATE_DIR, SOAK_HOME and SOAK_PYTHON (a Python that has adops installed) and run faults.sh there. kill-worker, reboot-in-retry and disk-full need the Linux machine.

Step 3 — Delete everything

scripts/trial-ec2.sh down

down deletes every adops-trial resource, found by tag or by name:

  1. Terminates the machine and waits until it is gone.
  2. Deletes any leftover adops-trial disks.
  3. Deletes the adops-trial security group. If AWS still says the group is in use, it retries for up to 2 minutes.
  4. Deletes the adops-trial key pair and the local key file.
  5. Deletes the adops-trial Budget alert, if there is one.

Then it checks again. It ends with No adops-trial resources are left., or it lists what is still there under Still present: and exits with an error. down is safe to run as often as you like. With nothing to delete, it finishes straight away.

Always run down when the trial is over. The machine stops itself after 72 hours, but a stopped machine's disk is still billed until it is deleted.

Cost guards

When something goes wrong

What you see What to do
AWS credentials ... are missing or expired Run aws login --profile adops-trial, then run the command again.
up stopped halfway (login expired, network error) Log in again, run down to clear what was made, then run up again.
up says something from a previous run still exists Run down, then up.
ssh times out Your public IP has probably changed since up, for example on a different network. SSH is only open to the IP you had then. Run down and up again from your current network.
down ends with Still present: Run down again. If something is still left, delete it in the AWS console: EC2 lists the machine, disks, security group and key pair, and Billing lists the Budget.
... security group is still in use after 2 minutes AWS is still releasing the network attachment of the deleted machine. Wait a minute and run down again.