Repository navigation
fix(metrics): isolate cluster incarnations - #1845
Merged
Merged
Conversation
Collaborator
Author
|
Review of 1bede9e. Fix requested before merge. The #1828 regression test fails on main and passes on this head. The design (an incarnation captured per request and checked when the metric is emitted) looks right. One HIGH issue needs fixing first: 1. HIGH: cluster-labelled metrics are dropped when no incarnation was captured, at every detail level.
2. LOW: the TCP capture is not one-shot.
3. LOW, performance: the incarnation arm of Checked and fine:
Verification:
|
Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS
force-pushed
the
fix/metrics-cluster-incarnation-1828
branch
from
October 3, 2026 22:57
1bede9e to
c61d1a3
Compare
…once A cluster referenced by frontends or backends without an AddCluster has no metrics incarnation, so its owners capture `None`. The incarnation gate returned early on a `None` capture before checking the effective detail, which dropped every cluster-labelled metric for such a cluster at every detail level, including the Process-detail worker aggregate. Compare the captured and current incarnations as optional values, and only at cluster and backend detail: `None == None` is recorded, any mismatch (including a missed `None` capture against a current incarnation) is still rejected. After the 64-bit incarnation space is exhausted, new clusters share `None` with undeclared ones. The TCP session now captures the incarnation exactly when its route is first set, instead of re-capturing on a retry while the value is `None` or again in the SNI preread upgrade. `record_backend_metrics!` performs a single identity lookup per invocation instead of one per emission. Signed-off-by: Florentin Dubois <[email protected]>
Signed-off-by: Florentin Dubois <[email protected]>
Signed-off-by: Florentin Dubois <[email protected]>
This was referenced Oct 4, 2026
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.
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
clusterandbackendmetrics 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 publicSessionMetricsliteral shape andregister_end_of_sessionbehavior remain compatible.The lifetime rules are:
AddCluster;AddClusterwithout an intervening removal preserves that identity;RemoveClusterdeletes the active identity and tombstones both drains;AddClusteris visible immediately while the removed identity remains fenced;metrics clear, detail changes, and collection disable/enable do not reset an active identity;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 passedcargo test -p sozu-e2e real_http_session_without_add_cluster_records_labelled_metrics --locked -j 4 -- --nocapture: 1 passedcargo 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 shutdownmain@9561b24e + #1845 product delta + #1843 tests@2f78aaf928b2241241713cbba28ff4abdc1f0926, the independent checker replayed the retained test(lifecycle): add regression coverage #1843 H1 oracle 1/1 and the new H2/WebSocket oracles 2/2. The test(lifecycle): add regression coverage #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 fix(metrics): isolate cluster incarnations #1845 oracle.101promotion intoPipe, exchanges structurally valid framed data in both directions for both lifetimes, and preserves access counts1→1→2and WebSocket gauges2→1→0. Its fixture omitsSec-WebSocket-Accept, so it proves pipe lifecycle/accounting rather than a complete RFC 6455 handshake.#1845@91e8a421 + complete #1843 test content, the functional run passed 628 tests with exactly four existingcargo fuzzwrappers filtered. That overlay predates merged fix(proxy-protocol): preserve payload after short v2 headers #1844; only the focused H1, H2, and WebSocket replays above were checked on the exactmain@9561 + #1845 product + #1843 testscomposition.cargo clippy -p sozu-lib -p sozu-e2e --all-targets --locked -j 4 -- -D warnings: passed on product-identical sourcecargo fmt --all -- --check, documentation citations, andgit diff --check: passedThe 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)
AddClustergets its metrics identity on that first route; a laterAddClusterreuses it and onlyRemoveClusterends it. Capture states areMissing/Active/Invalid(exhaustion), and only anActivecapture matching the current identity is accepted at Cluster/Backend detail; Process/Frontend aggregates accept every state.AddClusterallocates a fresh identity and re-arms the drains; exhaustion leaves them fenced.record_backend_metrics!checks once per invocation.AddClustercannot be removed (the main process rejectsRemoveClusterfor it), so its identity entry lives as long as the worker.