diff --git a/CHANGELOG.md b/CHANGELOG.md index 26b28484..7ed940cd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,18 @@ and listed with their assets on the ### Added +- **The dashboard shows the store of what `prepare` makes** (ADR-0062, + #291). A service's detail view says where its last `prepare` outputs came + from: copied out of the store (the key, the copy's time, what `prepare` + took when it made the entry) or a run (its time, and why the store gave + nothing: no entry for these inputs, copying slower than running, `version` + failed, an output git tracks). The usage page has a line with the store's + entries and size, which opens the list (service, key, outputs, size, last + used, which lanes use it) with a remove action per entry. The pool view + shows a node's store beside what it keeps. API: `ServiceView.prepare`, + `GET /v1/store`, `DELETE /v1/store/{service}/{key}`, and `kept.store_bytes` + in a node's report (older nodes omit it). + - **A pool node keeps a store of what `prepare` makes** (ADR-0062, #277), per member and repository: a lane on the node reads it (read-only) and copies an entry with the same inputs, platform and lane image instead of diff --git a/crates/devstack-daemon/src/api.rs b/crates/devstack-daemon/src/api.rs index 186565d4..2cf32be1 100644 --- a/crates/devstack-daemon/src/api.rs +++ b/crates/devstack-daemon/src/api.rs @@ -62,6 +62,11 @@ pub fn router(state: AppState) -> axum::Router { .route("/v1/infra/check", post(infra_check)) .route("/v1/events", get(events)) .route("/v1/usage", get(usage)) + .route("/v1/store", get(store_list)) + .route( + "/v1/store/{service}/{key}", + axum::routing::delete(store_delete), + ) .route("/v1/commands/{name}", post(run_command)) .route("/v1/commands/{name}/runs", get(command_runs)) .route("/v1/runs/{id}", get(run_info)) @@ -1340,6 +1345,49 @@ async fn usage(State(s): State, Query(q): Query) -> Respon Json(s.usage.report(&s.sup, q.history)).into_response() } +/// `GET /v1/store`: the store of what `prepare` makes (ADR-0062), its +/// entries and what they take. One per repository and machine: a lane's API +/// answers from the same store (on a node, the member's store there). +async fn store_list(State(s): State) -> Response { + let r = tokio::task::spawn_blocking(move || { + let used = match &s.lanes { + Some(l) => l.prepared_keys(), + None => s + .sup + .prepared_keys() + .into_iter() + .map(|(svc, k)| (s.sup.lane.clone(), svc, k)) + .collect(), + }; + crate::supervisor::store_view(&s.sup.store(), &used) + }) + .await; + match r { + Ok(v) => Json(v).into_response(), + Err(e) => err(StatusCode::INTERNAL_SERVER_ERROR, e.to_string()), + } +} + +/// `DELETE /v1/store/{service}/{key}`: an entry of the store removed. The +/// next `prepare` of its inputs runs and makes it again. +async fn store_delete( + State(s): State, + Path((service, key)): Path<(String, String)>, +) -> Response { + use crate::supervisor::StoreRemoveError as E; + let r = tokio::task::spawn_blocking(move || { + crate::supervisor::store_remove(&s.sup.store(), &service, &key) + }) + .await; + match r { + Ok(Ok(())) => StatusCode::NO_CONTENT.into_response(), + Ok(Err(E::NotFound(e))) => err(StatusCode::NOT_FOUND, e), + Ok(Err(E::Refused(e))) => err(StatusCode::CONFLICT, e), + Ok(Err(E::Failed(e))) => err(StatusCode::INTERNAL_SERVER_ERROR, e), + Err(e) => err(StatusCode::INTERNAL_SERVER_ERROR, e.to_string()), + } +} + #[derive(Deserialize, Default)] struct RunBody { #[serde(default)] diff --git a/crates/devstack-daemon/src/lanes.rs b/crates/devstack-daemon/src/lanes.rs index a83cb17f..ade5cce5 100644 --- a/crates/devstack-daemon/src/lanes.rs +++ b/crates/devstack-daemon/src/lanes.rs @@ -2288,6 +2288,27 @@ impl Lanes { } } + /// Of the main tree and each lane started here, the store key each + /// service's last `prepare` outputs came from or went into (ADR-0062): + /// (tree, service, key), the main tree as `""`. + pub fn prepared_keys(&self) -> Vec<(String, String, String)> { + let mut sups: Vec<(String, Arc)> = vec![(String::new(), self.main.clone())]; + sups.extend( + self.map + .lock() + .unwrap() + .iter() + .map(|(n, l)| (n.clone(), l.sup.clone())), + ); + sups.into_iter() + .flat_map(|(tree, sup)| { + sup.prepared_keys() + .into_iter() + .map(move |(s, k)| (tree.clone(), s, k)) + }) + .collect() + } + /// The lanes started, or starting, here and on nodes: while there is /// one, the main tree's `down` keeps the daemon they live in (ADR-0024). pub fn active(&self) -> Vec { diff --git a/crates/devstack-daemon/src/state.rs b/crates/devstack-daemon/src/state.rs index 297505c6..5d5262b6 100644 --- a/crates/devstack-daemon/src/state.rs +++ b/crates/devstack-daemon/src/state.rs @@ -95,6 +95,35 @@ pub struct ServiceView { pub hot_reload: bool, /// The stack file gives it a hot-reload mode. pub hot_reload_available: bool, + /// Where its last `prepare` outputs came from (ADR-0062): the store or + /// a run. Since this daemon started; none before its first `prepare`. + #[serde(skip_serializing_if = "Option::is_none")] + pub prepare: Option, +} + +/// Where a service's last `prepare` outputs came from (ADR-0062). +#[derive(Debug, Clone, PartialEq, Eq, Serialize)] +pub struct PrepareView { + /// `store`: copied out of the store; `run`: `prepare` ran. + pub source: &'static str, + /// Unix ms when it was done. + pub at: u128, + /// How long it took: the copy out of the store, or the run. + pub ms: u64, + /// The store's key: of the entry copied, or of the one the run made. + #[serde(skip_serializing_if = "Option::is_none")] + pub key: Option, + /// Of a copy: how long the `prepare` that made the entry took. + #[serde(skip_serializing_if = "Option::is_none")] + pub prepare_ms: Option, + /// Of a run: why the store gave nothing (no entry for these inputs, the + /// copy is slower, `version` failed, an output tracked by git). None: the + /// `prepare` names no `outputs`, it does not use the store. + #[serde(skip_serializing_if = "Option::is_none")] + pub miss: Option, + /// Of a run: what it made went into the store. + #[serde(skip_serializing_if = "std::ops::Not::not")] + pub stored: bool, } /// A replacement for the main instance in progress (ADR-0003). diff --git a/crates/devstack-daemon/src/supervisor/artifacts.rs b/crates/devstack-daemon/src/supervisor/artifacts.rs index b4e0cfcc..77bd344d 100644 --- a/crates/devstack-daemon/src/supervisor/artifacts.rs +++ b/crates/devstack-daemon/src/supervisor/artifacts.rs @@ -168,7 +168,8 @@ impl Supervisor { building(Some(id.clone())); if let Some(job) = self.prepare_job(name, svc, &snap)? { drop(snap); - self.run_prepare(name, job, cancel)?; + let view = self.run_prepare(name, job, cancel)?; + self.set_prepare(name, view); snap = self.snapshot.lock().unwrap(); } self.link_prepared(name, svc); diff --git a/crates/devstack-daemon/src/supervisor/copy.rs b/crates/devstack-daemon/src/supervisor/copy.rs index d311fed9..8543d263 100644 --- a/crates/devstack-daemon/src/supervisor/copy.rs +++ b/crates/devstack-daemon/src/supervisor/copy.rs @@ -1,7 +1,7 @@ //! A lane's copy of its worktree, and `prepare`. use super::{COPY_QUIET, KEEP_BUILD_LOGS, STOPPED, Supervisor, tail}; -use crate::state::{NoticeLevel, now_ms}; +use crate::state::{NoticeLevel, PrepareView, now_ms}; use devstack_build::Snapshot; use devstack_build::store::Store; use devstack_config::model::{Prepare, Service}; @@ -69,6 +69,27 @@ impl Supervisor { })) } + /// Where `name`'s last `prepare` outputs came from, on its view. + pub(super) fn set_prepare(&self, name: &str, view: PrepareView) { + if let Some(slot) = self.slots.lock().unwrap().get_mut(name) { + slot.view.prepare = Some(view); + } + } + + /// Of each service, the store key its last `prepare` outputs came from + /// or went to (ADR-0062). + pub(crate) fn prepared_keys(&self) -> Vec<(String, String)> { + self.slots + .lock() + .unwrap() + .iter() + .filter_map(|(name, slot)| { + let key = slot.view.prepare.as_ref()?.key.clone()?; + Some((name.clone(), key)) + }) + .collect() + } + /// The store of what `prepare` makes (ADR-0062): in the main tree's /// state, shared by its builds and its lanes. pub(crate) fn store(&self) -> Store { @@ -86,10 +107,19 @@ impl Supervisor { /// Whether `prepare` of `name` goes through the store: it names /// `outputs`, none of them is tracked by git (a copy from the store /// would overwrite the source), and, in a lane on a node, the node - /// gives it the member's store (an older node does not). - fn store_use(&self, name: &str, p: &Prepare, snap: &Snapshot) -> Option { - if p.outputs.is_empty() || (crate::remote_lane() && node_store().is_none()) { - return None; + /// gives it the member's store (an older node does not). `Err`: why + /// not, `None` when it names no `outputs`. + fn store_use( + &self, + name: &str, + p: &Prepare, + snap: &Snapshot, + ) -> Result> { + if p.outputs.is_empty() { + return Err(None); + } + if crate::remote_lane() && node_store().is_none() { + return Err(Some("the node gives this lane no store".into())); } let id = format!("prepare.store.{name}"); let tracked = p.outputs.iter().find(|o| { @@ -105,9 +135,9 @@ impl Supervisor { "`prepare` of {name} runs in every copy: its output `{o}` holds files git tracks, which a copy from the store would overwrite." ), ); - return None; + return Err(Some(format!("its output `{o}` holds files git tracks"))); } - Some(StoreUse { + Ok(StoreUse { root: snap.dir.clone(), outputs: p.outputs.clone(), version: p.version.clone(), @@ -115,16 +145,17 @@ impl Supervisor { } /// The store's key of `job`: its inputs, this machine's platform and - /// the output of `version` (ADR-0062 point 2). `None`: `version` failed, - /// the store is not used this time. + /// the output of `version` (ADR-0062 point 2). `Ok(Err(why))`: the store + /// is not used this time (`None`: the `prepare` does not use it). fn store_key( &self, name: &str, job: &PrepareJob, cancel: &dyn Fn() -> bool, - ) -> Result, String> { - let Some(s) = &job.store else { - return Ok(None); + ) -> Result>, String> { + let s = match &job.store { + Ok(s) => s, + Err(why) => return Ok(Err(why.clone())), }; let mut version = None; if let Some(cmd) = &s.version { @@ -143,11 +174,11 @@ impl Supervisor { "`prepare` of {name} ran without the store: its `version` (`{cmd}`) failed: {e}" ), ); - return Ok(None); + return Ok(Err(Some(format!("its `version` (`{cmd}`) failed")))); } } } - Ok(Some(store_key_of(&job.key, version.as_deref()))) + Ok(Ok(store_key_of(&job.key, version.as_deref()))) } /// `prepare.version` of `name`, run in `cwd` like `prepare`; its output. @@ -193,8 +224,8 @@ impl Supervisor { } /// A hit of `key`: its entry copied into the copy, unless the last copy - /// out of it took longer than its `prepare` (ADR-0062 point 6). `false`: - /// `prepare` runs. + /// out of it took longer than its `prepare` (ADR-0062 point 6). `Err`: + /// why not, `prepare` runs. fn prepare_from_store( &self, name: &str, @@ -202,13 +233,13 @@ impl Supervisor { key: &str, root: &Path, log: &Path, - ) -> bool { + ) -> Result { let miss = |why: &str| { crate::diag::info( "prepare_store_miss", serde_json::json!({ "lane": self.lane, "service": name, "key": key, "why": why }), ); - false + Err(why.to_string()) }; let Some(meta) = store.get(name, key) else { return miss("no entry for these inputs on this machine"); @@ -237,23 +268,39 @@ impl Supervisor { "files": stats.files, "bytes": stats.bytes, "ms": stats.elapsed.as_millis() as u64, "prepare_ms": meta.prepare_ms }), ); - true + Ok(PrepareView { + source: "store", + at: now_ms(), + ms: stats.elapsed.as_millis() as u64, + key: Some(key.to_string()), + prepare_ms: Some(meta.prepare_ms), + miss: None, + stored: false, + }) } Err(e) => { crate::diag::warn( "prepare_store_copy_failed", serde_json::json!({ "lane": self.lane, "service": name, "key": key, "error": e.to_string() }), ); - false + Err(format!("copying the entry failed: {e}")) } } } - /// After a `prepare` that succeeded: its outputs into the store. - fn store_put(&self, name: &str, store: &Store, key: &str, s: &StoreUse, took: Duration) { + /// After a `prepare` that succeeded: its outputs into the store. Whether + /// they are there. + fn store_put( + &self, + name: &str, + store: &Store, + key: &str, + s: &StoreUse, + took: Duration, + ) -> bool { let id = format!("prepare.store.{name}"); let t0 = Instant::now(); - match store.put(name, key, &s.root, &s.outputs, took) { + let stored = match store.put(name, key, &s.root, &s.outputs, took) { Ok(meta) => { self.clear_notice(&id); crate::diag::info( @@ -262,6 +309,7 @@ impl Supervisor { "files": meta.files, "bytes": meta.bytes, "ms": t0.elapsed().as_millis() as u64, "prepare_ms": meta.prepare_ms }), ); + true } Err(e) => { crate::diag::warn( @@ -275,19 +323,22 @@ impl Supervisor { "What `prepare` of {name} made is not in the store, the next copy runs it again: {e}" ), ); + false } - } + }; sweep_store(store); + stored } /// Run a `prepare` to completion; its output goes to a log of its own. - /// `cancel`: a stop came in, the prepare is killed. + /// `cancel`: a stop came in, the prepare is killed. Where its outputs + /// came from: the store or the run. pub(super) fn run_prepare( &self, name: &str, job: PrepareJob, cancel: &dyn Fn() -> bool, - ) -> Result { + ) -> Result { let _one = self.preparing.lock().unwrap(); let dir = self.log_dir(name); std::fs::create_dir_all(&dir).map_err(|e| e.to_string())?; @@ -296,7 +347,10 @@ impl Supervisor { // Through the store (ADR-0062): one copy of a key prepares, the // others wait for it and copy what it made. let store = self.store(); - let key = self.store_key(name, &job, cancel)?; + let (key, mut miss) = match self.store_key(name, &job, cancel)? { + Ok(k) => (Some(k), None), + Err(why) => (None, why), + }; let _key = match &key { Some(k) => Some( store @@ -305,11 +359,14 @@ impl Supervisor { ), None => None, }; - if let (Some(k), Some(s)) = (&key, &job.store) - && self.prepare_from_store(name, &store, k, &s.root, &log) - { - self.clear_notice(&format!("prepare.store.{name}")); - return job.done().map(|()| true); + if let (Some(k), Ok(s)) = (&key, &job.store) { + match self.prepare_from_store(name, &store, k, &s.root, &log) { + Ok(view) => { + self.clear_notice(&format!("prepare.store.{name}")); + return job.done().map(|()| view); + } + Err(why) => miss = Some(why), + } } if let Some(f) = &job.before_run { f()?; @@ -347,10 +404,20 @@ impl Supervisor { tail(&log, 15) )); } - if let (Some(k), Some(s)) = (&key, &job.store) { - self.store_put(name, &store, k, s, t0.elapsed()); - } - job.done().map(|()| false) + let took = t0.elapsed(); + let stored = match (&key, &job.store) { + (Some(k), Ok(s)) => self.store_put(name, &store, k, s, took), + _ => false, + }; + job.done().map(|()| PrepareView { + source: "run", + at: now_ms(), + ms: took.as_millis() as u64, + key: key.filter(|_| stored), + prepare_ms: None, + miss, + stored, + }) } /// A lane's copy, current and prepared for `svc`, before it starts from it. @@ -367,7 +434,8 @@ impl Supervisor { self.prepare_job(name, svc, &snap)? }; if let Some(job) = job { - self.run_prepare(name, job, cancel)?; + let view = self.run_prepare(name, job, cancel)?; + self.set_prepare(name, view); } self.link_prepared(name, svc); Ok(()) @@ -510,7 +578,7 @@ impl Supervisor { mark, cwd: cwd.map_or_else(|| root.clone(), |c| root.join(c)), run: p.run.clone(), - store: Some(StoreUse { + store: Ok(StoreUse { root: root.clone(), outputs: p.outputs.clone(), version: p.version.clone(), @@ -524,8 +592,8 @@ impl Supervisor { })), }; match self.run_prepare(name, job, cancel) { - Ok(true) => state = "linked (store)", - Ok(false) => {} + Ok(v) if v.source == "store" => state = "linked (store)", + Ok(_) => {} Err(e) => { views.extend(at("not linked", Some(e))); continue; @@ -693,7 +761,8 @@ pub(super) struct PrepareJob { cwd: PathBuf, run: String, /// What the store needs, when it is used (ADR-0062). - store: Option, + /// `Err`: why not (`None`: it names no `outputs`). + store: Result>, /// Runs before `prepare` itself does, not before a hit: the copy of a /// worktree linked for a lane on a node gets its source only when it /// has to prepare (ADR-0063). @@ -808,6 +877,130 @@ fn sweep_store(store: &Store) { }); } +/// The store of what `prepare` makes (ADR-0062) as `GET /v1/store` shows it. +#[derive(Debug, Clone, serde::Serialize)] +pub struct StoreView { + /// This daemon writes and sweeps it; `false`: a node's, read-only here. + pub owned: bool, + /// The largest first. + pub entries: Vec, + /// What all entries take. + pub bytes: u64, +} + +/// An entry of the store. +#[derive(Debug, Clone, serde::Serialize)] +pub struct StoreEntryView { + pub service: String, + pub key: String, + /// The directories it holds, relative to the repository. + pub outputs: Vec, + pub bytes: u64, + pub files: u64, + /// Unix ms. + pub created: u128, + /// Unix ms of its last use (a copy out of it), else of its making. + pub last_used: u128, + /// How long the `prepare` that made it took. + pub prepare_ms: u64, + /// How long the last copy out of it took. + #[serde(skip_serializing_if = "Option::is_none")] + pub copy_ms: Option, + /// The trees whose service's last `prepare` outputs came from it or + /// went into it, since their daemon started: lane names, `""` the main + /// working tree (its builds). + pub used_by: Vec, +} + +/// `store`'s entries; `used`: (tree, service, key) of the last `prepare` +/// of each service of each tree ([`Supervisor::prepared_keys`]). +pub fn store_view(store: &Store, used: &[(String, String, String)]) -> StoreView { + let now = now_ms(); + let mut entries: Vec = store + .entries() + .into_iter() + .map(|(m, idle)| StoreEntryView { + copy_ms: store.copy_ms(&m.service, &m.key), + used_by: used + .iter() + .filter(|(_, s, k)| *s == m.service && *k == m.key) + .map(|(t, _, _)| t.clone()) + .collect(), + last_used: now.saturating_sub(idle.as_millis()), + service: m.service, + key: m.key, + outputs: m.outputs, + bytes: m.bytes, + files: m.files, + created: m.created, + prepare_ms: m.prepare_ms, + }) + .collect(); + entries.sort_by(|a, b| { + b.bytes + .cmp(&a.bytes) + .then_with(|| (&a.service, &a.key).cmp(&(&b.service, &b.key))) + }); + StoreView { + owned: store.owned(), + bytes: entries.iter().map(|e| e.bytes).sum(), + entries, + } +} + +/// Why `DELETE /v1/store/{service}/{key}` did not remove an entry. +#[derive(Debug, PartialEq, Eq)] +pub enum StoreRemoveError { + /// No such entry (or a name that cannot be one). + NotFound(String), + /// Not this daemon's to change, or a `prepare` of the key under way. + Refused(String), + Failed(String), +} + +/// A segment of a store path as an entry's service or key may be: no +/// separator, nothing hidden or relative. +fn store_name_ok(s: &str) -> bool { + !s.is_empty() && !s.starts_with('.') && !s.contains(['/', '\\', ':']) && !s.contains("..") +} + +/// The entry `service`/`key` removed from `store`, unless a `prepare` of +/// the key in this daemon copies out of it or puts it right now. +pub fn store_remove(store: &Store, service: &str, key: &str) -> Result<(), StoreRemoveError> { + if !store_name_ok(service) || !store_name_ok(key) { + return Err(StoreRemoveError::NotFound(format!( + "no entry {service}/{key}" + ))); + } + if !store.owned() { + return Err(StoreRemoveError::Refused( + "the node's store is its agent's to change".into(), + )); + } + if store.get(service, key).is_none() { + return Err(StoreRemoveError::NotFound(format!( + "no entry {service}/{key} in the store" + ))); + } + let t0 = Instant::now(); + let Some(_guard) = store.lock(service, key, &|| t0.elapsed() > STORE_REMOVE_WAIT) else { + return Err(StoreRemoveError::Refused(format!( + "a `prepare` of {service} uses the entry {key} right now" + ))); + }; + store + .remove(service, key) + .map_err(|e| StoreRemoveError::Failed(e.to_string()))?; + crate::diag::info( + "prepare_store_removed", + serde_json::json!({ "service": service, "key": key }), + ); + Ok(()) +} + +/// How long a removal waits for a `prepare` of the key to end. +const STORE_REMOVE_WAIT: Duration = Duration::from_secs(5); + /// A path of a lane on a node's worktree, linked (or not) to a copy on this /// machine (ADR-0063): what `devstack status` and the dashboard show. #[derive(Debug, Clone, PartialEq, Eq, serde::Serialize)] @@ -1042,4 +1235,132 @@ mod tests { ); assert!(std::fs::symlink_metadata(wt.join("deps")).is_err()); } + + #[test] + fn the_store_lists_its_entries_with_who_used_them_and_removes_one() { + let d = tempfile::tempdir().unwrap(); + let made = d.path().join("made"); + std::fs::create_dir_all(made.join("deps")).unwrap(); + std::fs::write(made.join("deps/index.js"), "made").unwrap(); + let store = Store::new(d.path().join("store")); + store + .put("web", "k1", &made, &["deps".into()], Duration::from_secs(3)) + .unwrap(); + let used = vec![("fix-login".to_string(), "web".to_string(), "k1".to_string())]; + let v = store_view(&store, &used); + assert!(v.owned); + assert_eq!(v.entries.len(), 1); + let e = &v.entries[0]; + assert_eq!((e.service.as_str(), e.key.as_str()), ("web", "k1")); + assert_eq!((e.files, e.prepare_ms), (1, 3000)); + assert_eq!(e.used_by, vec!["fix-login".to_string()]); + assert_eq!(v.bytes, e.bytes); + assert!(matches!( + store_remove(&store, "web", "../web"), + Err(StoreRemoveError::NotFound(_)) + )); + store_remove(&store, "web", "k1").unwrap(); + assert!(store_view(&store, &used).entries.is_empty()); + assert!(matches!( + store_remove(&store, "web", "k1"), + Err(StoreRemoveError::NotFound(_)) + )); + // A node's store is its agent's. + let lane = Store::with_outbox(d.path().join("store"), d.path().join("out")); + assert!(!store_view(&lane, &[]).owned); + assert!(matches!( + store_remove(&lane, "web", "k1"), + Err(StoreRemoveError::Refused(_)) + )); + } + + // `prepare` runs as a process: without devstack's shim, on Windows only. + #[cfg(windows)] + #[test] + fn a_service_says_where_its_prepare_came_from_and_the_store_lists_and_removes_entries() { + let rt = tokio::runtime::Builder::new_current_thread() + .enable_all() + .build() + .unwrap(); + let d = tempfile::tempdir().unwrap(); + let main = d.path().join("main"); + std::fs::create_dir_all(&main).unwrap(); + let text = "version = 1\n[stack]\nname = \"t\"\n[services.web]\nkind = \"devserver\"\nrun = \"x\"\nport = 4200\nprepare = { run = \"git --version\", inputs = [\"package-lock.json\"], outputs = [\"deps\"] }\n"; + let stack = devstack_config::from_str(text, Path::new("t")).unwrap(); + let sup = Supervisor::new( + stack, + main.join("devstack.toml"), + main.clone(), + main.join(".devstack"), + devstack_proc::Options::default(), + rt.handle().clone(), + ) + .unwrap(); + let copy = d.path().join("copy"); + std::fs::create_dir_all(copy.join("deps")).unwrap(); + std::fs::write(copy.join("deps/index.js"), "made").unwrap(); + let job = || PrepareJob { + key: "inputs".into(), + mark: d.path().join("mark"), + cwd: copy.clone(), + run: "git --version".into(), + store: Ok(StoreUse { + root: copy.clone(), + outputs: vec!["deps".into()], + version: None, + }), + before_run: None, + }; + let key = store_key_of("inputs", None); + + // The first copy runs it: the store has no entry yet, and gets one. + let ran = sup.run_prepare("web", job(), &|| false).unwrap(); + assert_eq!(ran.source, "run"); + assert!(ran.stored); + assert_eq!(ran.key.as_deref(), Some(key.as_str())); + assert!(ran.miss.as_deref().unwrap().contains("no entry"), "{ran:?}"); + + // The next one copies it out of the store. + let hit = sup.run_prepare("web", job(), &|| false).unwrap(); + assert_eq!(hit.source, "store", "{hit:?}"); + assert_eq!(hit.key.as_deref(), Some(key.as_str())); + assert!(hit.prepare_ms.is_some() && hit.miss.is_none()); + sup.set_prepare("web", hit.clone()); + assert_eq!(sup.view().services[0].prepare.as_ref(), Some(&hit)); + assert_eq!(sup.prepared_keys(), vec![("web".to_string(), key.clone())]); + + // Without the store: why, and nothing stored. + let mut off = job(); + off.store = Err(Some("its `version` (`node --version`) failed".into())); + let plain = sup.run_prepare("web", off, &|| false).unwrap(); + assert_eq!(plain.source, "run"); + assert!(!plain.stored && plain.key.is_none()); + assert!(plain.miss.as_deref().unwrap().contains("version")); + + // The store as the dashboard lists it, with who used an entry. + let store = sup.store(); + let used = vec![("fix-login".to_string(), "web".to_string(), key.clone())]; + let v = store_view(&store, &used); + assert!(v.owned); + assert_eq!(v.entries.len(), 1); + let e = &v.entries[0]; + assert_eq!((e.service.as_str(), e.key.as_str()), ("web", key.as_str())); + assert_eq!(e.outputs, vec!["deps".to_string()]); + assert_eq!(e.files, 1); + assert_eq!(v.bytes, e.bytes); + assert!(e.copy_ms.is_some()); + assert_eq!(e.used_by, vec!["fix-login".to_string()]); + + // Removed: gone from the list; a name that is no entry is refused. + assert!(matches!( + store_remove(&store, "web", "../web"), + Err(StoreRemoveError::NotFound(_)) + )); + store_remove(&store, "web", &key).unwrap(); + assert!(store_view(&store, &used).entries.is_empty()); + assert!(matches!( + store_remove(&store, "web", &key), + Err(StoreRemoveError::NotFound(_)) + )); + } } diff --git a/crates/devstack-daemon/src/supervisor/mod.rs b/crates/devstack-daemon/src/supervisor/mod.rs index 0887a7d5..fbda088f 100644 --- a/crates/devstack-daemon/src/supervisor/mod.rs +++ b/crates/devstack-daemon/src/supervisor/mod.rs @@ -26,7 +26,7 @@ use tokio::sync::broadcast; mod artifacts; mod candidate; mod copy; -pub use copy::NodeLink; +pub use copy::{NodeLink, StoreEntryView, StoreRemoveError, StoreView, store_remove, store_view}; mod handover; mod infra; pub use infra::ContainerTarget; @@ -411,6 +411,7 @@ impl Supervisor { rebuild: None, hot_reload: false, hot_reload_available: svc.hot_reload.is_some(), + prepare: None, }, main: None, previous: None, diff --git a/crates/devstack-node/src/coordinator.rs b/crates/devstack-node/src/coordinator.rs index 686bd316..3cca2338 100644 --- a/crates/devstack-node/src/coordinator.rs +++ b/crates/devstack-node/src/coordinator.rs @@ -428,8 +428,13 @@ pub fn valid_version(v: &str) -> bool { #[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize)] pub struct Kept { pub lanes: usize, - /// Their directories (mirrors, builds, caches); volumes not counted. + /// Their directories (mirrors, builds, caches) and the members' stores + /// of what `prepare` makes; volumes not counted. pub bytes: u64, + /// Of `bytes`, the members' stores of what `prepare` makes (ADR-0062). + /// Older nodes do not say. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub store_bytes: Option, } /// One moment of a node's capacity, or the pool's (ADR-0036): what it has, @@ -2264,6 +2269,28 @@ pub async fn stop_signal() { let _ = tokio::signal::ctrl_c().await; } +#[cfg(test)] +mod kept_tests { + use super::*; + + #[test] + fn what_a_node_keeps_names_its_store_and_older_nodes_need_not() { + let old: Kept = serde_json::from_str(r#"{"lanes":2,"bytes":100}"#).unwrap(); + assert_eq!(old.store_bytes, None); + assert_eq!( + serde_json::to_string(&old).unwrap(), + r#"{"lanes":2,"bytes":100}"# + ); + let new = Kept { + lanes: 0, + bytes: 40, + store_bytes: Some(40), + }; + let back: Kept = serde_json::from_str(&serde_json::to_string(&new).unwrap()).unwrap(); + assert_eq!(back, new); + } +} + #[cfg(test)] mod history_tests { use super::*; diff --git a/crates/devstack-node/src/node.rs b/crates/devstack-node/src/node.rs index 3184d8e7..380e1174 100644 --- a/crates/devstack-node/src/node.rs +++ b/crates/devstack-node/src/node.rs @@ -703,10 +703,11 @@ impl Inner { .or_default() .push((slot, info, bytes)); } + let store_bytes = stored.values().flatten().map(|e| e.3).sum::(); *self.kept_use.lock().unwrap() = Some(crate::coordinator::Kept { lanes: by_member.values().map(Vec::len).sum(), - bytes: by_member.values().flatten().map(|s| s.2).sum::() - + stored.values().flatten().map(|e| e.3).sum::(), + bytes: by_member.values().flatten().map(|s| s.2).sum::() + store_bytes, + store_bytes: Some(store_bytes), }); // A member with only a store here counts too. for member in stored.keys() { diff --git a/docs/dashboard-api.md b/docs/dashboard-api.md index 19245cdc..09367650 100644 --- a/docs/dashboard-api.md +++ b/docs/dashboard-api.md @@ -136,6 +136,7 @@ type PoolOverview = { total?: { cpus: number; memory: number }; // what the machine has (ADR-0036) used?: { cpus: number; memory: number }; // what its lanes use gpus?: { name: string; memory: number; memory_used: number; load: number; offered: boolean }[]; + kept?: { lanes: number; bytes: number; store_bytes?: number }; // stopped lanes it keeps (ADR-0038) and the members' stores of what `prepare` makes (ADR-0062), together in `bytes`; `store_bytes` the stores' part (older nodes omit it) devstack?: PoolRelease; // what it runs; absent from a release before version reporting }; }[]; @@ -212,6 +213,16 @@ type ServiceView = { rebuild?: Rebuild; // a dev server's last rebuild, from its output (ADR-0042): {state: rebuilding|ok|failed, since, ms?, tool, errors?}; an ok one for a minute, a failed one until the next hot_reload: boolean; // the toolchain's watcher runs it now hot_reload_available: boolean; // the stack file has `hot_reload` for it + prepare?: PrepareView; // where its last `prepare` outputs came from (ADR-0062), since the daemon started; absent before its first `prepare` (and from older daemons) +}; +type PrepareView = { + source: "store" | "run"; // copied out of the store, or `prepare` ran + at: number; // unix ms, when it was done + ms: number; // how long: the copy, or the run + key?: string; // the store's key: of the entry copied, or of the one the run put + prepare_ms?: number; // `store`: how long the `prepare` that made the entry took + miss?: string; // `run`: why the store gave nothing (no entry for these inputs on this machine; copying the entry took longer than running prepare; its `version` failed; an output git tracks; the node gives the lane no store); absent: the `prepare` names no `outputs` + stored?: true; // `run`: what it made went into the store }; type Status = | { state: "stopped" | "starting" | "running" | "healthy" } @@ -307,6 +318,36 @@ type UsageReport = { }; ``` +### The store of what `prepare` makes + +One per repository and machine +([ADR-0062](adr/0062-what-prepare-makes-is-kept-in-a-store-per-machine-and-repository-keyed-by-its-inputs.md)), +in the main working tree's `.devstack/store/`. A lane's API (`/v1/lanes/{lane}/v1/store`) +answers from the same store; a lane on a node from the member's store on its +node, read-only there. + +| Method and path | Answer | +|---|---| +| `GET /v1/store` | JSON `StoreView` | +| `DELETE /v1/store/{service}/{key}` | `204`: the entry is gone; the next `prepare` of its inputs runs and makes it again. `404` for no such entry, `409` when a `prepare` of that key in this daemon uses it (for more than 5 s) or the store is a node's. `POST /v1/lanes/prune` with `older_than` removes entries not used for that long too | + +```ts +type StoreView = { + owned: boolean; // this daemon writes and sweeps it; false: a node's store, seen from a lane there + bytes: number; // all entries + entries: { // the largest first + service: string; key: string; // `key`: 20 hex digits, the entry's directory + outputs: string[]; // its directories, relative to the repository + bytes: number; files: number; + created: number; // unix ms + last_used: number; // unix ms of the last copy out of it, else of its making + prepare_ms: number; // how long the `prepare` that made it took + copy_ms?: number; // how long the last copy out of it took + used_by: string[]; // the trees (lane names, "" the main tree's builds) whose service's last `prepare` came from it or went into it, since the daemon started + }[]; +}; +``` + ### Logs | Method and path | Answer | diff --git a/docs/pool.md b/docs/pool.md index edf30a58..c053ef40 100644 --- a/docs/pool.md +++ b/docs/pool.md @@ -349,7 +349,8 @@ one per repository on the node, counts with its kept lanes: an entry no lane used for as long as a stopped lane is kept goes, and over the room the store's least recently used entries go before a kept lane does. A lane's container reads the store read-only; what it adds waits in its slot until -the node takes it in. The images Compose built for a lane go with its slot, and +the node takes it in. The node reports what its stores take beside its kept +lanes; the dashboard's pool view shows both. The images Compose built for a lane go with its slot, and the lane images built from `[lanes] dockerfile` with the member, or when the node has less than 10 GiB free. A node takes no lane without the disk it needs there and 5 GiB to spare (see "What a lane needs"). A stack with `[lanes] diff --git a/ui/src/api/mock/data.ts b/ui/src/api/mock/data.ts index 0be30b73..832b8bcb 100644 --- a/ui/src/api/mock/data.ts +++ b/ui/src/api/mock/data.ts @@ -48,9 +48,20 @@ export type MockStackSeed = { export function shopSeed(now: number): MockStackSeed { const repo = 'C:\\work\\shop'; const services: ServiceView[] = [ - service({ name: 'api', kind: 'service', groups: ['app'], port: 5080, hot_reload_available: true }, repo, now), + service( + { + name: 'api', + kind: 'service', + groups: ['app'], + port: 5080, + hot_reload_available: true, + prepare: { source: 'run', at: now - 26 * MIN, ms: 41_000, key: '5be0c2a91f7d34e8a0c6', miss: 'no entry for these inputs on this machine', stored: true }, + }, + repo, + now, + ), service({ name: 'worker', kind: 'service', groups: ['app'] }, repo, now), - service({ name: 'web', kind: 'devserver', groups: ['app'], port: 4200 }, repo, now), + service({ name: 'web', kind: 'devserver', groups: ['app'], port: 4200, prepare: { source: 'store', at: now - 26 * MIN, ms: 2400, key: 'a41f09c3e2b87d5610fe', prepare_ms: 162_000 } }, repo, now), service( { name: 'migrate', diff --git a/ui/src/api/mock/index.ts b/ui/src/api/mock/index.ts index d1c6365b..f7913920 100644 --- a/ui/src/api/mock/index.ts +++ b/ui/src/api/mock/index.ts @@ -706,6 +706,13 @@ export class MockTransport implements Transport { const view = () => json(200, s.view); if (p === '/v1/stack' && method === 'GET') return view(); if (p === '/v1/usage' && method === 'GET') return json(200, s.usageWithHistory()); + // The store of what `prepare` makes (ADR-0062). + if (p === '/v1/store' && method === 'GET') { + const entries = s.storeEntries(); + return json(200, { owned: true, bytes: entries.reduce((n, e) => n + e.bytes, 0), entries }); + } + const se = /^\/v1\/store\/([^/]+)\/([^/]+)$/.exec(p); + if (se && method === 'DELETE') return s.removeStoreEntry(decodeURIComponent(se[1]), decodeURIComponent(se[2])) ? empty(204) : json(404, { error: 'no such entry in the store' }); if (p === '/v1/up' && method === 'POST') return empty(202); if (p === '/v1/down' && method === 'POST') return empty(204); diff --git a/ui/src/api/mock/pool.ts b/ui/src/api/mock/pool.ts index 5964dde3..a5d88245 100644 --- a/ui/src/api/mock/pool.ts +++ b/ui/src/api/mock/pool.ts @@ -38,7 +38,7 @@ export class MockPool { ]; this.nodes = [ { id: this.me, name: 'dev-pc', online: true, seen: 4, report: { sharing: false, cpus: 0, memory: 0 }, kind: 'machine' }, - { id: '9f8e7d6c5b4a3921', name: 'build-server', online: true, seen: 7, report: { sharing: true, cpus: 12, memory: 48 * 2 ** 30, api: 'https://10.0.0.14:4261', devstack: { version: '0.10.0', protocol: 1 }, total: { cpus: 32, memory: 128 * 2 ** 30 }, used: { cpus: 6.5, memory: 22 * 2 ** 30 }, gpus: [{ name: 'NVIDIA L4', memory: 24 * 2 ** 30, memory_used: 3 * 2 ** 30, load: 18, offered: true }] }, kind: 'server' }, + { id: '9f8e7d6c5b4a3921', name: 'build-server', online: true, seen: 7, report: { sharing: true, cpus: 12, memory: 48 * 2 ** 30, api: 'https://10.0.0.14:4261', devstack: { version: '0.10.0', protocol: 1 }, total: { cpus: 32, memory: 128 * 2 ** 30 }, used: { cpus: 6.5, memory: 22 * 2 ** 30 }, kept: { lanes: 1, bytes: 5 * 2 ** 30, store_bytes: 2 * 2 ** 30 }, gpus: [{ name: 'NVIDIA L4', memory: 24 * 2 ** 30, memory_used: 3 * 2 ** 30, load: 18, offered: true }] }, kind: 'server' }, { id: '1122334455667788', name: 'laptop-anna', online: false, seen: 7200, kind: 'machine' }, ]; this.leases = [ diff --git a/ui/src/api/mock/stack.ts b/ui/src/api/mock/stack.ts index 72fd9c90..e9ec761e 100644 --- a/ui/src/api/mock/stack.ts +++ b/ui/src/api/mock/stack.ts @@ -11,6 +11,7 @@ import type { StackEventBody, StackView, Status, + StoreEntry, UsageReport, } from '../types'; import { buildId, buildLog, logLine, startupLines, type MockStackSeed } from './data'; @@ -420,6 +421,36 @@ export class MockStack { this.lastUsage = r; } + /** The store of what `prepare` makes (ADR-0062): the entries the services' last `prepare` used or made, and an older one. */ + private storeGone = new Set(); + storeEntries(): StoreEntry[] { + const now = Date.now(); + const used = this.view.services.flatMap((s) => (s.prepare?.key ? [{ s: s.name, k: s.prepare.key }] : [])); + const all: StoreEntry[] = [ + ...used.map(({ s, k }, i) => ({ + service: s, + key: k, + outputs: s === 'web' ? ['web/node_modules'] : [`${s}/obj`], + bytes: (i + 1) * 410 * 2 ** 20, + files: (i + 1) * 24_500, + created: now - (3 + i) * 3_600_000, + last_used: now - 26 * 60_000, + prepare_ms: 162_000, + copy_ms: 2400, + used_by: ['', 'agent-login-fix'], + })), + { service: 'web', key: '0c77d2e1b9a4f3605d18', outputs: ['web/node_modules'], bytes: 395 * 2 ** 20, files: 24_100, created: now - 9 * 86_400_000, last_used: now - 6 * 86_400_000, prepare_ms: 158_000, used_by: [] }, + ]; + return all.filter((e) => !this.storeGone.has(`${e.service}/${e.key}`)).sort((a, b) => b.bytes - a.bytes); + } + + removeStoreEntry(service: string, key: string): boolean { + const id = `${service}/${key}`; + if (!this.storeEntries().some((e) => `${e.service}/${e.key}` === id)) return false; + this.storeGone.add(id); + return true; + } + usageWithHistory(): UsageReport { const r = clone(this.lastUsage ?? this.report(Date.now())); for (const s of r.services) s.history = clone(this.history.get(`svc:${s.name}`) ?? []); diff --git a/ui/src/api/transport.ts b/ui/src/api/transport.ts index 4da2e407..238b1c46 100644 --- a/ui/src/api/transport.ts +++ b/ui/src/api/transport.ts @@ -133,6 +133,8 @@ export const v1 = { laneMove: (lane: string) => `/v1/lanes/${enc(lane)}/move`, events: '/v1/events', usage: '/v1/usage?history=true', + store: '/v1/store', + storeEntry: (service: string, key: string) => `/v1/store/${enc(service)}/${enc(key)}`, up: '/v1/up', down: '/v1/down', logStream: (service: string, tail = 500, build?: string) => diff --git a/ui/src/api/types.ts b/ui/src/api/types.ts index 6f0a95a7..8cdb02a2 100644 --- a/ui/src/api/types.ts +++ b/ui/src/api/types.ts @@ -226,6 +226,50 @@ export type ServiceView = { hot_reload?: boolean; /** The stack file gives the service a hot-reload mode. */ hot_reload_available?: boolean; + /** Where its last `prepare` outputs came from (ADR-0062), since the daemon started. Older daemons omit it. */ + prepare?: PrepareView; +}; + +/** Where a service's last `prepare` outputs came from (ADR-0062). */ +export type PrepareView = { + /** Copied out of the store, or `prepare` ran. */ + source: 'store' | 'run' | (string & {}); + /** Unix ms, when it was done. */ + at: number; + /** How long: the copy, or the run. */ + ms: number; + /** The store's key: of the entry copied, or of the one the run put. */ + key?: string; + /** Of a copy: how long the `prepare` that made the entry took. */ + prepare_ms?: number; + /** Of a run: why the store gave nothing; absent: the `prepare` names no `outputs`. */ + miss?: string; + /** Of a run: what it made went into the store. */ + stored?: boolean; +}; + +/** `GET /v1/store`: the store of what `prepare` makes (ADR-0062). */ +export type StoreView = { + /** The daemon writes it; false: a node's store, seen from a lane there (read-only). */ + owned: boolean; + bytes: number; + entries: StoreEntry[]; +}; + +export type StoreEntry = { + service: string; + key: string; + outputs: string[]; + bytes: number; + files: number; + /** Unix ms. */ + created: number; + /** Unix ms of the last copy out of it, else of its making. */ + last_used: number; + prepare_ms: number; + copy_ms?: number; + /** Lane names whose last `prepare` came from it or went into it; `""` the main tree. */ + used_by: string[]; }; export type ContainerView = { @@ -447,7 +491,7 @@ export type PoolNode = { used?: PoolAmount; gpus?: { name: string; memory: number; memory_used: number; load: number; offered: boolean }[]; /** Stopped lanes it keeps for their next start (ADR-0038); older nodes omit it. */ - kept?: { lanes: number; bytes: number }; + kept?: { lanes: number; bytes: number; /** Of `bytes`, the members' stores of what `prepare` makes (ADR-0062); older nodes omit it. */ store_bytes?: number }; /** How the last update an admin ordered goes (ADR-0039). */ update?: { at: number; state: 'draining' | 'installing' | 'restarting' | 'done' | 'refused' | 'failed' | 'cancelled' | (string & {}); target?: string; error?: string }; /** Why it would refuse an ordered update (in a container its image is updated instead); absent: it updates itself. */ diff --git a/ui/src/components/StoreLine.vue b/ui/src/components/StoreLine.vue new file mode 100644 index 00000000..9cd5af07 --- /dev/null +++ b/ui/src/components/StoreLine.vue @@ -0,0 +1,160 @@ + + + + + diff --git a/ui/src/lib/store.test.ts b/ui/src/lib/store.test.ts new file mode 100644 index 00000000..b57bdbb3 --- /dev/null +++ b/ui/src/lib/store.test.ts @@ -0,0 +1,27 @@ +import { describe, expect, it } from 'vitest'; +import { prepareLine, shortTime, storeLine, treeLabel } from './store'; + +describe('the store of what prepare makes', () => { + it('says where the outputs came from', () => { + expect(prepareLine({ source: 'store', at: 0, ms: 2400, key: 'abc', prepare_ms: 160_000 })).toBe('from the store, copied in 2.4s; prepare took 2m 40s when it made them'); + expect(prepareLine({ source: 'run', at: 0, ms: 160_000, key: 'abc', miss: 'no entry for these inputs on this machine', stored: true })).toBe( + 'prepare ran, 2m 40s (store miss: no entry for these inputs on this machine); kept in the store', + ); + expect(prepareLine({ source: 'run', at: 0, ms: 3000, miss: 'its `version` (`node --version`) failed' })).toBe('prepare ran, 3.0s (store miss: its `version` (`node --version`) failed)'); + expect(prepareLine({ source: 'run', at: 0, ms: 3000 })).toBe('prepare ran, 3.0s (it names no outputs: no store)'); + }); + + it('sums the store up', () => { + expect(storeLine({ entries: [], bytes: 0 })).toBe('empty'); + const e = { service: 'web', key: 'k', outputs: [], bytes: 1536, files: 1, created: 0, last_used: 0, prepare_ms: 0, used_by: [] }; + expect(storeLine({ entries: [e], bytes: 1536 })).toBe('1 entry, 1.5 KB'); + expect(storeLine({ entries: [e, e], bytes: 3 * 1024 ** 3 })).toBe('2 entries, 3.0 GB'); + }); + + it('names times and trees', () => { + expect(shortTime(-5)).toBe('0.0s'); + expect(shortTime(65_000)).toBe('1m 5s'); + expect(treeLabel('')).toBe('main tree'); + expect(treeLabel('fix-login')).toBe('fix-login'); + }); +}); diff --git a/ui/src/lib/store.ts b/ui/src/lib/store.ts new file mode 100644 index 00000000..e825d628 --- /dev/null +++ b/ui/src/lib/store.ts @@ -0,0 +1,32 @@ +// The store of what `prepare` makes (ADR-0062), in words. +import type { PrepareView, StoreView } from '@/api/types'; +import { bytes, duration } from './format'; + +/** A short time: tenths of a second below ten seconds (a copy out of the store), else as `duration`. */ +export function shortTime(ms: number): string { + if (ms < 0) ms = 0; + return ms < 10_000 ? `${(ms / 1000).toFixed(1)}s` : duration(ms); +} + +/** Where a service's last `prepare` outputs came from, in one line. */ +export function prepareLine(p: PrepareView): string { + if (p.source === 'store') { + const made = p.prepare_ms !== undefined ? `; prepare took ${shortTime(p.prepare_ms)} when it made them` : ''; + return `from the store, copied in ${shortTime(p.ms)}${made}`; + } + const ran = `prepare ran, ${shortTime(p.ms)}`; + if (!p.miss) return p.stored ? `${ran}; kept in the store` : `${ran} (it names no outputs: no store)`; + return `${ran} (store miss: ${p.miss})${p.stored ? '; kept in the store' : ''}`; +} + +/** The store in a few words: `3 entries, 1.2 GB`. */ +export function storeLine(v: Pick): string { + const n = v.entries.length; + if (!n) return 'empty'; + return `${n} ${n === 1 ? 'entry' : 'entries'}, ${bytes(v.bytes)}`; +} + +/** A tree an entry is used by: a lane's name, or the main tree (`""`). */ +export function treeLabel(tree: string): string { + return tree === '' ? 'main tree' : tree; +} diff --git a/ui/src/views/PoolView.vue b/ui/src/views/PoolView.vue index 208b5783..a1132e85 100644 --- a/ui/src/views/PoolView.vue +++ b/ui/src/views/PoolView.vue @@ -575,7 +575,13 @@ function policyText(id: string) { class="faint small" :title="`${n.report.kept.lanes} stopped lane(s) kept there for their next start: mirrors, builds, caches and volumes`" data-testid="pool-node-kept" - >· {{ n.report.kept.lanes }} kept, {{ bytes(n.report.kept.bytes) }} + >· {{ n.report.kept.lanes }} kept, {{ bytes(n.report.kept.bytes - (n.report.kept.store_bytes ?? 0)) }} + · store {{ bytes(n.report.kept.store_bytes) }} {{ n.seen === undefined ? 'never' : ago(now - n.seen * 1000, now) }} diff --git a/ui/src/views/ServiceDetailView.vue b/ui/src/views/ServiceDetailView.vue index b28dbe62..1fecce58 100644 --- a/ui/src/views/ServiceDetailView.vue +++ b/ui/src/views/ServiceDetailView.vue @@ -4,6 +4,7 @@ import { useRoute } from 'vue-router'; import { paths, v1, type ServiceAction } from '@/api'; import { ago, bytes, dateTime, percent, serviceUrl, shortBuild, useNow } from '@/lib/format'; import { kindIcon, kindLabel, statusLook } from '@/lib/status'; +import { prepareLine } from '@/lib/store'; import { useStack } from '@/stores/stack'; import StatusPill from '@/components/StatusPill.vue'; import ErrorLine from '@/components/ErrorLine.vue'; @@ -82,6 +83,10 @@ const kv = computed(() => { { k: 'Autostart', v: s.autostart ? 'yes' : 'no' }, { k: 'Groups', v: s.groups.length ? s.groups.join(', ') : '—' }, { k: 'Log file', v: s.log ?? '—', mono: true }, + // Where its last `prepare` outputs came from (ADR-0062): the store or a run. + ...(s.prepare + ? [{ k: 'Prepare', v: `${prepareLine(s.prepare)} · ${ago(s.prepare.at, now.value)}${s.prepare.key ? ` · key ${s.prepare.key}` : ''}`, testid: 'detail-prepare' }] + : []), ]; }); diff --git a/ui/src/views/UsageView.vue b/ui/src/views/UsageView.vue index 57948767..97228fef 100644 --- a/ui/src/views/UsageView.vue +++ b/ui/src/views/UsageView.vue @@ -5,6 +5,7 @@ import { useSort } from '@/lib/sort'; import { useStack } from '@/stores/stack'; import Sparkline from '@/components/Sparkline.vue'; import LaneUsage from '@/components/LaneUsage.vue'; +import StoreLine from '@/components/StoreLine.vue'; import SortTh from '@/components/SortTh.vue'; import Icon from '@/components/icons/Icon.vue'; @@ -83,6 +84,8 @@ const filters: { v: 'all' | Kind; label: string }[] = [ + +

Processes and containers