A pillar that could not write kept answering with the count it had before the break
The read side got its counters last cycle; the write side was still catching everything, logging one line and keeping the process alive. A failed write is worse than a failed read - the row never existed and no later request brings it back - and the surface hid it better. Measured on the shipped image with SQLite triggers aborting every INSERT/UPDATE on source_observations and edge_alerts while reads kept working: three new sources refused and a six-request 5xx storm later, GET /admin-api/observations answered 200 with the same X-Total-Count it had before the break (46), GET /admin-api/alerts still showed its one row, /healthz and /readyz were 200, /admin-api/state had no write-side field at all, and the log carried "flush failed, 4 entries dropped" plus two "could not persist". DurabilityHealth counts each writer separately; /state reports observationWriteFailures/observationsLost/observationLastWriteError, alertWriteFailures/alertsLost and retentionPruneFailures; /readyz answers 503 naming the pillar, the rows lost and the innermost error rather than EF's wrapper. A counter clears only on a successful write of its own pillar, and retention is reported without being a readiness failure - stated in code, with the reason. Teeth: WriteFailureVisibilityTests (5) - 5 failed / 0 passed before the fix. Gates: compose-smoke 53 -> 63 (blocks writes with triggers, asserts the unchanged X-Total-Count as the lie, and heals per pillar), smoke.sh 25 -> 28, console-check 53 -> 57.
This commit is contained in:
@@ -331,6 +331,87 @@ check 'putting the table back clears the counters and readiness returns' '200' "
|
||||
check 'and the policy answer says so again' 'X-Policy-Reload-Failures: 0' \
|
||||
"$(hdr -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" "$EDGE/admin-api/policy" | grep -i '^x-policy-reload-failures:' | tr -d '\r')"
|
||||
|
||||
echo '- a pillar that cannot write says so'
|
||||
# The read side got its counters first; the write side was still silent, and a
|
||||
# failed write is worse than a failed read — the row never existed, and no later
|
||||
# request brings it back. Measured on the shipped image with SQLite triggers
|
||||
# aborting every INSERT and UPDATE on source_observations and edge_alerts while
|
||||
# reads stayed working: three new sources refused and a six-request 5xx storm
|
||||
# later, GET /admin-api/observations answered 200 with the same X-Total-Count it
|
||||
# had before the break, GET /admin-api/alerts still showed its one row, /healthz
|
||||
# and /readyz answered 200, /admin-api/state had no write-side field at all, and
|
||||
# the log carried "ObservationWriter: flush failed, 4 entries dropped." plus two
|
||||
# "AlertWriter: could not persist…". A trigger, not a dropped table, on purpose:
|
||||
# a missing table breaks the listing too, and a broken listing is honest about
|
||||
# being broken. The lie this asserts is the 200 that stays complete-looking.
|
||||
TOTAL_BEFORE=$(hdr -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" "$EDGE/admin-api/observations?limit=1" \
|
||||
| grep -i '^x-total-count:' | tr -d '\r' | awk '{print $2}')
|
||||
sidecar <<'PYSQL'
|
||||
import sqlite3
|
||||
c = sqlite3.connect("/app/data/openwaf.db", isolation_level=None)
|
||||
for t in ("source_observations", "edge_alerts"):
|
||||
for op in ("INSERT", "UPDATE"):
|
||||
c.execute(f'CREATE TRIGGER "gate_{t}_{op}" BEFORE {op} ON "{t}" '
|
||||
"BEGIN SELECT RAISE(ABORT, 'gate: durable write blocked'); END")
|
||||
print("triggers:", [r[0] for r in c.execute("SELECT name FROM sqlite_master WHERE type='trigger'")])
|
||||
PYSQL
|
||||
for src in 203.0.113.201 203.0.113.202 203.0.113.203; do
|
||||
for i in 1 2 3; do code -H "$(xff "$src")" "$EDGE/no-write-$i" >/dev/null; done
|
||||
done
|
||||
for i in $(seq 1 6); do code -H "$(xff 203.0.113.210)" "$EDGE/boom" >/dev/null; done
|
||||
OBS_FAILS=0
|
||||
for _ in $(seq 1 12); do
|
||||
OBS_FAILS=$(admin "$EDGE/admin-api/state" | jval observationWriteFailures)
|
||||
[ "${OBS_FAILS:-0}" != "0" ] && break
|
||||
sleep 3
|
||||
done
|
||||
printf ' info observation write failures counted after writes were blocked: %s\n' "${OBS_FAILS:-0}"
|
||||
check 'the state counts observations this edge could not persist' 'yes' \
|
||||
"$([ "${OBS_FAILS:-0}" != "0" ] && echo yes || echo no)"
|
||||
check 'and it says how many rows were lost, not only that something failed' 'yes' \
|
||||
"$(admin "$EDGE/admin-api/state" | jval observationsLost | awk '{exit ($1+0>=1)?0:1}' && echo yes || echo no)"
|
||||
check 'the alerting pillar counts its lost alerts too' 'yes' \
|
||||
"$(admin "$EDGE/admin-api/state" | jval alertWriteFailures | awk '{exit ($1+0>=1)?0:1}' && echo yes || echo no)"
|
||||
TOTAL_AFTER=$(hdr -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" "$EDGE/admin-api/observations?limit=1" \
|
||||
| grep -i '^x-total-count:' | tr -d '\r' | awk '{print $2}')
|
||||
printf ' info X-Total-Count across the break: %s -> %s (three new sources saw, none stored)\n' "$TOTAL_BEFORE" "$TOTAL_AFTER"
|
||||
check 'the listing still answers with the count it had before the break' "$TOTAL_BEFORE" "$TOTAL_AFTER"
|
||||
check 'readiness names the write pillar that is failing' '503' "$(code "$EDGE/readyz")"
|
||||
check 'the failure it names is the real reason, not an EF wrapper' 'yes' \
|
||||
"$(admin "$EDGE/admin-api/state" | jval observationLastWriteError | grep -qi 'durable write blocked' && echo yes || echo no)"
|
||||
sidecar <<'PYSQL'
|
||||
import sqlite3
|
||||
c = sqlite3.connect("/app/data/openwaf.db", isolation_level=None)
|
||||
for r in list(c.execute("SELECT name FROM sqlite_master WHERE type='trigger'")):
|
||||
c.execute(f'DROP TRIGGER "{r[0]}"')
|
||||
print("triggers after cleanup:", c.execute("SELECT count(*) FROM sqlite_master WHERE type='trigger'").fetchone()[0])
|
||||
PYSQL
|
||||
for src in 203.0.113.221 203.0.113.222; do
|
||||
for i in 1 2 3; do code -H "$(xff "$src")" "$EDGE/healed-$i" >/dev/null; done
|
||||
done
|
||||
for _ in $(seq 1 12); do
|
||||
[ "$(admin "$EDGE/admin-api/state" | jval observationWriteFailures)" = "0" ] && break
|
||||
sleep 3
|
||||
done
|
||||
check 'the observation pillar heals on its next successful write' '0' \
|
||||
"$(admin "$EDGE/admin-api/state" | jval observationWriteFailures)"
|
||||
# Readiness does not come back yet, and that is the semantics being asserted: a
|
||||
# counter clears only on a successful write of its own pillar, so the alert
|
||||
# pillar — which has had nothing to write since the break — keeps the edge
|
||||
# unready. A gauge that reset on any write would have said "ready" here while
|
||||
# the alerting pillar had still not produced a single row.
|
||||
check 'readiness still refuses until the alert pillar writes again' '503' "$(code "$EDGE/readyz")"
|
||||
# Twelve 502s from a fresh source: the alerting threshold this run set is 3,
|
||||
# and the escalation alerts at 3 and 6, so this is enough to raise one for sure.
|
||||
for i in $(seq 1 12); do code -H "$(xff 203.0.113.230)" "$EDGE/boom" >/dev/null; done
|
||||
for _ in $(seq 1 12); do
|
||||
[ "$(code "$EDGE/readyz")" = "200" ] && break
|
||||
sleep 3
|
||||
done
|
||||
check 'and readiness returns once every failing pillar has written again' '200' "$(code "$EDGE/readyz")"
|
||||
check 'the rows the edge sees now land again' 'yes' \
|
||||
"$([ "$(admin "$EDGE/admin-api/state" | jval alertWriteFailures)" = "0" ] && echo yes || echo no)"
|
||||
|
||||
echo
|
||||
printf 'compose smoke: %d passed, %d failed\n' "$PASS" "$FAIL"
|
||||
[ "$FAIL" -eq 0 ]
|
||||
|
||||
@@ -496,6 +496,78 @@ const rgb = (s) => s.match(/\d+/g).slice(0, 3).map(Number);
|
||||
await broken.close();
|
||||
}
|
||||
|
||||
// The write half of the same contract. A failed write loses a row for good —
|
||||
// measured on the shipped image with SQLite triggers aborting every INSERT
|
||||
// and UPDATE on source_observations and edge_alerts: the observation listing
|
||||
// kept answering with the X-Total-Count it had before the break while three
|
||||
// new sources were being refused, the alert table kept its one row through a
|
||||
// six-request 5xx storm, and /readyz said "ready". scripts/compose-smoke.sh
|
||||
// proves that end to end against the image; what is proven here is that the
|
||||
// page renders the fields it now has to render, and that a write failure is
|
||||
// shown as a write failure rather than folded into the snapshot pill.
|
||||
{
|
||||
const lost = await browser.newPage();
|
||||
const lostProblems = [];
|
||||
lost.on('pageerror', (e) => lostProblems.push('pageerror: ' + e.message));
|
||||
await lost.route('**/admin-api/state', (route) => route.fulfill({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify({
|
||||
snapshotAgeSeconds: 0.4, snapshotTtlSeconds: 30, snapshotStale: false,
|
||||
snapshotRefreshFailures: 0, snapshotLastRefreshError: null,
|
||||
policyReloadFailures: 0, policyLastReadAt: '2026-10-02T05:12:07.0000000+00:00',
|
||||
observationWriteFailures: 3, observationsLost: 4,
|
||||
observationLastWriteError: 'gate: durable write blocked',
|
||||
observationLastWriteAt: '2026-10-02T05:11:52.0000000+00:00',
|
||||
alertWriteFailures: 2, alertsLost: 2,
|
||||
alertLastWriteError: 'gate: durable write blocked',
|
||||
retentionPruneFailures: 1, retentionLastError: 'gate: durable write blocked',
|
||||
retentionLastPruneAt: '2026-10-02T04:41:19.0000000+00:00',
|
||||
trackedSources: 4, operatorBlocks: 2, engineBans: 0,
|
||||
allowEntries: 0, allowEntriesExpired: 0, mode: 'Enforce'
|
||||
})
|
||||
}));
|
||||
await lost.goto(`${EDGE}/admin`, { waitUntil: 'domcontentloaded' });
|
||||
await lost.fill('#token', TOKEN);
|
||||
await lost.click('#save');
|
||||
await lost.waitForFunction(
|
||||
() => /durable writes/.test([...document.querySelectorAll('#summary .pill')]
|
||||
.map((p) => p.textContent).join(' | ')),
|
||||
null, { timeout: 15000 }).catch(() => {});
|
||||
const writePill = await lost.evaluate(() => {
|
||||
const pill = [...document.querySelectorAll('#summary .pill')].find((p) => /durable writes/.test(p.textContent));
|
||||
return pill ? { text: pill.textContent.replace(/\s+/g, ' ').trim(), cls: pill.className } : null;
|
||||
});
|
||||
const snapshotPill = await lost.evaluate(() => {
|
||||
const pill = [...document.querySelectorAll('#summary .pill')].find((p) => /snapshot/.test(p.textContent));
|
||||
return pill ? { text: pill.textContent.replace(/\s+/g, ' ').trim(), cls: pill.className } : null;
|
||||
});
|
||||
check('a write that never reached storage is marked on the page, with what it cost',
|
||||
!!writePill && /observations not persisted/.test(writePill.text)
|
||||
&& /4 rows lost/.test(writePill.text) && /alerts not persisted/.test(writePill.text)
|
||||
&& /warn/.test(writePill.cls),
|
||||
JSON.stringify(writePill));
|
||||
check('and it is shown as a write failure, not folded into the snapshot pill',
|
||||
!!snapshotPill && !/warn/.test(snapshotPill.cls) && !/not persisted/.test(snapshotPill.text)
|
||||
&& /retention not running/.test(writePill.text || ''),
|
||||
JSON.stringify({ write: writePill, snapshot: snapshotPill }));
|
||||
check('the page threw no javascript on that answer', lostProblems.length === 0, lostProblems.join(' | '));
|
||||
await lost.close();
|
||||
}
|
||||
|
||||
// The clean case, on the real stand rather than a rendered contract: the pill
|
||||
// has to say it checked, because a pill that only appears when something is
|
||||
// wrong is how "no alerts" and "alerts are not being written" look identical.
|
||||
{
|
||||
const cleanPill = await page.evaluate(() => {
|
||||
const pill = [...document.querySelectorAll('#summary .pill')].find((p) => /durable writes/.test(p.textContent));
|
||||
return pill ? { text: pill.textContent.replace(/\s+/g, ' ').trim(), cls: pill.className } : null;
|
||||
});
|
||||
check('with the write path healthy the page says so rather than staying quiet',
|
||||
!!cleanPill && /durable writes ok/.test(cleanPill.text) && !/warn/.test(cleanPill.cls),
|
||||
JSON.stringify(cleanPill));
|
||||
}
|
||||
|
||||
// A phone in dark mode is the case an operator actually reaches the console
|
||||
// from — the address that got them blocked is the one they are typing about.
|
||||
// Both halves of this used to be broken and measured: the page overflowed a
|
||||
|
||||
@@ -142,6 +142,17 @@ check 'the policy answer carries its provenance header' 0 \
|
||||
"$(curl -s -D- -o /dev/null -H "X-Admin-Token: $TOKEN" \
|
||||
"http://127.0.0.1:$EDGE_PORT/admin-api/policy" | tr -d '\r' \
|
||||
| sed -n 's/^[Xx]-[Pp]olicy-[Rr]eload-[Ff]ailures: //p')"
|
||||
# The write side of the same contract. A failed write is worse than a failed
|
||||
# read — the row never existed and no later request brings it back — so the
|
||||
# counters exist even in a clean run, where they read 0 0 0. A surface that
|
||||
# answers "0" for a field it never publishes is indistinguishable from one that
|
||||
# publishes it and means it, which is why the keys are asserted too.
|
||||
check 'the state counts writes it could not persist, and there are none' '0 0 0' \
|
||||
"$(printf '%s' "$STATE_JSON" | python3 -c 'import sys,json;d=json.load(sys.stdin);print(d["observationWriteFailures"], d["alertWriteFailures"], d["retentionPruneFailures"])')"
|
||||
check 'and it carries what was lost and when a write last landed' True \
|
||||
"$(printf '%s' "$STATE_JSON" | python3 -c 'import sys,json;d=json.load(sys.stdin);print(all(k in d for k in ("observationsLost","alertsLost","observationLastWriteAt","alertLastWriteAt","retentionLastPruneAt")))')"
|
||||
check 'readiness is ready while the write path is healthy' 200 \
|
||||
"$(code "http://127.0.0.1:$EDGE_PORT/readyz")"
|
||||
check 'switching the engine off is accepted' Off \
|
||||
"$(curl -s -X PUT -H "X-Admin-Token: $TOKEN" -H 'Content-Type: application/json' --data-binary "$POLICY_OFF_JSON" \
|
||||
"http://127.0.0.1:$EDGE_PORT/admin-api/policy" | python3 -c 'import sys,json;print(json.load(sys.stdin)["mode"])')"
|
||||
|
||||
Reference in New Issue
Block a user