Repository navigation
v3.0.0 fix: preserve pool-wait alert during collector failure - #351
Conversation
Describe metrics collection and instrumented ledger transaction pool acquisition, retaining query/advisory-lock/read-gate exclusions and the five no-replacement dispositions. Regenerate migration tables and deployment patch from the verified frozen snapshot; all alert behavior is unchanged.
Preserve the updated base alert specifications and regenerate the deployment patch from the verified frozen snapshot. Clarify that rollup worker transactions, public API queries and other traffic outside instrumented acquisition paths remain untimed; retain all alert expressions and thresholds.
Remove only the collector-availability gate; preserve snapshot freshness, sample sufficiency, thresholds, duration and labels. Add bounded PromQL scenarios with per-instance assertions, recovery and the old-expression negative control. Refs #336. Landing depends on #334 and reconciliation with #343 and #345.
The native registry declares two database wait families, but nothing in the ledger observed either one: advisory-lock waits had no observations at all, and pool acquisition counted only the metrics collector's own. ORDER_LOCK contention, which serializes every share acknowledgement, was therefore invisible in production and in qualification. Give Ledger an optional metrics handle, supplied by the new connect_with_metrics; connect keeps its signature and passes None, so the tools and tests that connect without a registry are unchanged and record nothing. The coordinator passes its own handle. Route every advisory lock through the existing lock() helper, now timing the pg_advisory_xact_lock statement alone, and every ledger transaction through a new begin() helper that times pool acquisition alone. begin() is Pool::begin split in two around the timer, down to its sqlx::Error return type, so both helpers are drop-in replacements and every call site's `?` converts exactly as before. Leaving the BEGIN round trip outside the timer keeps the pool series meaning what the collector already records. Errors, including a lock_timeout expiry, propagate unchanged and record as failure. A drop guard records a wait abandoned by cancellation as a failure with its elapsed time, so a cancelled wait stays distinct from one that never happened. Completing the wait takes the handle out of the guard, so a wait is recorded exactly once. The metrics mutex is taken only after the wait has ended, never across an await, so rendering cannot queue behind a contended lock; a guard held across the await would also make the future !Send and fail to compile in the spawned share path. The CPFP funding lock has no LockKind value and stays unobserved; an unmapped key trips a debug assertion rather than borrowing another lock's label. Refs #328.
Two gated PostgreSQL tests and one source invariant. The first attaches a registry and drives each outcome against a real database: the migration lock from schema creation, a share append taking ORDER_LOCK once, a second session holding ORDER_LOCK past a 200 ms lock_timeout so the append fails with SQLSTATE 55P03 and records one failure of at least that duration, an append cancelled mid-wait recording its partial wait and no more, the settlement lock through save_job, five transactions each observing one pool acquisition plus the collector's own unchanged, a pool acquisition cancelled while every connection is held, and a closed pool recording an acquisition failure. The second runs the same sequence on a ledger with no handle and asserts that results and error codes, 55P03 included, are what they are at the base. It deliberately makes no assertion about a registry: one no ledger can reach has nothing to record into and could not fail the test. The third walks the ledger sources recursively and fails if a transaction begins outside the timed helper or a second pg_advisory_xact_lock statement appears, so a new call site, including one in a nested module directory, cannot silently stop being observed. Refs #328.
The two database wait families now say what they measure and who records them: pool acquisition excludes transaction BEGIN and the queries that follow, and advisory-lock timing covers one pg_advisory_xact_lock round trip for the migration, order and settlement locks. Both record a wait abandoned by cancellation as a failure, except the collector's own acquisitions, which keep reporting cancellation through collector status rather than inventing a completed wait. The follow-up ownership and alert-migration notes no longer describe either family as unpopulated, and record that PrismDatabasePoolWaitHigh now evaluates ledger acquisitions while its description still predates this change. No alert rule or digest input changes. Refs #328.
PrismDatabasePoolWaitHigh is gated on collector_available for the database collector. That collector acquires from the same pool as the ledger, so sustained pool exhaustion times out its own acquisition, zeroes the gauge and suppresses the rule exactly while the ledger histogram is recording the waits that should fire it. The gate cost nothing before this branch, because the family carried no samples during such an outage. It does now. The rule itself cannot change here: its file feeds the alert specification digest embedded in the deployment patch, which can only be regenerated from the frozen template. #336 tracks that work; this records the interaction where operators read it. Refs #328.
|
Adversarial review checkpoint for head Verified
Finding 1 (major for this PR's stated goal): the remaining freshness gate re-suppresses the alarm during sustained pool exhaustion. Finding 2 (minor, cross-PR): the inherited description still says "collector availability remains a separate alert guard"; #343 owns the wording and must reconcile it and regenerate the shared patch before or after this lands (both PR bodies already state this). This checkpoint does not override the #334 landing hold and takes no merge action. |
|
Thermo-nuclear (code-quality) lane checkpoint for head Executed here
Findings
Landing note: #343 and this PR touch the same rule object and the same digest line, so one regeneration after both is required regardless; that does not resolve finding 1 by itself. No blocking correctness finding for the expression change. |
The native registry declares two database wait families, but nothing in the ledger observed either one: advisory-lock waits had no observations at all, and pool acquisition counted only the metrics collector's own. ORDER_LOCK contention, which serializes every share acknowledgement, was therefore invisible in production and in qualification. Give Ledger an optional metrics handle, supplied by the new connect_with_metrics; connect keeps its signature and passes None, so the tools and tests that connect without a registry are unchanged and record nothing. The coordinator passes its own handle. Route every advisory lock through the existing lock() helper, now timing the pg_advisory_xact_lock statement alone, and every ledger transaction through a new begin() helper that times pool acquisition alone. begin() is Pool::begin split in two around the timer, down to its sqlx::Error return type, so both helpers are drop-in replacements and every call site's `?` converts exactly as before. Leaving the BEGIN round trip outside the timer keeps the pool series meaning what the collector already records. Errors, including a lock_timeout expiry, propagate unchanged and record as failure. A drop guard records a wait abandoned by cancellation as a failure with its elapsed time, so a cancelled wait stays distinct from one that never happened. Completing the wait takes the handle out of the guard, so a wait is recorded exactly once. The metrics mutex is taken only after the wait has ended, never across an await, so rendering cannot queue behind a contended lock; a guard held across the await would also make the future !Send and fail to compile in the spawned share path. The CPFP funding lock has no LockKind value and stays unobserved; an unmapped key trips a debug assertion rather than borrowing another lock's label. Refs #328.
Two gated PostgreSQL tests and one source invariant. The first attaches a registry and drives each outcome against a real database: the migration lock from schema creation, a share append taking ORDER_LOCK once, a second session holding ORDER_LOCK past a 200 ms lock_timeout so the append fails with SQLSTATE 55P03 and records one failure of at least that duration, an append cancelled mid-wait recording its partial wait and no more, the settlement lock through save_job, five transactions each observing one pool acquisition plus the collector's own unchanged, a pool acquisition cancelled while every connection is held, and a closed pool recording an acquisition failure. The second runs the same sequence on a ledger with no handle and asserts that results and error codes, 55P03 included, are what they are at the base. It deliberately makes no assertion about a registry: one no ledger can reach has nothing to record into and could not fail the test. The third walks the ledger sources recursively and fails if a transaction begins outside the timed helper or a second pg_advisory_xact_lock statement appears, so a new call site, including one in a nested module directory, cannot silently stop being observed. Refs #328.
The two database wait families now say what they measure and who records them: pool acquisition excludes transaction BEGIN and the queries that follow, and advisory-lock timing covers one pg_advisory_xact_lock round trip for the migration, order and settlement locks. Both record a wait abandoned by cancellation as a failure, except the collector's own acquisitions, which keep reporting cancellation through collector status rather than inventing a completed wait. The follow-up ownership and alert-migration notes no longer describe either family as unpopulated, and record that PrismDatabasePoolWaitHigh now evaluates ledger acquisitions while its description still predates this change. No alert rule or digest input changes. Refs #328.
PrismDatabasePoolWaitHigh is gated on collector_available for the database collector. That collector acquires from the same pool as the ledger, so sustained pool exhaustion times out its own acquisition, zeroes the gauge and suppresses the rule exactly while the ledger histogram is recording the waits that should fire it. The gate cost nothing before this branch, because the family carried no samples during such an outage. It does now. The rule itself cannot change here: its file feeds the alert specification digest embedded in the deployment patch, which can only be regenerated from the frozen template. #336 tracks that work; this records the interaction where operators read it. Refs #328.
|
Heads-up from a review of #334: removing the collector-availability gate may not be sufficient on its own. A second mechanism suppresses this alert during the same incident. The metrics body an exposition scrape returns is the last published snapshot, and publication happens inside the health loop in
The pool's The snapshot is then marked stale between publications, and the rule's Worth checking against this branch before it lands: either publish the event observations independently of the database-bound loop, or make the freshness gate tolerate a publication delay that is itself a symptom of the condition being alerted on. Raised by the automated reviewer on #334 and verified in code here; recorded on #336. Nothing in #334 changes this behaviour, which predates it. |
|
The publisher coupling you identified is addressed in A disposable PostgreSQL regression exercises the publisher's real SQL dependency order while all shared-pool connections are held, and real HTTP scrapes see new ledger and collector cancellation observations across a stale-body interval. That test passes with the fix and fails against the old runtime because the HTTP count remains zero; the original complete alert rule also fails the sustained positive PromQL cases. Final CI and focused review of this pushed producer change are still pending. |
|
Thermo-nuclear (code-quality) delta checkpoint for head Commands run (this head)
Verified
Findings: no defects. Optional: |
|
Correction to the thermo delta checkpoint for |
|
Adversarial fix-verification checkpoint for head Correction to my previous checkpoint. I wrote that the pool histogram was "a live registry histogram recorded at scrape time". That was wrong for the code as it stood: What the fix does (verified in source). Attacked and held.
Negative controls. promtool 3.14.0 (independent copy): 28 expressions, 73 scenarios, 145 expression assertions and 86 alert assertions pass, and the built-in negative control confirms the original expression fails the two required positive scenarios ("slow waits survive unavailable collector", "publisher freshness cannot reset live pool dwell"). Rust: with the Findings. No refutation found at this head. Two non-blocking notes: (1) rollout dependency is real and correctly documented — older producers still cache the histogram, so the revised expression must not be activated before every coordinator target runs this producer; (2) the advisory-lock histogram remains cached (not Commands run on the frozen tree: |
|
Coordinator close-out for c703f3f: the final Fable verification confirms the original suppression finding is fixed, with independently executed positive and negative controls; thermo reports no defects, and CI is green on this head. No further code change is required for the reviewed scope. Optional predicate/suffix deduplication and the extra package in the new CI step are deferred as nonblocking maintenance; no behavior depends on changing them. The still-cached advisory-lock histogram has no alert in this scope and must be revisited before a rule is added. The documented deployment prerequisite remains mandatory: deploy the live pool-histogram producer to every coordinator target before enabling the revised expression. Ready for squash merge into 3.x.x; no merge or deployment performed here. |
Shared database-pool exhaustion can fail collection and stall the health publisher while instrumented acquisitions continue recording waits. Removing only the collector guard leaves the pool histogram cached and repeatedly resets the alert's three-minute dwell when that body becomes stale.
This reads the pool histogram live on each scrape using one coherent registry snapshot, replacing its cached HELP/TYPE, buckets, count and sum without duplicates. Only
PrismDatabasePoolWaitHighchanges its gates: a successful scrape (up == 1) replaces collector and cached-body availability. Its p99 threshold above 0.5 seconds, five-minute window, minimum ten acquisitions per instance, three-minute dwell and alert labels remain unchanged. Other cached measurements retain their existing freshness and unknown-data contracts; acquisition, cancellation, ACK and payout behavior are unchanged.Deploy the live-histogram producer to every coordinator target before activating this expression. Older producers still cache pool observations, so their successful scrapes do not establish the new freshness contract. Generated artifacts were regenerated against the pinned read-only template snapshot.
Validation on the pushed tree:
Landing order was #334 → #343 → #351; #334 and #343 are merged, and this PR now targets
3.x.x. Append-only merges preserve review history; #345's cancellation producer remains unchanged. The publisher fix is0bee2ef, included in pushed reconciliation headc703f3fd4daf8a0c95dd462d8a791861a93dabd4. Both final-head CI runs 34878673268 and 34878672937 passed without retry, including all 132 required gated tests. Focused Fable verification and thermo verification found no defects on this head, with independent positive and negative controls. The coordinator closeout records nonblocking maintenance notes and the mandatory producer-first rollout prerequisite; prior frozen-head reviews are not credited as verification of the runtime fix.Refs #336.