Skip to content

test(longhaul): add kill-operator-pod and kill-primary-pod chaos operations - #421

Merged
WentingWu666666 merged 31 commits into
documentdb:mainfrom
WentingWu666666:developer/wentingwu/longhaul-chaos-ops
Sep 17, 2026
Merged

WentingWu666666 merged 31 commits into
documentdb:mainfrom
WentingWu666666:developer/wentingwu/longhaul-chaos-ops

Conversation

@WentingWu666666

@WentingWu666666 WentingWu666666 commented Jul 10, 2026 •

Copy link
Copy Markdown
Collaborator

Long-haul chaos operations + sequence-mode smoke gate

Adds the first two Chaos / HA operations from the long-haul design (docs/designs/long-haul-test-design.md → Operations) to the driver introduced in #405, reworks the outage-budget model they depend on, and adds a deterministic sequence operation mode plus a PR smoke gate that runs the real driver end-to-end against kind. Scope: fault-inject the control plane and the database primary on the canary cluster, and assert — over a multi-day run — that the data plane keeps serving and the cluster reconverges to its declared topology; and gate every PR by exercising each operation once against a real cluster.

Chaos operations

Two new operations registered with the scheduler:

Operation Fault Asserts
kill-operator-pod Deletes the operator pod The data plane keeps serving throughout (control-plane restart must not drop writes); the operator Deployment returns to Available.
kill-primary-pod Deletes the CNPG primary pod CNPG promotes a standby (automatic failover); writes resume and the cluster returns to full topology. Requires HA (instancesPerNode>=2).

The continuous workload verifier independently catches any data loss caused by a failover.

Outage policy: duration-based, writer-count-independent

The chaos ops needed a principled disruption budget, so OutagePolicy moved from a raw write-failure count to a wall-clock write-outage duration:

  • OutagePolicy.MaxWriteOutage time.Duration replaces AllowedWriteFailures int64. The journal converts the observed failure count into an estimated outage using the workload's aggregate write rate (WriteFailures / WritesPerSecond), so budgets no longer scale with LONGHAUL_NUM_WRITERS. The rate is computed once at startup from NumWriters and the fixed writer cadence (workload.AggregateWriteRate) and stamped onto each disruption window.
  • Two orthogonal guardrails, both fail independently (ExceededPolicy trips if either is exceeded):
    • MaxWriteOutage — client-visible write availability (data plane).
    • MustRecoverWithin — the managed cluster's return to full declared topology (all pods Ready, CR Ready). Because a failed op is only logged (not scored), this is the sole mechanism that fails the run when the cluster never reconverges — e.g. a failover where writes resume fast but a replacement standby never rejoins.
  • Shared budgets to prevent drift (all in journal/policy.go):
    • NoOutagePolicy (~300ms cushion) for operations that keep the write path up throughout: kill-operator-pod and the scale ops (which only add/remove a standby). One fully-failed write tick maps to ~100ms of estimated outage regardless of writer count, so the cushion absorbs unrelated noise without tolerating a real outage.
    • PrimaryHandoverPolicy (30s) for kill-primary-pod: an ungraceful failover interrupts writes for exactly one primary handover.
    • UpgradeOutagePolicy (90s) for upgrade-documentdb: a cross-version rolling upgrade's graceful switchover coincides with the extension migration under live write load, so it gets its own, larger budget (calibrated from a real smoke run measuring ~33s, with headroom). The longer whole-topology restart is bounded by MustRecoverWithin, not the write-outage budget.

Operation runner modes + Long-Haul Smoke Gate

The operation runner now supports three modes (LONGHAUL_OPERATION_MODE): random (production long-haul — weighted, one op every 10s, global cooldown), sequence (an explicit ordered LONGHAUL_OPERATION_SEQUENCE, each op once, exits when the sequence completes/fails), and disabled. All modes keep the continuous writer/verifier workload active.

Sequence mode powers a new PR smoke gate — .github/workflows/longhaul-smoke.yml — that builds the operator/sidecar from the PR, stands up a real DocumentDB on kind, and runs the actual driver through scale-up → scale-down → upgrade-documentdb → kill-operator-pod → kill-primary-pod once each, asserting every op reaches PASSED, the run reaches COMPLETE, and the backup verifier scheduled+completed a snapshot. The upgrade-documentdb step is a real cross-version rolling upgrade between two published releases (0.110.0 → 0.113.0, both hardcoded and pulled from the public registry — the smoke builds no database image), exercising the operator's rolling-update path with clean semvers the image-rollback webhook accepts.

