B: B4 empty the peer snapshot when a reload disables the feature
This commit is contained in:
1 parent
734a6ed541
commit
9d6fbd3288
2 files changed
+31
-14
No files matched your search
@@ -54,7 +54,7 @@ Integration test starts a second in-process server (fake sources) as a peer and
|
|||||||
|
|
||||||
- 2026-10-19 B2: one task per peer (both probes in one `tokio::select!`) with a deterministic name-hash jitter capped at a quarter of the shorter interval. Probes are `health::probe_server` / `health::probe_api`; `check_once` joins them for A4. A 401/403 is `api.up = true, auth = rejected`; a 404 falls back to public `/healthz` with `auth = unknown` (older peers, D4). The loop reuses `FakeTransport` for the classification/threshold tests and a second in-process `slinuxm` (fake sources) for up/down/recovery, api-down-but-server-up (listener accepts, never answers) and rejected-token cases in `tests/peers_registry.rs`.
|
- 2026-10-19 B2: one task per peer (both probes in one `tokio::select!`) with a deterministic name-hash jitter capped at a quarter of the shorter interval. Probes are `health::probe_server` / `health::probe_api`; `check_once` joins them for A4. A 401/403 is `api.up = true, auth = rejected`; a 404 falls back to public `/healthz` with `auth = unknown` (older peers, D4). The loop reuses `FakeTransport` for the classification/threshold tests and a second in-process `slinuxm` (fake sources) for up/down/recovery, api-down-but-server-up (listener accepts, never answers) and rejected-token cases in `tests/peers_registry.rs`.
|
||||||
- 2026-10-19 B3: `ServerTracker`/`ApiTracker` keep `since` and consecutive failures in loop-local state, so a surviving peer keeps its timestamps across a reload and a restart resets them. `fail_threshold` consecutive failures flip a check down; a success recovers in one check. `last_error` is always the fixed class string (never peer text or a URL). The first check records `since` whether it is up or down.
|
- 2026-10-19 B3: `ServerTracker`/`ApiTracker` keep `since` and consecutive failures in loop-local state, so a surviving peer keeps its timestamps across a reload and a restart resets them. `fail_threshold` consecutive failures flip a check down; a success recovers in one check. `last_error` is always the fixed class string (never peer text or a URL). The first check records `since` whether it is up or down.
|
||||||
- 2026-10-19 B4: `PeerRegistry::start` builds the real transport and loops; `src/main.rs::serve()` assigns `state.peers`. SIGHUP now reloads TLS (when enabled) and peers from one handler (`tls::spawn_sighup_reload`); a config error is logged and the old registry stays. `reload` keeps statuses of surviving peers, cancels removed/disabled/changed loops and starts new ones. Token files are read on every API check, so agenix rotation needs no restart. `peers` concurrency and size caps are fixed for the process lifetime; only the peer set, intervals, timeouts and threshold follow a reload. `PeerRegistry::shutdown` cancels and joins loops with a 5 s bound.
|
- 2026-10-19 B4: `PeerRegistry::start` builds the real transport and loops; `src/main.rs::serve()` assigns `state.peers`. SIGHUP now reloads TLS (when enabled) and peers from one handler (`tls::spawn_sighup_reload`); a config error is logged and the old registry stays. `reload` keeps statuses of surviving peers, cancels removed/disabled/changed loops and starts new ones. Token files are read on every API check, so agenix rotation needs no restart. `peers` concurrency and size caps are fixed for the process lifetime; only the peer set, intervals, timeouts and threshold follow a reload. `PeerRegistry::shutdown` cancels and joins loops with a 5 s bound. A reload with `[peers] enabled = false` empties the snapshot (routes stay mounted until restart). `main()` passes the config path and CLI overrides into `serve()` because a SIGHUP reload must re-read the same file; that is the only edit outside `serve()`.
|
||||||
- 2026-10-19 B5: connect-time SSRF guard resolves the peer host, rejects any address in `deny_cidrs` (parsed with `ipnet` at `ReqwestTransport::new`), and pins the allowed address into the HTTP client; plain HTTP to a non-loopback host requires `allow_plain_http`. `tcp_check` uses the same resolution and guard. DNS failures map to `dns`, all-denied to `unreachable`.
|
- 2026-10-19 B5: connect-time SSRF guard resolves the peer host, rejects any address in `deny_cidrs` (parsed with `ipnet` at `ReqwestTransport::new`), and pins the allowed address into the HTTP client; plain HTTP to a non-loopback host requires `allow_plain_http`. `tcp_check` uses the same resolution and guard. DNS failures map to `dns`, all-denied to `unreachable`.
|
||||||
|
|
||||||
## Handoff (2026-10-19)
|
## Handoff (2026-10-19)
|
||||||
|
|||||||
+30
-13
@@ -266,19 +266,25 @@ impl PeerRegistry {
|
|||||||
{
|
{
|
||||||
let mut st = lock_write(&self.shared.state);
|
let mut st = lock_write(&self.shared.state);
|
||||||
let old = std::mem::take(&mut st.statuses);
|
let old = std::mem::take(&mut st.statuses);
|
||||||
st.statuses = new
|
// Turning the feature off renders an empty list rather than a
|
||||||
.peer
|
// stale snapshot; the routes themselves stay mounted until
|
||||||
.iter()
|
// restart because the router is built once.
|
||||||
.map(|peer| {
|
st.statuses = if new.enabled {
|
||||||
let mut status = old
|
new.peer
|
||||||
.get(&peer.name)
|
.iter()
|
||||||
.cloned()
|
.map(|peer| {
|
||||||
.unwrap_or_else(|| initial_status(peer));
|
let mut status = old
|
||||||
status.enabled = peer.enabled;
|
.get(&peer.name)
|
||||||
status.url = peer.display_url();
|
.cloned()
|
||||||
(peer.name.clone(), status)
|
.unwrap_or_else(|| initial_status(peer));
|
||||||
})
|
status.enabled = peer.enabled;
|
||||||
.collect();
|
status.url = peer.display_url();
|
||||||
|
(peer.name.clone(), status)
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
|
} else {
|
||||||
|
BTreeMap::new()
|
||||||
|
};
|
||||||
st.config = Arc::new(new.clone());
|
st.config = Arc::new(new.clone());
|
||||||
}
|
}
|
||||||
if self.loops_enabled {
|
if self.loops_enabled {
|
||||||
@@ -600,6 +606,17 @@ mod tests {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn reload_disabling_the_feature_empties_the_snapshot() {
|
||||||
|
let reg = registry_with(FakeTransport::new(), fake_peers_config(&["beta"]));
|
||||||
|
let mut new = fake_peers_config(&["beta"]);
|
||||||
|
new.enabled = false;
|
||||||
|
reg.reload(new).await.unwrap();
|
||||||
|
assert!(reg.snapshot().is_empty());
|
||||||
|
assert!(reg.status("beta").is_err());
|
||||||
|
assert!(!reg.config().enabled);
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn reload_moves_loops_to_the_new_peer_set() {
|
async fn reload_moves_loops_to_the_new_peer_set() {
|
||||||
let fake = FakeTransport::new();
|
let fake = FakeTransport::new();
|
||||||
|
|||||||
Reference in new issue
Block a user