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.
65 lines
3.0 KiB
C#
65 lines
3.0 KiB
C#
namespace OpenWaf.Domain.Security;
|
|
|
|
/// <summary>
|
|
/// A delivery this edge owes somebody (OPEN-60).
|
|
///
|
|
/// The alert table is the record of what happened; this table is the record of
|
|
/// whether anyone was told. They are separate rows because they fail separately:
|
|
/// an alert that is durably written and never pushed is exactly the blindness
|
|
/// the webhook was added to remove, and until now the queue of "not yet pushed"
|
|
/// lived in a channel in one process — three attempts, then the delivery was
|
|
/// gone for good, and a restart dropped everything still waiting.
|
|
///
|
|
/// The payload is copied here rather than referenced. Retention prunes
|
|
/// <c>edge_alerts</c> on the ban-retention window, and a push that is still due
|
|
/// must not die with the row it came from: an alert raised at 03:00 against an
|
|
/// endpoint that is down until the morning is the case this exists for.
|
|
/// </summary>
|
|
public sealed class AlertPush
|
|
{
|
|
public long Id { get; init; }
|
|
|
|
/// <summary>The alert this delivery came from. Not a foreign key and not
|
|
/// unique-by-constraint across restarts — it is the answer to "have I already
|
|
/// promised this alert to somebody", and it is what an operator reads next to
|
|
/// the alert row.</summary>
|
|
public long AlertId { get; set; }
|
|
|
|
// ---- the payload, copied (see the class note) ----
|
|
public string Kind { get; set; } = string.Empty;
|
|
public string SourceKey { get; set; } = string.Empty;
|
|
public int Count { get; set; }
|
|
public int? LastStatusCode { get; set; }
|
|
public string? LastPath { get; set; }
|
|
public string Detail { get; set; } = string.Empty;
|
|
public DateTimeOffset AlertCreatedAt { get; set; } = DateTimeOffset.UtcNow;
|
|
|
|
// ---- the delivery state ----
|
|
public int Attempts { get; set; }
|
|
public DateTimeOffset CreatedAt { get; set; } = DateTimeOffset.UtcNow;
|
|
|
|
/// <summary>When this row may be tried again. Null while a process holds a
|
|
/// claim on it.</summary>
|
|
public DateTimeOffset? NextAttemptAt { get; set; }
|
|
|
|
public string? LastError { get; set; }
|
|
|
|
/// <summary>Set once, when the endpoint accepted the push. A delivered row
|
|
/// keeps its row until retention ages it out, so "how many did we tell people
|
|
/// about" is a count of rows rather than a counter that resets on restart.</summary>
|
|
public DateTimeOffset? PushedAt { get; set; }
|
|
|
|
/// <summary>Set once, when the attempts ran out. The difference between this
|
|
/// and a pending row is the difference between "the endpoint is down" and
|
|
/// "we stopped asking", and an operator is entitled to know which one they
|
|
/// are reading.</summary>
|
|
public DateTimeOffset? GivenUpAt { get; set; }
|
|
|
|
/// <summary>Which process is trying this row right now. Two edges sharing one
|
|
/// database would otherwise push the same alert twice, and a duplicate page
|
|
/// at 03:00 is not a harmless bug. A claim older than the reclaim window
|
|
/// belongs to a process that died and is taken over.</summary>
|
|
public string? ClaimedBy { get; set; }
|
|
public DateTimeOffset? ClaimedAt { get; set; }
|
|
}
|