Design notes

  • Operator discovery. The operator Deployment name is a chart-pinned literal (documentdb-operator, singleton install), so it is a safe constant; the namespace is install-overridable, exposed as LONGHAUL_OPERATOR_NAMESPACE (default documentdb-operator). There is no back-reference from the DocumentDB CR to the operator, so cluster-derived discovery isn't viable. kill-operator-pod builds its pod selector from the Deployment's own spec.selector.matchLabels rather than a hardcoded label (the operator label is release-name dependent), and refuses to proceed on an empty selector so it can never list/delete every pod in the namespace.
  • Primary discovery. kill-primary-pod reads the CNPG Cluster.Status.CurrentPrimary (CNPG cluster name == DocumentDB CR name) to target the primary pod, then waits for the promoted primary to change and steady state to return.
  • HA guard. kill-primary-pod and upgrade-documentdb skip (do not fail) when instancesPerNode<2 — the disruption would be guaranteed downtime with no standby. Skips don't consume the scheduler cooldown and are re-evaluated on the next tick.

Changes

  • operations/kill_operator.go, operations/kill_primary.go (+ unit tests): the two chaos ops.
  • operations/{registry,runner,sequence}.go (+ tests) and operations/scheduler.go: the operation runner with random / sequence / disabled modes.
  • journal/policy.go, journal/journal.go: duration-based OutagePolicy, WritesPerSecond per window + EstimatedWriteOutage, SetWriteRate, and the shared NoOutagePolicy / PrimaryHandoverPolicy / UpgradeOutagePolicy helpers.
  • workload/writer.go: AggregateWriteRate(numWriters).
  • monitor/{health,k8sclient}.go: GetPrimaryInstance / DeletePod on ClusterClient; CNPG scheme registration.
  • operations/scale.go, operations/upgrade.go: adopt the shared policies (scale ops were previously over-lenient count budgets; upgrade gets its own 90s budget).
  • config/config.go: LONGHAUL_OPERATOR_NAMESPACE, LONGHAUL_OPERATION_MODE, LONGHAUL_OPERATION_SEQUENCE + validation.
  • report/{report,checkpoint}.go: disruption-window table gains an Est. Write Outage column; report exposes operation-status / operation-results / operation-aggregates.
  • cmd/longhaul/main.go: supply the write rate to the journal; wire up the operation mode; register both ops.
  • deploy/rbac.yaml: chaos-op RBAC (see below).
  • .github/workflows/longhaul-smoke.yml: the sequence-mode PR smoke gate.
  • docs/designs/long-haul-test-design.md / test/longhaul/README.md: README slimmed to a runner's guide; design doc gains the outage-budget, backup-verification, HA-precondition, and e2e-relationship rationale.
  • go.mod: promote cloudnative-pg to a direct dependency.

RBAC

Included in deploy/rbac.yaml: the driver ServiceAccount gets get/list on clusters.postgresql.cnpg.io + delete on pods (kill-primary), and, via a namespace-scoped Role/RoleBinding on LONGHAUL_OPERATOR_NAMESPACE, get on deployments + get/list/delete on pods in the operator namespace (kill-operator). Documented in test/longhaul/README.md.

Verification

cd test/longhaul
go build ./...   # clean
go vet ./...     # clean
go test ./...    # all packages pass

The Long-Haul Smoke Gate runs the full sequence (including the real 0.110.0 → 0.113.0 upgrade) green on kind.

Follow-up tasks

  • Improve write-outage measurement to handle concurrent writers correctly. Do not end an outage after a single writer succeeds; require a stronger recovery signal, such as consecutive successful writes from all active writers or a continuous healthy-write interval. Add unit tests covering overlapping failures, partial recovery, and recovery after all writers resume.

@documentdb-triage-tool documentdb-triage-tool Bot added dependencies Pull requests that update a dependency file documentation Improvements or additions to documentation enhancement New feature or request test labels Jul 10, 2026
@documentdb-triage-tool

Copy link
Copy Markdown

