diff --git a/CHANGELOG.md b/CHANGELOG.md index 38e15aca..81e6c8b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,6 +41,11 @@ and listed with their assets on the ### Fixed +- **A lane on a node names its requester in its journal**: what the + requester's daemon asks of the lane's daemon (a restart of its + services, its start) showed as "by an unknown client" in that lane's + *Activity*; it now shows as "by devstack". The client a person used is + in the requester's journal. - **A lane on a node keeps its journal** (#287): the requester's take of the lane daemon's telemetry lines, every 30 seconds, went into that daemon's journal as "take the telemetry lines by an unknown client" and diff --git a/crates/devstack-node/src/tls.rs b/crates/devstack-node/src/tls.rs index 9da9128e..a739933d 100644 --- a/crates/devstack-node/src/tls.rs +++ b/crates/devstack-node/src/tls.rs @@ -201,10 +201,14 @@ pub async fn request( .await .map_err(|e| TlsError::Other(format!("{authority}: {e}")))?; tokio::spawn(conn); + // What sends it is a devstack daemon, the lane's requester: the lane + // daemon's journal says "by devstack", not "an unknown client" + // (ADR-0067). The client a person used is in the requester's journal. let mut req = hyper::Request::builder() .method(method) .uri(path) - .header(hyper::header::HOST, authority); + .header(hyper::header::HOST, authority) + .header("x-devstack-client", "auto"); let payload = match body { Some((ty, b)) => { req = req.header(hyper::header::CONTENT_TYPE, ty); diff --git a/crates/devstack/tests/remote_lane.rs b/crates/devstack/tests/remote_lane.rs index cfbd8b3c..614b5d3b 100644 --- a/crates/devstack/tests/remote_lane.rs +++ b/crates/devstack/tests/remote_lane.rs @@ -641,6 +641,35 @@ fn a_lane_runs_on_a_node_of_the_pool() { body.contains("ok"), "GET /health on the main port after the restart: {body}" ); + + // With its service running, a warm restart restarts it through the + // lane's own API, and the lane daemon's journal names those calls as + // devstack's, not an unknown client's (ADR-0067). Only what came after: + // the CLI's restarts above are journaled as the CLI's. + let journal = || { + let (_, body) = api_request(&main, state.path(), "GET", "/v1/lanes/wt/v1/journal") + .expect("the lane answers"); + let v: serde_json::Value = serde_json::from_str(&body).unwrap(); + (v, body) + }; + let (v, _) = journal(); + let last = v + .as_array() + .and_then(|a| a.iter().filter_map(|e| e["at"].as_u64()).max()) + .unwrap_or(0); + let (st, body) = api_request(&main, state.path(), "POST", "/v1/lanes/wt/restart") + .expect("the daemon answers"); + assert_eq!(st, 200, "{body}"); + let (v, body) = journal(); + let restarts: Vec<&serde_json::Value> = v + .as_array() + .into_iter() + .flatten() + .filter(|e| e["at"].as_u64().is_some_and(|at| at > last)) + .filter(|e| e["path"].as_str().is_some_and(|p| p.ends_with("/restart"))) + .collect(); + assert!(!restarts.is_empty(), "{body}"); + assert!(restarts.iter().all(|e| e["via"] == "auto"), "{body}"); cli(&main, &["promote", "--lane", "main"]); // `down` in the main tree stops the main tree only: the lane on the diff --git a/docs/dashboard-api.md b/docs/dashboard-api.md index 2e911a36..bc32c31c 100644 --- a/docs/dashboard-api.md +++ b/docs/dashboard-api.md @@ -398,7 +398,7 @@ type StoreView = { | Method and path | Answer | |---|---| -| `GET /v1/journal?since=` | what changed the stack at runtime ([ADR-0067](adr/0067-a-change-at-runtime-says-who-made-it.md)), oldest first, the last 500, kept across restarts in `.devstack/journal.ndjson`: `[{at, via, lane?, method, path, status, error?}]`. Every request but `GET`/`HEAD` (and `POST /v1/telemetry/take`, a requester's take every 30 seconds) that came through the main tree's API (a lane's under `/v1/lanes//...`, with `lane`), refused ones with their `status` and `error`; devstack's own change of the main slot as `method: "AUTO"`, `via: "auto"`, with the path the API would have taken. `since`: Unix ms. A lane's API answers the same, the stack's journal. `via` is the client the request named in `X-Devstack-Client` (`cli`, `mcp`, `dashboard`, `tray`), else `unknown`; the hub sets `dashboard` for a request with its session cookie and drops what a browser sent | +| `GET /v1/journal?since=` | what changed the stack at runtime ([ADR-0067](adr/0067-a-change-at-runtime-says-who-made-it.md)), oldest first, the last 500, kept across restarts in `.devstack/journal.ndjson`: `[{at, via, lane?, method, path, status, error?}]`. Every request but `GET`/`HEAD` (and `POST /v1/telemetry/take`, a requester's take every 30 seconds) that came through the main tree's API (a lane's under `/v1/lanes//...`, with `lane`), refused ones with their `status` and `error`; devstack's own change of the main slot as `method: "AUTO"`, `via: "auto"`, with the path the API would have taken. `since`: Unix ms. A lane's API answers the same, the stack's journal. `via` is the client the request named in `X-Devstack-Client` (`cli`, `mcp`, `dashboard`, `tray`; `auto` for what a lane's requester asks of its daemon on a node), else `unknown`; the hub sets `dashboard` for a request with its session cookie and drops what a browser sent | | `POST /v1/up` | `202` | | `POST /v1/down?infra=true&all=false` | `204` when every service stopped and, with `infra=true` (the default since 0.25.0, [ADR-0068](adr/0068-a-stop-takes-the-containers-too.md)), the containers were removed, volumes kept; `infra=false` leaves them running. `409 {"error"}` naming what did not stop. In the main tree while lanes run: `200 {"lanes": [...], "kept": [...], "containers": [...]}`; `kept`: the services that serve the lanes and keep running (`lanes = false`, and what they start `after`); `containers` (`.`, or a whole `` that lists no `services`): what `infra` left running, the containers a kept service comes `after` and, while a lane runs on this machine, the `shared` ones (ADR-0030); every other container of the main tree goes. With `all=true` the lanes stop first, each with its own containers (a lane on the main ports gives them back first, a lane on a node is released), so `infra` then removes the main tree's containers too | | `POST /v1/shutdown?unless_lanes=false&restart=false` | `202`; the daemon stops its lanes and services and exits (`devstack down`). With `unless_lanes=true` and a lane running: `409 {"error", "lanes"}`, and it stays. With `restart=true` it exits whatever runs and leaves its lanes to the next daemon ([ADR-0052](adr/0052-a-restart-carries-the-lanes-over.md)): it writes `.devstack/restart.json` (the lanes here with their profile, those on nodes with their lease and ports, who serves the main ports) and keeps the leases of its lanes on nodes; a daemon started within two minutes renews them and follows those lanes again, starts the lanes here again from the artifacts they ran, and gives the main slot back to its lane once the main tree's `up` is done |