remove what no longer has a reader: build-log store, dashboard sent/delivered events, graph resource dep
This commit is contained in:
parent
32f5b74ba4
commit
49266e4410
1 changed files with 204 additions and 1054 deletions
|
|
@ -11,13 +11,15 @@
|
|||
//! together they remix, and every consumer of the scheduler ends up carrying a
|
||||
//! JSON vocabulary it may never serve.
|
||||
//!
|
||||
//! A host says how its `N` and `R` render by implementing [`WireNode`] and
|
||||
//! [`WireResource`]. [`GraphWire`] is then blanket-implemented for any
|
||||
//! `Graph<N, R>` whose two type parameters do — so the projection exists
|
||||
//! exactly when both have answered, and a payload that has never said how it
|
||||
//! displays cannot reach a viewer at all. The alternative (a projection written
|
||||
//! next to each host's endpoint) lets the second host ship a graph of
|
||||
//! unlabelled integers.
|
||||
//! A host says how its `N` renders by implementing [`WireNode`].
|
||||
//! [`GraphWire`] is then blanket-implemented for any `Graph<N, R>` whose payload
|
||||
//! does — so the projection exists exactly when `N` has answered, and a payload
|
||||
//! that has never said how it displays cannot reach a viewer at all. The
|
||||
//! alternative (a projection written next to each host's endpoint) lets the second
|
||||
//! host ship a graph of unlabelled integers.
|
||||
//!
|
||||
//! Resource edges (`Dep::Resource`) are scheduling detail and do not ride the
|
||||
//! wire: no viewer reads them.
|
||||
//!
|
||||
//! There is deliberately **no roll-up field**. A group root's own [`State`]
|
||||
//! *is* its subtree's answer: `Finishing` means "own logic done, children still
|
||||
|
|
@ -97,15 +99,6 @@ pub trait WireNode {
|
|||
fn data(&self, id: WireId) -> serde_json::Value;
|
||||
}
|
||||
|
||||
/// How a resource name `R` rides the wire.
|
||||
///
|
||||
/// Resource deps are named rather than typed on the wire: the resource
|
||||
/// vocabulary belongs to the host, and a viewer only ever groups by the string.
|
||||
pub trait WireResource {
|
||||
/// Stable display name for this resource.
|
||||
fn name(&self) -> String;
|
||||
}
|
||||
|
||||
/// One node, serialised near-raw from [`hive_jobq::Node`].
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
|
||||
pub struct GraphNode {
|
||||
|
|
@ -191,7 +184,7 @@ pub struct NodePayload {
|
|||
/// What must hold before a node runs.
|
||||
///
|
||||
/// Externally tagged on `kind`, whose values are the **variant names verbatim**
|
||||
/// (`"Node"`, `"Resource"`) — no `rename_all`. A rename is a second spelling of
|
||||
/// (`"Node"`) — no `rename_all`. A rename is a second spelling of
|
||||
/// the same name that has to be kept in agreement with the Rust one by hand.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
|
||||
#[serde(tag = "kind")]
|
||||
|
|
@ -202,14 +195,18 @@ pub enum GraphDep {
|
|||
/// (a filtered view); treat an absent target as satisfied.
|
||||
id: WireId,
|
||||
},
|
||||
/// Need `count` units of a named resource, per [`WireResource::name`].
|
||||
Resource { name: String, count: u32 },
|
||||
/// Any other `kind`. Only deserialising produces it: a sender from before
|
||||
/// resource edges left the wire still emits `"Resource"`, and a viewer
|
||||
/// must skip it rather than reject the whole graph. Nothing serialises
|
||||
/// it; remove once no such sender runs.
|
||||
#[serde(other)]
|
||||
Unknown,
|
||||
}
|
||||
|
||||
/// Serving a [`Graph`] to a viewer.
|
||||
///
|
||||
/// Blanket-implemented for every `Graph<N, R>` whose payload and resource types
|
||||
/// implement [`WireNode`] / [`WireResource`], and for no others — an extension
|
||||
/// Blanket-implemented for every `Graph<N, R>` whose payload implements
|
||||
/// [`WireNode`], and for no others — an extension
|
||||
/// trait rather than an inherent method because the graph lives in the
|
||||
/// scheduler crate and this projection deliberately does not.
|
||||
pub trait GraphWire {
|
||||
|
|
@ -229,7 +226,7 @@ pub trait GraphWire {
|
|||
fn wire_snapshot(&self, roots: impl IntoIterator<Item = NodeId>) -> Vec<GraphNode>;
|
||||
}
|
||||
|
||||
impl<N: WireNode, R: WireResource> GraphWire for Graph<N, R> {
|
||||
impl<N: WireNode, R> GraphWire for Graph<N, R> {
|
||||
fn wire_snapshot(&self, roots: impl IntoIterator<Item = NodeId>) -> Vec<GraphNode> {
|
||||
let mut roots: Vec<NodeId> = roots.into_iter().collect();
|
||||
roots.sort_unstable_by_key(|id| id.get());
|
||||
|
|
@ -251,9 +248,9 @@ impl<N: WireNode, R: WireResource> GraphWire for Graph<N, R> {
|
|||
/// graph: a summary line, a badge, a health check. Every consumer re-deriving
|
||||
/// the same tally is the thing this replaces.
|
||||
///
|
||||
/// **Free of `WireNode`/`WireResource`, unlike [`GraphWire`]** — a node's state
|
||||
/// **Free of `WireNode`, unlike [`GraphWire`]** — a node's state
|
||||
/// is a scheduler concept, so counting by state needs to know nothing about
|
||||
/// what the payload or the resource *are*. Bounding it like the projection
|
||||
/// what the payload *is*. Bounding it like the projection
|
||||
/// would make a host implement two display traits to be allowed to count, which
|
||||
/// is a requirement about rendering imposed on arithmetic.
|
||||
///
|
||||
|
|
@ -346,13 +343,13 @@ pub fn filter_nodes_by_state(nodes: Vec<GraphNode>, states: Option<&[State]>) ->
|
|||
.collect()
|
||||
}
|
||||
|
||||
fn wire_node<N: WireNode, R: WireResource>(node: &hive_jobq::Node<N, R>) -> GraphNode {
|
||||
fn wire_node<N: WireNode, R>(node: &hive_jobq::Node<N, R>) -> GraphNode {
|
||||
let id = node.id.get();
|
||||
GraphNode {
|
||||
id,
|
||||
parent: node.parent.map(NodeId::get),
|
||||
state: node.state,
|
||||
deps: node.deps.iter().map(wire_dep).collect(),
|
||||
deps: node.deps.iter().filter_map(wire_dep).collect(),
|
||||
error: node.error.clone(),
|
||||
payload: NodePayload {
|
||||
label: node.payload.label(),
|
||||
|
|
@ -361,13 +358,10 @@ fn wire_node<N: WireNode, R: WireResource>(node: &hive_jobq::Node<N, R>) -> Grap
|
|||
}
|
||||
}
|
||||
|
||||
fn wire_dep<R: WireResource>(dep: &Dep<R>) -> GraphDep {
|
||||
fn wire_dep<R>(dep: &Dep<R>) -> Option<GraphDep> {
|
||||
match dep {
|
||||
Dep::Node { id, .. } => GraphDep::Node { id: id.get() },
|
||||
Dep::Resource { name, count } => GraphDep::Resource {
|
||||
name: name.name(),
|
||||
count: *count,
|
||||
},
|
||||
Dep::Node { id, .. } => Some(GraphDep::Node { id: id.get() }),
|
||||
Dep::Resource { .. } => None,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -426,7 +420,7 @@ mod tests {
|
|||
}
|
||||
|
||||
// The test payloads. `&str` labels itself and has nothing extra to say;
|
||||
// `String` is its own resource name.
|
||||
|
||||
impl WireNode for &str {
|
||||
fn label(&self) -> String {
|
||||
(*self).to_owned()
|
||||
|
|
@ -438,12 +432,6 @@ mod tests {
|
|||
}
|
||||
}
|
||||
|
||||
impl super::WireResource for String {
|
||||
fn name(&self) -> String {
|
||||
self.clone()
|
||||
}
|
||||
}
|
||||
|
||||
/// The bound is the *caller's*: `wire_snapshot` serialises the roots it is
|
||||
/// handed and their subtrees, and nothing else. Nothing in a `Graph` is
|
||||
/// ever removed, so a host that couldn't restrict this would have no way to
|
||||
|
|
@ -479,10 +467,11 @@ mod tests {
|
|||
assert_eq!(wire[1].parent, Some(shown[0].get()));
|
||||
}
|
||||
|
||||
/// `label` / `data` / `name` all come from the host's impls — the graph
|
||||
/// layer never invents a rendering for a payload it cannot read.
|
||||
/// `label` / `data` come from the host's impl — the graph layer never
|
||||
/// invents a rendering for a payload it cannot read. A resource edge is in
|
||||
/// the scheduler's graph but not on the wire.
|
||||
#[test]
|
||||
fn payload_and_resource_rendering_come_from_the_host_impls() {
|
||||
fn payload_rendering_comes_from_the_host_impl_and_resource_edges_stay_off_the_wire() {
|
||||
let mut sched = sched();
|
||||
let ids = sched
|
||||
.insert_job(None, |job| {
|
||||
|
|
@ -498,15 +487,18 @@ mod tests {
|
|||
|
||||
let wire = sched.graph().wire_snapshot([first, second]);
|
||||
|
||||
assert_eq!(
|
||||
sched.graph().node(second).expect("node").deps.len(),
|
||||
2,
|
||||
"control: the scheduler holds the node dep and the resource dep"
|
||||
);
|
||||
assert_eq!(wire[0].payload.label, "reconcile");
|
||||
assert_eq!(wire[0].payload.data["seen_id"], first.get());
|
||||
match &wire[1].deps[..] {
|
||||
[GraphDep::Node { id }, GraphDep::Resource { name, count }] => {
|
||||
[GraphDep::Node { id }] => {
|
||||
assert_eq!(*id, first.get());
|
||||
assert_eq!(name, "build-slot", "the host's WireResource::name");
|
||||
assert_eq!(*count, 2);
|
||||
}
|
||||
other => panic!("expected a node dep then a resource dep, got {other:?}"),
|
||||
other => panic!("expected only the node dep, got {other:?}"),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -526,23 +518,39 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn a_node_round_trips_through_json() {
|
||||
let before = node(
|
||||
7,
|
||||
Some(3),
|
||||
State::Running,
|
||||
vec![
|
||||
GraphDep::Node { id: 3 },
|
||||
GraphDep::Resource {
|
||||
name: "build-slot".to_owned(),
|
||||
count: 1,
|
||||
},
|
||||
],
|
||||
);
|
||||
let before = node(7, Some(3), State::Running, vec![GraphDep::Node { id: 3 }]);
|
||||
let json = serde_json::to_string(&before).expect("serialises");
|
||||
let after: GraphNode = serde_json::from_str(&json).expect("round trips");
|
||||
assert_eq!(format!("{after:?}"), format!("{before:?}"));
|
||||
}
|
||||
|
||||
/// A sender from before resource edges left the wire still emits them; the
|
||||
/// receiver keeps the node and reads the edge as `Unknown` instead of
|
||||
/// rejecting the graph.
|
||||
#[test]
|
||||
fn an_old_senders_resource_edge_is_tolerated() {
|
||||
let mut json = serde_json::to_value(node(
|
||||
7,
|
||||
None,
|
||||
State::Pending,
|
||||
vec![GraphDep::Node { id: 3 }],
|
||||
))
|
||||
.expect("serialises");
|
||||
json["deps"]
|
||||
.as_array_mut()
|
||||
.expect("deps")
|
||||
.push(serde_json::json!({ "kind": "Resource", "name": "build-slot", "count": 1 }));
|
||||
|
||||
let after: GraphNode = serde_json::from_value(json).expect("tolerated");
|
||||
|
||||
assert_eq!(after.deps.len(), 2);
|
||||
assert!(
|
||||
matches!(after.deps[0], GraphDep::Node { id: 3 }),
|
||||
"control: a node edge still parses"
|
||||
);
|
||||
assert!(matches!(after.deps[1], GraphDep::Unknown));
|
||||
}
|
||||
|
||||
/// The serialised node carries exactly these keys (`parent`, `deps` and
|
||||
/// `error` are omitted when empty, `payload.data` when null).
|
||||
#[test]
|
||||
|
|
|
|||
Loading…
Reference in a new issue