🤖 Auto-triaged by documentdb-triage-tool.

Applied: test, documentation, dependencies, enhancement
Project fields suggested: Component test · Priority P2 · Effort XL · Status In Progress
Confidence: 0.88 (mixed)

Reasoning

component from path globs (test, docs, dependencies); effort from diff stats (746+78 LOC, 23 files); LLM: Adds new chaos fault-injection operations (kill-operator-pod, kill-primary-pod) to the long-haul test suite, touching multiple files across the test infrastructure including health monitoring, k8s client, config, and operation implementations.

If a label is wrong, remove it manually and ping @patty-chow so the rules can be tuned. The bot will not re-label items that already have component labels.

@WentingWu666666 WentingWu666666 changed the title test: add kill-operator-pod and kill-primary-pod chaos operations to long-haul test(longhaul): add kill-operator-pod and kill-primary-pod chaos operations Jul 10, 2026
@WentingWu666666
WentingWu666666 marked this pull request as ready for review July 10, 2026 17:52
@WentingWu666666
WentingWu666666 requested a review from xgerman as a code owner July 10, 2026 17:52
Copilot AI review requested due to automatic review settings July 10, 2026 17:52

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

wentingwu000 and others added 6 commits July 14, 2026 15:00
Add the first two chaos fault-injection operations to the long-haul
operation scheduler:

- kill-operator-pod: deletes the operator pod via its Deployment selector
  and waits for the Deployment to become Available again. Asserts the CNPG
  data plane is unaffected by an operator restart (small write-failure
  budget).
- kill-primary-pod: deletes the CNPG primary pod to exercise the automatic
  failover path, guarded by an HA precondition (instancesPerNode>=2).

Both plug into the existing Operation interface and are selected by the
weighted scheduler (one disruptive op at a time, cooldown + steady-state
gate). Recovery is judged by the health monitor and workload verifier.

Adds ClusterClient.GetPrimaryInstance (reads CNPG Cluster
status.currentPrimary) and DeletePod, a LONGHAUL_OPERATOR_NAMESPACE
config knob (default documentdb-operator), unit tests, and README
operations + RBAC notes.

Controlled failover was intentionally excluded: DocumentDB exposes no
single-cluster manual switchover, so it would only test upstream CNPG.

Co-authored-by: Copilot <[email protected]>
Signed-off-by: Wenting Wu <[email protected]>
Introduce journal.NoOutagePolicy (and the NoOutageWriteFailureCushion
constant) as the single budget for operations that keep the write path
(client -> gateway -> primary) up throughout, so they must not cause write
failures. Apply it to:

- kill-operator-pod (control-plane fault; was an inline budget of 5), and
- scale-up / scale-down, which only add/remove a standby replica — the
  primary is never touched, so their previous ad-hoc budgets (20 / 50) were
  too lenient and could mask a regression that disrupted writes.

The cushion is a small non-zero value (5) that absorbs unrelated background
noise without tolerating a real outage: at the default workload rate
(~50 writes/s) it is well under a second of stray errors. Centralizing it
lets the value be recalibrated against real long-haul runs in one place.

Co-authored-by: Copilot <[email protected]>
Signed-off-by: Wenting Wu <[email protected]>
Express OutagePolicy as a wall-clock write-outage duration
(MaxWriteOutage) instead of a raw write-failure count. The journal
converts the observed failure count into an estimated outage using the
workload's aggregate write rate, so budgets no longer scale with
LONGHAUL_NUM_WRITERS.

- policy: OutagePolicy.AllowedWriteFailures -> MaxWriteOutage;
  DisruptionWindow gains WritesPerSecond + EstimatedWriteOutage();
  NoOutageWriteFailureCushion -> NoOutageWriteOutageCushion (300ms).
- journal: New() defaults to DefaultWritesPerSecond; SetWriteRate lets
  main.go supply the real rate; OpenDisruptionWindow stamps the rate.
- workload: expose AggregateWriteRate(numWriters).
- ops: kill-primary 30s, upgrade 45s (was 50/200 failures).
- report: surface Est. Write Outage column.

Co-authored-by: Copilot <[email protected]>
Signed-off-by: Wenting Wu <[email protected]>
Document that MaxWriteOutage (data plane) and MustRecoverWithin
(control plane) assert on orthogonal subsystems and fail independently,
and that MustRecoverWithin is the only path that fails the run when the
cluster never converges (op errors are logged, not scored).

