Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ and listed with their assets on the

## [Unreleased]

### Added

- **A lane on a node is in the pool's telemetry from the inside** (ADR-0037
addendum, #287): its own daemon sent nothing, having no membership. It now
keeps its diagnostic lines (the newest 5,000), and the daemon that started
the lane takes them every 30 s and sends them with its own, under its
consent, as lines of that lane on its node (`place` `remote`): its
services, builds, `prepare`, notices and failed requests. Needs the node
on this version too; an older node's lane answers `404` and is skipped.

## [0.23.0] - 2026-10-26

One `npm ci` per lockfile and machine instead of one per lane: what
Expand Down
8 changes: 8 additions & 0 deletions crates/devstack-daemon/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pub struct AppState {
pub fn router(state: AppState) -> axum::Router {
axum::Router::new()
.route("/v1/stack", get(stack))
.route("/v1/telemetry/take", post(telemetry_take))
.route("/v1/up", post(up))
.route("/v1/down", post(down))
.route("/v1/shutdown", post(shutdown))
Expand Down Expand Up @@ -215,6 +216,13 @@ async fn stack(State(s): State<AppState>) -> Response {
Json(s.sup.view()).into_response()
}

/// `POST /v1/telemetry/take`: in the daemon of a lane on a node, the
/// diagnostic lines kept since the last take, for its requester to send
/// under its consent (#287); `{"lines": []}` elsewhere.
async fn telemetry_take() -> Response {
Json(serde_json::json!({ "lines": crate::telemetry::take_relayed() })).into_response()
}

/// Long operations run in the background; progress arrives on `/v1/events`.
async fn up(State(s): State<AppState>) -> Response {
let sup = s.sup.clone();
Expand Down
6 changes: 5 additions & 1 deletion crates/devstack-daemon/src/diag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,11 @@ pub fn init(path: impl Into<PathBuf>) -> &'static DiagLog {
for stack in crate::registry::list() {
add_root(&stack.repo, "<repo>");
}
crate::telemetry::start(service);
if crate::remote_lane() {
crate::telemetry::start_relay(service);
} else {
crate::telemetry::start(service);
}
GLOBAL.get_or_init(|| DiagLog::open(path))
}

Expand Down
30 changes: 30 additions & 0 deletions crates/devstack-daemon/src/remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ const RENEW_EVERY: Duration = Duration::from_secs(30);
const LEASE_LIVES: Duration = Duration::from_secs(150);
/// How often the lane's state is read for the lists.
const STATE_EVERY: Duration = Duration::from_secs(5);
/// How often what the lane's daemon logged is taken for telemetry (#287):
/// within the minute this daemon sends in.
const TELEMETRY_EVERY: Duration = Duration::from_secs(30);

/// What the lists show of a remote lane.
#[derive(Debug, Clone, Default)]
Expand Down Expand Up @@ -1094,6 +1097,33 @@ impl RemoteLane {
rt.spawn(async move { me.follow_renew().await });
let me = self.clone();
rt.spawn(async move { me.follow_state().await });
let me = self.clone();
rt.spawn(async move { me.follow_telemetry().await });
}

/// Take what the lane's daemon logged and send it with this daemon's
/// lines, as lines of this lane on its node, every [`TELEMETRY_EVERY`]
/// while this daemon sends any (#287): the lane's daemon has no
/// membership and no consent of its own. A lane daemon that does not
/// keep them (an older node's) answers 404, and nothing is taken.
async fn follow_telemetry(self: Arc<Self>) {
while self.tick(TELEMETRY_EVERY).await {
if !crate::telemetry::active() {
continue;
}
let Ok((200, body)) = self
.client
.api(&self.lease, "POST", "/v1/telemetry/take", None)
.await
else {
continue;
};
let lines = serde_json::from_str::<serde_json::Value>(&body)
.ok()
.and_then(|v| v["lines"].as_array().cloned())
.unwrap_or_default();
crate::telemetry::record_relayed(&self.name, &self.node.name, lines);
}
}

/// Resolves when the lane is stopped or gone.
Expand Down
86 changes: 85 additions & 1 deletion crates/devstack-daemon/src/telemetry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ const UNDECIDED: u8 = 1;
const ON: u8 = 2;
/// No pool takes it: nothing is kept.
const OFF: u8 = 3;
/// The daemon of a lane on a node: lines are kept, the newest
/// [`MAX_LINES`], for the lane's requester to take ([`take_relayed`]) and
/// send with its own, under its consent (#287). Nothing is sent from here.
const RELAY: u8 = 4;

static STATE: AtomicU8 = AtomicU8::new(IDLE);
static BUFFER: Mutex<Vec<Value>> = Mutex::new(Vec::new());
Expand All @@ -55,7 +59,7 @@ static TARGETS: Mutex<Vec<PathBuf>> = Mutex::new(Vec::new());
/// Whether diagnostic lines are kept now: a pool takes them, or none was
/// asked yet.
pub fn active() -> bool {
matches!(STATE.load(Ordering::Relaxed), UNDECIDED | ON)
matches!(STATE.load(Ordering::Relaxed), UNDECIDED | ON | RELAY)
}

/// Keep a diagnostic line for the next send (when a pool takes them).
Expand All @@ -66,6 +70,43 @@ pub fn record(line: &serde_json::Map<String, Value>) {
let mut b = BUFFER.lock().unwrap();
if b.len() < MAX_LINES {
b.push(Value::Object(line.clone()));
} else if STATE.load(Ordering::Relaxed) == RELAY {
// A requester that is away takes the latest when it is back.
b.remove(0);
b.push(Value::Object(line.clone()));
}
}

/// The daemon of a lane on a node: keep its lines for the requester, which
/// has the member's consent and certificate; the container has neither
/// (#287). Instead of [`start`].
pub fn start_relay(service: &'static str) {
let _ = SERVICE.set(service);
STATE.store(RELAY, Ordering::Relaxed);
}

/// The lines kept for the requester since it last took them (`POST
/// /v1/telemetry/take`); none when this daemon does not relay.
pub fn take_relayed() -> Vec<Value> {
if STATE.load(Ordering::Relaxed) != RELAY {
return Vec::new();
}
std::mem::take(&mut *BUFFER.lock().unwrap())
}

/// The lines a lane's daemon on a node kept (`lines`), recorded as this
/// process's own, as lines of `lane` on `node`: what the lane's daemon
/// calls itself (`main`, it runs as a main tree there) is replaced. Sent
/// with this process's lines, under its consent; nothing when it sends none.
pub fn record_relayed(lane: &str, node: &str, lines: Vec<Value>) {
for l in lines {
let Value::Object(mut l) = l else {
continue;
};
l.insert("lane".into(), lane.into());
l.insert("node".into(), node.into());
l.insert("place".into(), "remote".into());
record(&l);
}
}

Expand Down Expand Up @@ -551,6 +592,49 @@ mod tests {
.retain(|l| l["event"] != "telemetry_test_early");
}

#[test]
fn a_lane_on_a_node_keeps_its_lines_for_the_requester_which_sends_them_as_the_lanes() {
let line = |n: &str| {
let mut m = serde_json::Map::new();
m.insert("event".into(), Value::String(n.into()));
m.insert("lane".into(), Value::String("main".into()));
m
};
let _g = GLOBALS.lock().unwrap_or_else(|e| e.into_inner());
BUFFER.lock().unwrap().clear();
// Not relaying: nothing to take.
STATE.store(UNDECIDED, Ordering::Relaxed);
record(&line("telemetry_test_kept"));
assert!(take_relayed().is_empty());
BUFFER.lock().unwrap().clear();
// The lane's daemon: kept, the newest when full, taken once.
STATE.store(RELAY, Ordering::Relaxed);
for i in 0..MAX_LINES + 2 {
record(&line(&format!("telemetry_test_{i}")));
}
let taken = take_relayed();
assert_eq!(taken.len(), MAX_LINES);
assert_eq!(taken[0]["event"], "telemetry_test_2", "the oldest went");
assert!(take_relayed().is_empty(), "taken once");
// The requester: recorded as the lane's, on its node.
STATE.store(UNDECIDED, Ordering::Relaxed);
record_relayed(
"feat-x",
"n1",
vec![Value::Object(line("telemetry_test_relayed")), Value::Null],
);
let b = std::mem::take(&mut *BUFFER.lock().unwrap());
assert_eq!(b.len(), 1, "{b:?}");
assert_eq!(b[0]["lane"], "feat-x");
assert_eq!(b[0]["node"], "n1");
assert_eq!(b[0]["place"], "remote");
// Off: the requester sends nothing, so it keeps nothing.
STATE.store(OFF, Ordering::Relaxed);
record_relayed("feat-x", "n1", vec![Value::Object(line("x"))]);
assert!(BUFFER.lock().unwrap().is_empty());
STATE.store(IDLE, Ordering::Relaxed);
}

#[test]
fn an_exit_sends_what_was_kept_and_waits_no_longer_than_it_may() {
let _g = GLOBALS.lock().unwrap_or_else(|e| e.into_inner());
Expand Down
26 changes: 26 additions & 0 deletions crates/devstack/tests/remote_lane.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,32 @@ fn a_lane_runs_on_a_node_of_the_pool() {
);
std::thread::sleep(Duration::from_millis(250));
}
// The lane's own daemon keeps its lines for this daemon to send with
// its own telemetry (ADR-0037 addendum, #287); taken once. This test's
// daemon sends no telemetry, so nothing took them before.
let (st, body) = api_request(
&main,
state.path(),
"POST",
"/v1/lanes/wt/v1/telemetry/take",
)
.expect("the lane answers");
assert_eq!(st, 200, "{body}");
let taken: serde_json::Value = serde_json::from_str(&body).unwrap();
assert!(
taken["lines"]
.as_array()
.is_some_and(|l| l.iter().any(|l| l["event"] == "daemon_start")),
"{body}"
);
let (_, again) = api_request(
&main,
state.path(),
"POST",
"/v1/lanes/wt/v1/telemetry/take",
)
.expect("the lane answers");
assert!(!again.contains("daemon_start"), "taken once: {again}");
let status = child.wait().unwrap();
let up = format!("{}{}", out.join().unwrap(), err.join().unwrap());
assert!(status.success(), "devstack up --on ci-node: {up}");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ADR-0037: Telemetry goes to the pool's collector, if the pool has one and the member agrees

- **Status:** Accepted (2026-10-16)
- **Status:** Accepted (2026-10-16); addendum 2026-10-26 accepted (a lane's own daemon on a node: its lines go through its requester, #287)
- **Date:** 2026-10-16
- **Deciders:** project owner
- **Related:** [ADR-0031](0031-a-coordinator-places-lanes.md) (the coordinator, member certificates), [ADR-0034](0034-a-machine-can-belong-to-several-pools.md), [ADR-0036](0036-the-pool-shows-its-capacity-over-time.md), plan §11 (the diagnostic log)
Expand Down Expand Up @@ -141,3 +141,38 @@ replaces the roots the process knows in every text: the repository as
Point 2's "the member stops sending" now holds at once: a `404` to a send
marks the pool as not collecting until it is asked again (10 minutes),
where before the member sent on until then.

## Addendum 2026-10-26: a lane's own daemon on a node

*[#287](https://github.com/nuetzliches/devstack/issues/287).* The daemon in
a node's lane container sent nothing: a daemon sends to the pools its state
is a member of, and the container has no membership (and must get no member
key, ADR-0027, ADR-0033). The collector saw a lane on a node from the
outside only, the requester's `remote_lane_*` and the node's `node_*` lines;
not its services, builds, `prepare`, notices or failed requests.

1. **The lane's daemon keeps its lines and sends none.** In a lane on a node
(`DEVSTACK_REMOTE_LANE`) its telemetry neither asks pools nor sends; it
keeps its diagnostic lines, the newest 5,000, already masked as point 4
and the 2026-10-20 note say, and hands them over on `POST
/v1/telemetry/take`, each once.
2. **The requester sends them as its own.** The daemon that follows the
lane takes them every 30 seconds, through the node as every request to
the lane goes, while it sends telemetry at all, and records them with
its own lines as lines of that lane (`lane` its name, as the developer
calls it), on that node (`node`), `place` `remote`. They go where its own
lines go: to the pools it agreed to send to, with its member identity set
by the coordinator (point 2). Without its consent nothing is taken.
3. **Not the node.** Point 3 lets a node send what concerns a lane on the
coordinator's setting alone; the lane's own lines are the member's
(its services, its repository) and go under the member's consent.
4. **Lossy, as point 5.** A requester that is away takes the latest 5,000
lines when it is back; what the lane logs in its last 30 seconds before
it stops is not taken; a lane daemon of a node that does not keep them
(before 0.24.0) answers `404`, and nothing is taken. The lane's gauges
are not relayed: the requester counts the lane already.

*Enforced by:* `crates/devstack-daemon/src/telemetry.rs` (`RELAY`,
`start_relay`, `take_relayed`, `record_relayed`), `diag.rs` (relay in a lane
on a node), `api.rs` (`POST /v1/telemetry/take`), `remote.rs`
(`follow_telemetry`), `docs/pool.md`, `docs/dashboard-api.md`.
2 changes: 1 addition & 1 deletion docs/adr/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ stay.
| [0034](0034-a-machine-can-belong-to-several-pools.md) | A machine can belong to several pools; pools do not trust each other | Accepted; noted 2026-10-20 (several agents on one Docker engine) |
| [0035](0035-lanes-can-be-shared-with-the-pool.md) | The pool sees the lanes its members share, and can use them | Accepted; point 4 extended by ADR-0040 (sharing for viewing; since 2026-10-20 sharing includes viewing); point 3 amended by ADR-0053 (a member connects to a lane and disconnects) |
| [0036](0036-the-pool-shows-its-capacity-over-time.md) | The pool shows its capacity, GPUs included, and how it changed | Accepted |
| [0037](0037-telemetry-goes-to-the-pools-collector-with-consent.md) | Telemetry goes to the pool's collector, if the pool has one and the member agrees | Accepted |
| [0037](0037-telemetry-goes-to-the-pools-collector-with-consent.md) | Telemetry goes to the pool's collector, if the pool has one and the member agrees | Accepted; addendum 2026-10-26 (a lane's own daemon on a node: through its requester) |
| [0038](0038-a-lanes-data-outlives-its-lease.md) | A lane's mirror and data outlive its lease on a node, for a while, and can be pruned | Accepted; noted 2026-10-26 (a member's store, ADR-0062, counts towards the cap) |
| [0039](0039-an-admin-can-update-a-server-node.md) | An admin can have a server node update its devstack, from the dashboard | Accepted, amended 2026-10-20 (a checksum from the release, not a signature; the running binary is replaced; a drain ends, and can be withdrawn) |
| [0040](0040-a-shared-lane-can-be-watched-like-ones-own.md) | A shared lane can be shared for viewing, and is then shown as one's own lane is | Accepted; amended 2026-10-20 (sharing a lane includes viewing it) |
Expand Down
1 change: 1 addition & 0 deletions docs/dashboard-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ type UsageReport = {
| `GET /v1/services/{name}/env?export=false` | JSON, its environment with each variable's origin (`devstack env`); `export=true`: only what Compose and the stack file give, for running it without devstack |
| `GET /v1/runs/{id}/log` | text, a command run's output so far (the last 20 000 lines) |
| `POST /v1/runs/{id}/cancel` | `202`; the run stops: its `exec` step's process tree is killed, its `run` step's job stopped, no further step starts; it ends `failed` with error `cancelled`. `409` when it is not running, `404` for no such run |
| `POST /v1/telemetry/take` | `{"lines": [...]}`: in the daemon of a lane on a node, the diagnostic lines it kept since the last take, which its requester sends with its own telemetry, under its consent ([ADR-0037](adr/0037-telemetry-goes-to-the-pools-collector-with-consent.md), addendum 2026-10-26); `{"lines": []}` in any other daemon |
| `GET /v1/tunnel/{port}` with `Upgrade: devstack-tcp` | a raw TCP connection to that port on the daemon's machine (ADR-0029 point 4): a service's port on its loopback, or a lane's container port on the lane's network; other ports `403`. How the requester reaches the services of its lane on a node: each port it forwards here connects, through the node agent, to the lane daemon's tunnel there |
| `GET /v1/tunnel/{port}` with `Upgrade: devstack-udp` | a UDP session to the lane's container published on `port` as UDP ([ADR-0056](adr/0056-a-lane-on-a-node-relays-its-udp-ports-through-a-tunnel-per-session.md)): each datagram a frame, its length as two bytes big-endian, then its bytes, both ways; the daemon sends them from a socket of the session's own. Other ports `403`, a container that does not resolve yet `502`. The requester opens one per client address of a UDP port it relays, and ends it after 60 s without a datagram either way |
| `POST /v1/services/{name}/start` \| `stop` \| `restart` \| `rebuild` \| `promote` \| `rollback` | `200 StackView`, or `409 {"error": "..."}` (e.g. compiler errors; the running instance stays). `rebuild` is `restart` that builds even when an artifact for the same inputs exists (`devstack restart --rebuild`; the build gets the id `<inputs>-<n>`). A `stop` ends a start in progress (a build, a health wait, a job) at once. For a name that is no service but a group, `start`/`stop`/`restart` act on the group; for a name that is neither but a Compose service (`<group>.<service>`, the member form `compose.<group>.<service>`, or `<service>` when exactly one compose group lists it in `services`) they act on that container as `/v1/infra/{group}/{service}/…` does, and answer `200 StackView`. `404` for a name that is none of these. `hot-reload-on` / `hot-reload-off` switch a service with `hot_reload` in the stack file into and out of hot-reload mode (`ServiceView.hot_reload`, `hot_reload_available`) |
Expand Down
8 changes: 8 additions & 0 deletions docs/pool.md
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,14 @@ refused, a lane started, not started with its phase and reason, a compose
group of it up or failed with how long it took, stopped, an update refused
or failed).

A lane's own daemon on a node (its services, builds, `prepare`, notices)
has no membership and sends nothing itself: it keeps its lines (the newest
5,000), and the daemon that started the lane takes them every 30 seconds
and sends them with its own, under its consent, as lines of that lane on
that node (`devstack.place` `remote`). Lines of a lane whose requester is
away wait in the lane until it is back; what the lane logs in the last
moments before it stops is not taken.

Never sent: file contents, environment values, command lines, service output.
Every text of a log line is cut to its first line before it leaves the
machine (a failed job's reason keeps its process output in `daemon.log`
Expand Down
Loading