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
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
48 changes: 48 additions & 0 deletions crates/devstack-daemon/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -1340,6 +1345,49 @@ async fn usage(State(s): State<AppState>, Query(q): Query<UsageQuery>) -> 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<AppState>) -> 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<AppState>,
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)]
Expand Down
21 changes: 21 additions & 0 deletions crates/devstack-daemon/src/lanes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Supervisor>)> = 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<String> {
Expand Down
29 changes: 29 additions & 0 deletions crates/devstack-daemon/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PrepareView>,
}

/// 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<String>,
/// Of a copy: how long the `prepare` that made the entry took.
#[serde(skip_serializing_if = "Option::is_none")]
pub prepare_ms: Option<u64>,
/// 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<String>,
/// 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).
Expand Down
3 changes: 2 additions & 1 deletion crates/devstack-daemon/src/supervisor/artifacts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading
Loading