Co-authored-by: Copilot <[email protected]>
Signed-off-by: Wenting Wu <[email protected]>
MustRecoverWithin bounds the managed database cluster's return to full
topology (all pods Ready, CR Ready) — not the operator/control plane.
Reframe as write-availability vs. full-topology recovery to avoid
implying scale/kill-primary recovery involves the operator.

Co-authored-by: Copilot <[email protected]>
Signed-off-by: Wenting Wu <[email protected]>
kill-primary-pod and upgrade-documentdb both interrupt writes for a
single primary handover, so they now share journal.PrimaryHandoverPolicy
(30s) instead of diverging (was 30s vs 45s). The 45s was inflated by
conflating the rolling upgrade's whole-topology restart with its
write-outage window; that longer restart is bounded by MustRecoverWithin
instead. A graceful switchover (upgrade) is no worse than an ungraceful
failover (kill-primary), which also pays a detection delay.

Co-authored-by: Copilot <[email protected]>
Signed-off-by: Wenting Wu <[email protected]>
@WentingWu666666
WentingWu666666 force-pushed the developer/wentingwu/longhaul-chaos-ops branch from ace474b to 40c62ce Compare July 14, 2026 19:00
deploy/rbac.yaml now exists on main (added by documentdb#413), so add the chaos
operations' required verbs rather than leaving them as a follow-up:

- kill-primary-pod: get/list on clusters.postgresql.cnpg.io and delete
  on pods, added to the longhaul-test Role in the target namespace.
- kill-operator-pod: a separate longhaul-test-operator Role/RoleBinding
  in the operator namespace (documentdb-operator) granting get on
  deployments and get/list/delete on pods, since the operator runs
  outside the driver's own namespace.

Update the README RBAC section to reflect that the verbs are now granted.

Co-authored-by: Copilot <[email protected]>
Signed-off-by: Wenting Wu <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 24 out of 24 changed files in this pull request and generated 5 comments.

Comment thread test/longhaul/deploy/rbac.yaml Resolved
Comment thread test/longhaul/deploy/rbac.yaml Resolved
wentingwu000 and others added 2 commits July 23, 2026 13:13
Address PR documentdb#421 review:
- kill-operator-pod: fail fast when the operator Deployment has no
  matchLabels selector, so SelectorFromSet can't produce an everything
  selector that lists/targets unrelated pods.
- kill-operator-pod: after deleting the pod, wait until that specific pod
  (by UID) is actually gone before checking Deployment availability. Pod
  deletion doesn't bump ObservedGeneration, so status can stay Available
  and mask the restart otherwise.
- kill-primary-pod: validate GetPrimaryInstance returned a non-empty pod
  name and guard the health monitor against nil before dereferencing.
- rbac.yaml: note that the operator-namespace Role/RoleBinding must be kept
  in sync with LONGHAUL_OPERATOR_NAMESPACE.

Add unit tests for the empty-selector and empty-primary guard paths.

Co-authored-by: Copilot <[email protected]>
Signed-off-by: Wenting Wu <[email protected]>
…/longhaul-chaos-ops

Signed-off-by: Wenting Wu <[email protected]>

# Conflicts:
#	test/longhaul/config/config.go
#	test/longhaul/deploy/rbac.yaml
@WentingWu666666
WentingWu666666 marked this pull request as draft August 21, 2026 19:27
wentingwu000 and others added 3 commits August 21, 2026 15:49
Introduce a without-replacement "coverage mode" so the CI smoke gate
exercises the production random scheduler path while still guaranteeing
every operation runs at least once. Adds LONGHAUL_OPERATION_COVERAGE and
LONGHAUL_OPERATION_SEED config, seeded RNG + completion-driven Run loop in
the scheduler, and switches longhaul-smoke.yml from sequence to
random+coverage with a jq assertion on operation-aggregates. Includes the
operations registry/sequence/runner refactor, journal and report updates,
and accompanying unit tests.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: dceb76cc-e7c1-40f2-92ad-3b6de007281c
Signed-off-by: Wenting Wu <[email protected]>
…>0.113.0 upgrade

Replace the random coverage/seed scheduler machinery with an explicit
sequence mode for the long-haul smoke gate so the PR gate deterministically
exercises each operation (scale-up, scale-down, upgrade-documentdb,
kill-operator-pod, kill-primary-pod) exactly once, in order, and asserts
every one reached PASSED with the run COMPLETE.

Make upgrade-documentdb a real cross-version rolling upgrade: start the
cluster on the most recent published release before the under-test version
(0.110.0; 0.111/0.112 were never published) via setup-test-environment
image overrides, convert the CR to version-based references, then move
documentDBVersion forward to the chart's documentDbVersion. Both endpoints
are clean semvers so the image-rollback admission webhook accepts the patch
(the previous non-semver candidate tag was Forbidden by the webhook).

Removes OperationCoverage/OperationSeed config, the scheduler's rng/coverage
selection, and their tests; keeps plain random mode intact.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: dceb76cc-e7c1-40f2-92ad-3b6de007281c
Signed-off-by: Wenting Wu <[email protected]>
wentingwu000 and others added 7 commits August 28, 2026 11:12
A real cross-version rolling upgrade (0.110.0 -> 0.113.0) in the smoke gate
measured a ~33s primary-switchover write outage, tripping the 30s
PrimaryHandoverWriteOutage budget that upgrade-documentdb previously shared
with kill-primary-pod. That shared budget assumed a graceful upgrade
switchover is no worse than an ungraceful failover, but the upgrade switchover
is heavier: it coincides with the extension version migration under live write
load and the new primary must come up on the new image before accepting writes.

Split the budgets: add UpgradeWriteOutage (90s) / UpgradeOutagePolicy and use
it for upgrade-documentdb, leaving kill-primary-pod on the 30s failover budget.
The value carries headroom over the observed ~33s (and CI variance) while still
catching a gross multi-minute regression; the whole-topology restart stays
bounded by MustRecoverWithin. Calibration backed by a real long-haul upgrade,
as the prior heuristic comment invited.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: dceb76cc-e7c1-40f2-92ad-3b6de007281c
Signed-off-by: Wenting Wu <[email protected]>
Sequence mode paces operations entirely via the steady-state and recovery
gates (SequenceRunner never consults the cooldown); LONGHAUL_OP_COOLDOWN is a
random-scheduler-only rate limiter. Setting it in the sequence-mode smoke
ConfigMap had no effect, so remove it and note why to avoid implying it does
something.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: dceb76cc-e7c1-40f2-92ad-3b6de007281c
Signed-off-by: Wenting Wu <[email protected]>
- Trim 'RBAC for chaos operations' to the one actionable fact (kill-operator-pod
  needs cross-namespace access via LONGHAUL_OPERATOR_NAMESPACE); rbac.yaml grants
  the rest. Drop the verb-by-verb Role breakdown, which is design detail.
- Simplify the outage-budget prose: remove internal type names (journal.*,
  OutagePolicy, AggregateWriteRate) and point to the design doc for exact
  policies, keeping the user-relevant concepts (~30s failover, ~90s upgrade).
- Fix an outdated claim: the smoke upgrade is now a real cross-version upgrade
  (start on the last published release, upgrade forward to the under-test
  version), not a same-image second-tag retag.
- Note LONGHAUL_OP_COOLDOWN is random-mode only.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: dceb76cc-e7c1-40f2-92ad-3b6de007281c
Signed-off-by: Wenting Wu <[email protected]>
The smoke's cross-version upgrade target was re-tagged from the build
artifact's candidate documentdb/gateway images. Since the database images
are never actually built (the under-test release is public), pull the
released target images straight from the public registry instead, exactly
like the 0.110.0 base override. This makes the smoke's intent explicit: it
upgrades between two published database releases (0.110.0 -> under-test) and
builds no database image.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: dceb76cc-e7c1-40f2-92ad-3b6de007281c
Signed-off-by: Wenting Wu <[email protected]>
Pin the upgrade target to DB_TARGET_VERSION (0.113.0) alongside the already
hardcoded DB_BASE_VERSION, instead of deriving it from ext_image_tag. Both
endpoints of the smoke's upgrade are now explicit, published releases pulled
from the public registry, keeping the two versions co-located and easy to
bump with the chart's documentDbVersion.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: dceb76cc-e7c1-40f2-92ad-3b6de007281c
Signed-off-by: Wenting Wu <[email protected]>
Both upgrade endpoints are now hardcoded (DB_BASE_VERSION=0.110.0,
DB_TARGET_VERSION=0.113.0), so replace the misleading "under-test" phrasing
that implied the target auto-follows the chart's documentDbVersion. Also fix
comments that suggested the database images come from the build artifact:
the base and target are pulled from the public registry, and documentdb-image-tag
is only kept to satisfy the shared action's mandatory DB-image load.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: dceb76cc-e7c1-40f2-92ad-3b6de007281c
Signed-off-by: Wenting Wu <[email protected]>
The README is the operator's guide for people running the long-haul harness;
several blocks were design rationale, not how-to. Move them to the design doc
and leave the README with what a runner needs:

- Outage-budget specifics and the HA auto-skip rationale -> design (Operations).
- Backup verifier internals (scheduling liveness, 3-schedule completion gap,
  retention-leak arithmetic, black-box oracle) -> design (Backup Verification).
- The test/e2e comparison table, shared-code, and future opportunities -> design
  (Relationship to test/e2e/).

The README now links into those design sections and keeps the concise,
actionable summaries (prerequisites, RBAC, config table, operations catalog,
CI-safety pointer).

Co-authored-by: Copilot <[email protected]>
Copilot-Session: dceb76cc-e7c1-40f2-92ad-3b6de007281c
Signed-off-by: Wenting Wu <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Runner termination, recovery gating, outage measurement, and smoke-test timing contain correctness issues.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details
  • Files reviewed: 38/38 changed files
  • Comments generated: 7
  • Review effort level: Balanced

Comment thread test/longhaul/cmd/longhaul/main.go Resolved
Comment thread test/longhaul/journal/policy.go Resolved
Comment thread test/longhaul/operations/sequence.go Resolved
Comment thread .github/workflows/longhaul-smoke.yml Resolved
Comment thread test/longhaul/README.md Resolved
wentingwu000 and others added 3 commits September 3, 2026 10:53
Address Copilot review feedback on the long-haul chaos harness:

- kill_operator: after the targeted pod is gone, wait for a *replacement*
  pod (different UID) to reach Running+Ready before trusting the
  Deployment-level availability check. Deleting a pod does not bump the
  Deployment generation, so its status can still count the pre-deletion
  replica as Ready and report a false recovery.
- health/sequence/scheduler: add HealthMonitor.InvalidateSteadyState and
  reset the steady-state epoch when opening a disruption window, so the
  post-operation recovery gate must observe a health sample taken after the
  disruption rather than being satisfied instantly by a stale steadySince.
- docs: qualify HA auto-skip as random-mode behaviour (sequence mode waits
  then fails); fix outdated kill-primary OutagePolicy comment.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: dceb76cc-e7c1-40f2-92ad-3b6de007281c
Signed-off-by: Wenting Wu <[email protected]>
Address two more Copilot review findings:

- scheduler/main: a terminal operation failure in random mode now ends the
  run immediately (Scheduler.Run returns and closes Done; main reacts to it)
  instead of looping until MaxDuration, which is unbounded in production and
  meant a real failure never surfaced a verdict.
- journal/policy/writer: replace the write-failure-count / write-rate outage
  estimate with a timestamp-based measurement. A synchronous InsertOne blocks
  for the full server-selection timeout and errors only once, so a 30s outage
  produced ~1 failure and an estimate of ~100ms — a false PASS on the core
  safety check. Writers now report every attempt outcome with its start time
  and the window measures the outage as first-failing-attempt ->
  first-subsequent-success (open outages measured to window end). Removes the
  now-unused write-rate plumbing (SetWriteRate/AggregateWriteRate).

Co-authored-by: Copilot <[email protected]>
Copilot-Session: dceb76cc-e7c1-40f2-92ad-3b6de007281c
Signed-off-by: Wenting Wu <[email protected]>
The retention pruner used a hardcoded 5m interval, so the smoke gate's
"pruner pruned N docs" assertion depended on the sequence run happening to
outlast the default first tick. Sequence mode exits on operation completion,
which can be faster.

Add LONGHAUL_PRUNE_INTERVAL (default 5m) plumbed through the config and the
Pruner, and set it to 30s in longhaul-smoke.yml so a real prune reliably
fires within the bounded window. Document the new knob in the runner README.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: dceb76cc-e7c1-40f2-92ad-3b6de007281c
Signed-off-by: Wenting Wu <[email protected]>
@WentingWu666666
WentingWu666666 marked this pull request as ready for review September 4, 2026 18:26
wentingwu000 and others added 2 commits September 15, 2026 10:51
- monitor/health: a health sample fetched before InvalidateSteadyState could
  publish its stale healthy result afterwards and re-establish steadySince,
  letting the post-operation gate pass without observing post-disruption
  health. Snapshot an invalidation generation before the (unlocked) fetch and
  discard the sample if it moved while the fetch was in flight.
- operations/kill-primary: GetPrimaryInstance and DeletePod are not atomic, so
  an unrelated failover between them made the op delete a former primary and
  accept the already-completed promotion as success. Re-confirm the primary
  immediately before the delete, abort on an unexpected change, and key the
  change/verification off the pod actually deleted.
- journal: write outcomes arrive in completion order but the outage span is
  computed from attempt-start times. A success that began before the outage
  opened produced a negative gap and wrongly cleared WriteOutageStart, erasing
  a real outage. Ignore successes whose attempt predates the outage start, and
  track the earliest failing attempt so out-of-order failures measure correctly.

Each fix has a regression test that reproduces the race deterministically
(interleaved invalidate, pre-delete promotion, out-of-order write outcomes).

Co-authored-by: Copilot <[email protected]>
Copilot-Session: dceb76cc-e7c1-40f2-92ad-3b6de007281c
Signed-off-by: Wenting Wu <[email protected]>
The "Assert PASS verdict" step grepped the rendered report for a
"pruner: pruned N docs" line, but the report only renders the last ~20
journal events. When kill-primary runs last, its failover floods the
event tail with transient InternalError prune/verify warnings, aging out
the earlier prune-success lines and failing the gate on an otherwise
passing run.

Replace the brittle event-tail grep with a durable metric: add a
DocsPruned counter to workload.Metrics (incremented in pruneWriter),
surface it in MetricsSnapshot, the markdown report, and a new
docs-pruned key on the longhaul-report ConfigMap. The smoke gate now
asserts docs-pruned > 0, which survives the bounded event ring.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: dceb76cc-e7c1-40f2-92ad-3b6de007281c
Signed-off-by: Wenting Wu <[email protected]>

@xgerman xgerman left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requesting changes for three correctness issues that can hide real failures in the long-haul test: outage duration is under-counted, normal random-mode expiry can be reported as an operation failure, and a pod restart can erase the durable failure verdict.

Comment thread test/longhaul/journal/journal.go Resolved
Comment thread test/longhaul/operations/scheduler.go Resolved
Comment thread test/longhaul/report/checkpoint.go Resolved
wentingwu000 and others added 7 commits September 16, 2026 10:56
Resolve three issues xgerman flagged that can hide real failures in the
long-haul harness:

1. Write outage under-counted (journal.go). The outage was measured to
   the recovering write's *start*, but recovery is only proven when that
   call completes — during a failover the successful write can block in
   server selection for many seconds. RecordWriteOutcome now takes the
   attempt completion time and measures attemptEnd - outageStart, so an
   over-budget failover can no longer slip past the gate. attemptStart is
   retained solely to reject stale in-flight successes.

2. Normal bounded-run expiry reported as FAIL (scheduler.go). When a
   random-mode run reached its configured duration while an operation was
   waiting for recovery, the parent-context cancellation surfaced as an
   operation error and was recorded as a failure. executeOp now detects
   parent-context cancellation and returns a sentinel (errRunInterrupted)
   that the run loop treats as a clean shutdown, never a FAIL.

3. Restart erases the FAIL verdict (checkpoint.go). emit replaced the
   whole ConfigMap data, so an auto-restarted driver's fresh RUNNING
   checkpoint overwrote a prior FAIL. Latch durable incident state
   (incident-latched, monotonic incident-count, first/last failure
   reason+time) carried forward from the existing ConfigMap. The hourly
   longhaul-monitor workflow now pages on the latched incident, not just
   the transient result.

Adds regression tests for each: an early-start/late-complete recovering
write, a context cancelled inside Execute, and a fresh checkpoint over an
existing failed ConfigMap.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: dceb76cc-e7c1-40f2-92ad-3b6de007281c
Signed-off-by: Wenting Wu <[email protected]>
actionlint (filter_mode: file) now flags actions/checkout@v4 and
actions/download-artifact@v4 as errors because their node20 runtime is
deprecated (removal 2026-09-23). Editing longhaul-monitor.yaml and
longhaul-smoke.yml brought the whole files under lint, so bump their
checkout/download-artifact pins to @v5 (node24). download-artifact@v5
remains compatible with the build workflow's upload-artifact@v4 outputs.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: dceb76cc-e7c1-40f2-92ad-3b6de007281c
Signed-off-by: Wenting Wu <[email protected]>
The 0.110.0 -> 0.113.0 cross-version upgrade failed in CI: the primary
pod's postgres container never became healthy on the 0.113.0 image within
the operation's recovery budget (operator logged "container not found
(postgres)" and repeatedly skipped the extension upgrade). Retarget the
smoke to the newer published pair 0.116.0 -> 0.117.0 (both present in the
public registry) and update the accompanying comments and step name.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: dceb76cc-e7c1-40f2-92ad-3b6de007281c
Signed-off-by: Wenting Wu <[email protected]>
Raise LONGHAUL_RECOVERY_TIMEOUT from 5m to 10m so operations (notably the
cross-version upgrade) get more headroom to reach steady state before the
op is failed. Update the in-code default, its unit test, the README env
table, the deployment ConfigMap, and the smoke-gate override — the smoke's
5m budget is exactly what the upgrade hit when it timed out.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: dceb76cc-e7c1-40f2-92ad-3b6de007281c
Signed-off-by: Wenting Wu <[email protected]>
actions/download-artifact ships no node24 major yet — v4, v5 and v6 all
still declare `using: node20` — so the node20 deprecation actionlint now
raises cannot be cleared by a version bump. Pass `-ignore node20` to the
actionlint step so this single, upstream-blocked deprecation stops failing
the long-haul lint gate while every other diagnostic still gates. The
pattern is space-free so it survives the action's shell word-splitting.
checkout stays on @v5 (which does provide a node24 runtime).

Co-authored-by: Copilot <[email protected]>
Copilot-Session: dceb76cc-e7c1-40f2-92ad-3b6de007281c
Signed-off-by: Wenting Wu <[email protected]>
The latched-incident error annotation inlined two `${{ }}` step outputs on
one line, pushing it to 274 chars and tripping yamllint's 200-char limit.
Hoist the last-failure reason/time into shell vars so the physical YAML
line stays under the limit; the emitted annotation is unchanged.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: dceb76cc-e7c1-40f2-92ad-3b6de007281c
Signed-off-by: Wenting Wu <[email protected]>
The smoke gate's kill-primary-pod step measured a 30.292s write outage
against a 30s budget and failed by ~292ms, even though the failover itself
was healthy (full-topology recovery in 52s). The 30s value was an explicit
"heuristic pending calibration against real long-haul runs" placeholder.

An ungraceful failover cannot start promoting a standby until CNPG detects
the lost primary pod, so detection latency stacks on top of the promotion —
on a resource-constrained kind runner that lands right around 30s. Raise
PrimaryHandoverWriteOutage to 60s so a healthy failover on slow CI is not
flagged while a multi-minute write stall still is, mirroring how the upgrade
budget was calibrated (measured ~33s -> 90s budget). The accurate
attempt-end outage measurement added earlier in this PR is what surfaced
that the old budget was a hair too tight.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: dceb76cc-e7c1-40f2-92ad-3b6de007281c
Signed-off-by: Wenting Wu <[email protected]>

@xgerman xgerman left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed the latest head. The three previously blocking issues are fixed with regression coverage: write outages use successful completion time, expected random-mode cancellation is not recorded as failure, and durable incident state survives driver restarts and is consumed by the monitor. The long-haul race tests, vet, smoke workflow, and required CI checks pass.

@WentingWu666666
WentingWu666666 merged commit 258b0e3 into documentdb:main Sep 17, 2026
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file documentation Improvements or additions to documentation enhancement New feature or request test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants