an alert that could not be pushed is pushed later, and says so while it waits

The push queue was a channel in one process: three attempts inside one request of work, then the row was simply no longer owed to anybody. An endpoint down for ten minutes swallowed every alert raised in that window, and a restart swallowed everything still waiting. The alert table stayed correct the whole time, which is exactly what made the hole invisible from the surface.

What is owed is now a row in alert_pushes: denormalised payload (retention prunes edge_alerts, and a delivery still owed must not go with the row it was copied from), attempts, next-attempt time, last error, and a claim so two edges over one database send each row once. Attempts are configuration (OpenWaf:Alerts:MaxPushAttempts, PushRetrySeconds), validated at startup like the other bounds; when they run out the row records that and the surface says how many were given up, because a counter that cannot tell 'still retrying' from 'stopped retrying' is the blindness this item removes.

Surfaces: /admin-api/state answers alertPushPending/Delivered/GivenUp/OldestPendingAt/LastError from the table, /metrics publishes the same as gauges from a cache no older than 5s (the metrics endpoint's rule is that it never leans on the database per scrape). Retention prunes only rows that are finished.

What the run caught, in order: (1) SchemaUpgradeTests hardcoded the migration count as a literal, so the new migration turned a working upgrade into a red test - the count is now read from the migrations assembly. (2) Two of the new queue tests asserted 'pending == 0' after waiting only for 'delivered >= 1'; one scene raises more than one alert, so the read landed between two rows and failed on a correct product - the wait now requires the queue to have emptied. (3) The whole integration suite answered 9 failures of 251, every one 'Timed out waiting for the entry point to build the IHost after 00:05:00', while the identical build minutes later answered 251/251 in 34s: a test host that cannot bind a loopback socket fails as a timeout, and the README now says so next to the scheduling note that used to be the only explanation on file.

Gates on this tree: build 0 warnings / 0 errors, unit 277/277, integration 251/251 in 34s, smoke 68 passed / 0 failed (3 new), image 261 MB, compose-smoke 232 passed / 0 failed with 0 containers left behind (2 new, including the push-queue table being added by the edge to a volume that predates it), console 90 assertions / 0 failed.

Refs OPEN-60.
This commit is contained in:
Pavlo Ratushnyi
2026-10-05 03:21:39 +02:00
parent 575ef88afe
commit d635a00078
20 changed files with 1565 additions and 122 deletions
+23 -1
View File
@@ -1332,6 +1332,10 @@ import sqlite3
c = sqlite3.connect("/app/data/openwaf.db", isolation_level=None)
c.execute("DROP TABLE request_rules")
c.execute("DROP TABLE source_streaks")
# OPEN-60 added a table. A volume written by the previous release is exactly the
# state an upgrading operator is in, so the queue table goes too: the edge has to
# put it back by itself, with no operator migration step.
c.execute("DROP TABLE alert_pushes")
print("dropped; tables now:", sorted(r[0] for r in c.execute("SELECT name FROM sqlite_master WHERE type='table'")))
PYSQL
docker compose restart edge >/dev/null 2>&1
@@ -1347,7 +1351,23 @@ OPEN55_STATE=$(admin "$EDGE/admin-api/state")
OPEN55_ADDED=$(printf '%s' "$OPEN55_STATE" | jval schemaTablesAdded)
printf ' info tables this start had to create: %s\n' "${OPEN55_ADDED:-none}"
check 'the state names the tables it had to add' 'yes' \
"$([ "${OPEN55_ADDED:-0}" -ge 2 ] && echo yes || echo no)"
"$([ "${OPEN55_ADDED:-0}" -ge 3 ] && echo yes || echo no)"
# The table the durable push queue (OPEN-60) lives in, added by the edge to a
# database that predates it. A restart is the only thing that ran between the
# drop and this read.
OPEN55_PUSH_TABLE=$(sidecar <<'PYSQL'
import sqlite3
c = sqlite3.connect("/app/data/openwaf.db", isolation_level=None)
print("yes" if c.execute(
"SELECT count(*) FROM sqlite_master WHERE type='table' AND name='alert_pushes'"
).fetchone()[0] else "no")
PYSQL
)
check 'the push queue table was added to a database that predates it' 'yes' "$OPEN55_PUSH_TABLE"
check 'and the state counts the queue it now keeps' '0 0 0' \
"$(printf '%s' "$OPEN55_STATE" | jval alertPushPending) \
$(printf '%s' "$OPEN55_STATE" | jval alertPushDelivered) \
$(printf '%s' "$OPEN55_STATE" | jval alertPushGivenUp)"
check 'and says nothing the build needs is missing now' '[]' \
"$(printf '%s' "$OPEN55_STATE" | jval schemaMissingTables)"
check 'the rules pillar is reading again' 'true' \
@@ -1386,6 +1406,8 @@ check 'the verdict counter counts the rule refusal this stack just made' 'yes' \
"$([ "$(msample 'openwaf_requests_total{verdict="block_rule"} ')" -gt 0 ] 2>/dev/null && echo yes || echo no)"
check 'the schema gauge says nothing the build needs is missing' '0' \
"$(msample 'openwaf_schema_missing_tables ')"
check 'the push queue is published as gauges on the shipped image' '0 0 0' \
"$(msample 'openwaf_alert_push_pending ') $(msample 'openwaf_alert_push_delivered_total ') $(msample 'openwaf_alert_push_given_up_total ')"
check 'the write counters are published even on a healthy stack' '0' \
"$(msample 'openwaf_write_failures_total{pillar="bans"} ')"
check 'the body names no address from the scene above' 'yes' \
+13
View File
@@ -145,6 +145,12 @@ check 'the verdict counter counts the ban this scene just made' yes \
"$([ "${BLOCK_ENGINE:-0}" -gt 0 ] 2>/dev/null && echo yes || echo no)"
check 'the live blocks gauge counts the engine ban' 1 \
"$(msample 'openwaf_blocks_live{source="engine"} ')"
# The push queue (OPEN-60) is a table, so its numbers are publishable the same
# way. No endpoint is configured in this scene, so the honest answer is three
# zeros — and a gauge that is missing is a different failure from a gauge that
# says 0, which is why msample's empty answer fails the check.
check 'the push queue is published as gauges as well' '0 0 0' \
"$(msample 'openwaf_alert_push_pending ') $(msample 'openwaf_alert_push_delivered_total ') $(msample 'openwaf_alert_push_given_up_total ')"
# The aggregate-only invariant, asserted over the whole body with the markers
# from the scene above actually in the database behind it.
check 'the body names no address, no path and no operator note' yes \
@@ -300,6 +306,13 @@ check 'the state says the snapshot is inside its ttl' False \
# surface has to say which of "no alerts" and "no push" it is answering.
check 'the state says alerts are not pushed anywhere by default' False \
"$(printf '%s' "$STATE_JSON" | python3 -c 'import sys,json;print(json.load(sys.stdin)["alertWebhookConfigured"])')"
# What the push queue holds (OPEN-60): owed, delivered, given up. The keys are
# asserted before the values, because "0" from a surface that never writes the
# queue is indistinguishable from "0" from one that does.
check 'the state names the push queue it keeps' True \
"$(printf '%s' "$STATE_JSON" | python3 -c 'import sys,json;d=json.load(sys.stdin);print(all(k in d for k in ("alertPushPending","alertPushDelivered","alertPushGivenUp","alertPushLastError","alertPushOldestPendingAt")))')"
check 'and with no endpoint configured it keeps nothing' '0 0 0' \
"$(printf '%s' "$STATE_JSON" | python3 -c 'import sys,json;d=json.load(sys.stdin);print(d["alertPushPending"], d["alertPushDelivered"], d["alertPushGivenUp"])')"
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' \