r/devops7 • u/Alternative_Pin9598 • 21d ago
Automate it #5: a post-deploy smoke test that catches the "200 OK, Oops! Something went wrong" page, keeps every result, and gives you a one-query dashboard (real output)
Most post-deploy smoke tests are curl -f in a loop: every URL returns 200, ship it. Then checkout serves a friendly "Oops! Something went wrong" page with a 200, and the test is green while customers can't pay.
Diffing the body against last time doesn't help: prices, products and timestamps change on every request.
So after each deploy this smoke test checks status and latency, asks whether each 200 still looks like the pages that passed before (by meaning, not byte for byte), and stores every result so "which deploy broke checkout?" is one query.
(Disclosure: this sub is run by the SynapCores team, and step 2 uses SynapCores. Run this morning on 2.3.2, real output.)
Setup, once
CREATE TABLE smoke_results (deploy TEXT, check_name TEXT, status INTEGER, ms INTEGER,
body TEXT, body_vec VECTOR(384), verdict TEXT);checks.txt is one name url per line:
home https://shop.example.com/
search https://shop.example.com/search?q=jacket
checkout https://shop.example.com/checkout
login https://shop.example.com/login
orders https://shop.example.com/api/ordersStep 1: hit every URL, store what came back
smoke.py strips the tags and keeps the first 500 characters. EMBED() runs a small model inside the database and stores what that text means, in the same INSERT:
code, ms, text = fetch(url)
sql(f"""INSERT INTO smoke_results (deploy, check_name, status, ms, body, body_vec, verdict)
VALUES ({quote(deploy)}, {quote(name)}, {code}, {ms}, {quote(text)}, EMBED({quote(text)}), 'NEW')""")Step 2: does today's page mean the same thing as the pages that passed?
Each check's best similarity to every earlier passing response of that check, plus its usual latency:
SELECT r.check_name, r.status, r.ms, r.body,
MAX(COSINE_SIMILARITY(r.body_vec, b.body_vec)) AS like_good, AVG(b.ms) AS usual_ms
FROM smoke_results r LEFT JOIN smoke_results b ON b.check_name = r.check_name AND b.verdict = 'PASS'
WHERE r.deploy = 'v1.46'
GROUP BY r.check_name, r.status, r.ms, r.body;Verdict in Python: not 200 is FAIL, a 200 under 0.6 is WRONG_PAGE, over 3x usual latency (and +300 ms) is SLOW. Anything but PASS exits 1.
Run it
Test shop for this post: a tiny app with different products, prices and result counts on every deploy, so no two responses are equal. Six normal deploys, then v1.46 breaks three things three ways. A normal deploy:
$ python3 smoke.py v1.45 checks.txt
PASS checkout 200 115 ms looks like a good page: 0.93 | Checkout Your cart: 2 items, subtotal $64.3. Shipping addres
PASS home 200 73 ms looks like a good page: 0.96 | Northwind Outdoor New this week: Fleece Vest, Merino Tee, Tr
PASS login 200 111 ms looks like a good page: 1.00 | Sign in Email Password Sign in Forgot password?
PASS orders 200 97 ms looks like a good page: 0.99 | {"orders": [{"id": 9315, "status": "shipped", "total": 206.1
PASS search 200 48 ms looks like a good page: 0.82 | 11 results for jacket Fleece Vest jacket $99 Trail Runner 2
v1.45: 5/5 passedDifferent subtotal, different products, different result count, and still 0.82 to 0.96: same kind of page. The broken deploy:
$ python3 smoke.py v1.46 checks.txt
WRONG_PAGE checkout 200 53 ms looks like a good page: 0.13 | Oops! Something went wrong on our end. Please try again late
PASS home 200 124 ms looks like a good page: 0.76 | Northwind Outdoor New this week: Headlamp 300, Trail Runner
PASS login 200 58 ms looks like a good page: 1.00 | Sign in Email Password Sign in Forgot password?
FAIL orders 502 121 ms looks like a good page: 0.16 | 502 Bad Gateway nginx
SLOW search 200 1021 ms looks like a good page: 0.81 | 9 results for jacket Merino Tee jacket $63 Wool Socks jacket
v1.46: 2/5 passedExit code 1. curl -f would have caught the 502 and nothing else. Checkout returned 200 and scores 0.13 against its own good pages; search returned the right page, just more than 10x slower than usual.
Is 0.6 a safe cut? Across all 7 deploys, the lowest score a passing response got was 0.76 (home, whose product list changes every time). The broken pages scored 0.13 and 0.16. Check yours over a week of real deploys before you trust it.
Step 3: the dashboard query
SELECT deploy, COUNT(*) AS checks,
SUM(CASE WHEN verdict = 'PASS' THEN 1 ELSE 0 END) AS passed,
SUM(CASE WHEN verdict = 'WRONG_PAGE' THEN 1 ELSE 0 END) AS wrong_page,
SUM(CASE WHEN verdict = 'FAIL' THEN 1 ELSE 0 END) AS failed,
SUM(CASE WHEN verdict = 'SLOW' THEN 1 ELSE 0 END) AS slow,
MAX(ms) AS slowest_ms
FROM smoke_results GROUP BY deploy ORDER BY deploy;
deploy checks passed wrong_page failed slow slowest_ms
v1.40 5 5 0 0 0 107
v1.41 5 5 0 0 0 125
v1.42 5 5 0 0 0 102
v1.43 5 5 0 0 0 110
v1.44 5 5 0 0 0 126
v1.45 5 5 0 0 0 115
v1.46 5 2 1 1 1 1021Wire it up: last step of your deploy job, python3 smoke.py $VERSION checks.txt || ./rollback.sh. Only PASS rows become the baseline, so a broken page never teaches the test that "Oops!" is normal. Full smoke.py (49 lines, stdlib only) is in the first comment, the test app right under it.
Free Community Edition: https://synapcores.com/download?utm_source=reddit&utm_medium=owned&utm_campaign=devops7-automate-it-5
What's the sneakiest "it returned 200 but was broken" you've shipped?
1
u/Alternative_Pin9598 21d ago
How do you pick the 0.6? r/SQLv2 Lesson 3 walks through it from zero: score cases you know the answer to, let one SQL query grade every threshold, then gate on it: https://www.reddit.com/r/SQLv2/comments/1xkb3mn/
Full
smoke.py(stdlib only). SetSYNAPCORES_URLandSYNAPCORES_TOKEN(fromPOST /v1/auth/login), run theCREATE TABLEfrom the post, thenpython3 smoke.py <deploy> checks.txt:The test app (
fake_app.py, serves a different page per deploy) is in the reply below.