Repository navigation
test(lifecycle): add regression coverage - #1843
Merged
Merged
Conversation
This was referenced Oct 3, 2026
FlorentinDUBOIS
force-pushed
the
codex/sozu-lifecycle-regression-tests
branch
3 times, most recently
from
October 4, 2026 01:28
fc14f9a to
2f78aaf
Compare
FlorentinDUBOIS
added a commit
that referenced
this pull request
Oct 4, 2026
Fixes #1828. Long-lived sessions can emit cluster and backend metrics after `RemoveCluster`. When the same cluster, backend id, and address are recreated, those delayed events must not update the replacement lifetime. This change gives each effective cluster lifetime an internal metrics incarnation captured by the request, route, pipe, or backend owner that may emit later. Labelled `cluster` and `backend` metrics reach the drains only while that captured incarnation is still active. Process and frontend aggregates continue to accept the same physical events after their labels are removed, so late decrements still balance the aggregate gauges they previously incremented. The public `SessionMetrics` literal shape and `register_end_of_session` behavior remain compatible. The lifetime rules are: - the first legal route can allocate an implicit identity before `AddCluster`; - `AddCluster` without an intervening removal preserves that identity; - `RemoveCluster` deletes the active identity and tombstones both drains; - the first legal route after removal allocates a different identity and re-arms both drains, so a replacement created without `AddCluster` is visible immediately while the removed identity remains fenced; - `metrics clear`, detail changes, and collection disable/enable do not reset an active identity; - identity exhaustion is a distinct invalid capture: labelled metrics fail closed and removed-drain tombstones remain armed. HTTP captures the identity per routed request or stream, so an H1 keep-alive connection can reroute correctly. TCP static and SNI routing capture once for the selected route and do not adopt a later incarnation during retry. Proxy-level connection metrics remain separate and still record physical closes. Documentation and regression coverage are included in the same changeset. The decisive strict H1 runtime test holds an old session, removes and recreates the same cluster/backend/address, observes the proxy gauge transition from 2 to 1, verifies the replacement remains at 1, then consumes a new response metric before checking that the old close did not contaminate the new row. Additional tests cover legal routing without `AddCluster`, implicit identity continuity across an add, remove/clear fencing, replacement re-arm without an add, process/frontend aggregation, exhaustion, public API compatibility, and TCP static/SNI capture. Validation: - `cargo test -p sozu-lib metrics::tests --locked -j 4 -- --nocapture`: 34 passed - `cargo test -p sozu-e2e real_http_session_without_add_cluster_records_labelled_metrics --locked -j 4 -- --nocapture`: 1 passed - `cargo test -p sozu-e2e test_old_http_session_metrics_do_not_decrement_same_identity_replacement --locked -j 4 -- --nocapture`: 1 passed with proxy 2→1, replacement 1→1, new 2xx metric 1, and clean worker shutdown - On the exact intended composition `main@9561b24 + #1845 product delta + #1843 tests@2f78aaf928b2241241713cbba28ff4abdc1f0926`, the independent checker replayed the retained #1843 H1 oracle 1/1 and the new H2/WebSocket oracles 2/2. The #1843 H1 case preserves the cluster id but deliberately uses distinct old/new backend ids and addresses; the strict same-cluster/backend/address H1 case above remains the #1845 oracle. - The H2 oracle uses one real TLS connection negotiated with ALPN, holds stream 1 across remove/recreate, lets stream 3 complete on the replacement over that same connection, then observes the old stream terminate without decrementing the replacement incarnation. - The WebSocket oracle observes a real HTTP `101` promotion into `Pipe`, exchanges structurally valid framed data in both directions for both lifetimes, and preserves access counts `1→1→2` and WebSocket gauges `2→1→0`. Its fixture omits `Sec-WebSocket-Accept`, so it proves pipe lifecycle/accounting rather than a complete RFC 6455 handshake. - On the owner overlay `#184591e8a42 + complete #1843 test content`, the functional run passed 628 tests with exactly four existing `cargo fuzz` wrappers filtered. That overlay predates merged #1844; only the focused H1, H2, and WebSocket replays above were checked on the exact `main@9561 + #1845 product + #1843 tests` composition. - `cargo clippy -p sozu-lib -p sozu-e2e --all-targets --locked -j 4 -- -D warnings`: passed on product-identical source - `cargo fmt --all -- --check`, documentation citations, and `git diff --check`: passed - the replacement-rearm regression was observed red before the fix; an invalid-exhaustion re-arm mutation was observed red before restoration The accepted H2 and WebSocket runtime tests are published by #1843, not by this PR, so they are absent from #1845's 27/27 CI run at `91e8a421`. TCP static and SNI capture remain covered by focused unit tests without a dedicated teardown runtime scenario. The network drain re-arm remains source-coupled with the local drain and compile/lint covered; the decisive post-removal replacement and exhaustion probes exercise the local drain rather than a UDP runtime. ### Follow-ups (90fbeb2, 3b73653, 91e8a42) - A cluster referenced by a route before any `AddCluster` gets its metrics identity on that first route; a later `AddCluster` reuses it and only `RemoveCluster` ends it. Capture states are `Missing` / `Active` / `Invalid` (exhaustion), and only an `Active` capture matching the current identity is accepted at Cluster/Backend detail; Process/Frontend aggregates accept every state. - A route that recreates a removed id without `AddCluster` allocates a fresh identity and re-arms the drains; exhaustion leaves them fenced. - TCP captures once at routing; `record_backend_metrics!` checks once per invocation. - Known limit: an id never declared with `AddCluster` cannot be removed (the main process rejects `RemoveCluster` for it), so its identity entry lives as long as the worker. Signed-off-by: Florentin Dubois <[email protected]>
Signed-off-by: Florentin Dubois <[email protected]>
Signed-off-by: Florentin Dubois <[email protected]>
Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS
force-pushed
the
codex/sozu-lifecycle-regression-tests
branch
from
October 4, 2026 09:40
2f78aaf to
1b23fd8
Compare
FlorentinDUBOIS
marked this pull request as ready for review
October 4, 2026 10:41
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Lifecycle regression contracts were scattered across issue descriptions and local reproducers. This draft collects replayable regression tests, deterministic process harnesses, and their test documentation. It contains no product fix.
The branch is rebased onto
mainatc0edfa8fb6462f9b895c3b1a2daaabef1251095b, which already contains the metrics incarnation fix and the normative pending-command main-upgrade implementation. This draft preserves all current-main tests and adds only lifecycle coverage that remains distinct.The metrics lifecycle coverage exercises three real session paths across
RemoveClusterfollowed by recreation:AddClustertests.101transition intoPipeplus framed bidirectional data, and proves that the old pipe cannot increment the replacement's access row. The synthetic backend response intentionally omitsSec-WebSocket-Accept, so this is a lifecycle/pipe oracle rather than a complete RFC 6455 negotiation test.The direct
LocalDraintest namedreadded_cluster_rejects_late_emission_from_previous_incarnationis excluded after independent review. A drain sees already-labelled events and cannot distinguish an old incarnation from a new one; fencing belongs to captured identities in the aggregator and protocol callers. The valid drain remove/add/clear tests and the public legacy metric path remain covered on current main.The branch preserves its other unique lifecycle coverage: admission lease restoration; load-state replay with rollback of entries refused by workers plus incremental application of a valid prefix before a malformed suffix, without promising whole-file atomicity; logging backpressure; sticky H1 behavior; TCP upgrade and half-close observations; the stronger three-run abandoned-lease TTL oracle with positive traffic and
TTL + 5s; and a real event-loop test for the earliest silent-worker task deadline.The older process characterization for main upgrade is excluded because current main's normative test subsumes its observables and adds stronger guarantees: a pending command survives handoff, client A and client B receive one terminal response each, the new PID takes over, HTTP continues, and client C progresses after handoff.
Validation of the rebased candidate:
sozu-command-lib: 247 library tests and all auxiliary test targets passed.sozu --lib: 157 passed, 0 failed.git diff --check: exit 0.3aefdac06de2022f7ae9d735fd0b21365c216bbf92717ac1dea9792dfc9ffb01) with no finding and independently replayed metrics 9/9, both deadline-poll contracts, and the normative upgrade test.The complete local functional E2E run is UNVERIFIED: with exactly the four existing fuzz-test wrappers that invoke
cargo fuzzfiltered, the command reached its 1,800-second timeout while progressing through H2 tests (exit 124), before Cargo emitted a terminal test summary. It emitted no anchoredFAILEDline, but that is not a passing result. The complete CI run on the published head remains the merge gate.The four existing fuzz-test wrappers that invoke
cargo fuzzand a complete RFC 6455 handshake are outside this draft's local validation scope. No failing assertion is skipped or weakened.Refs #1821
Refs #1822
Refs #1823
Refs #1824
Refs #1825
Refs #1826
Refs #1827
Refs #1828
Refs #1829
Refs #1830
Refs #1831
Refs #1832