Skip to content

Commit

Permalink
[π˜€π—½π—Ώ] initial version
Browse files Browse the repository at this point in the history
Created using spr 1.3.4
  • Loading branch information
sunshowers committed Oct 26, 2023
2 parents 3c6ae58 + 424abe5 commit 4ac14da
Show file tree
Hide file tree
Showing 5 changed files with 276 additions and 108 deletions.
185 changes: 152 additions & 33 deletions update-engine/src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,13 @@ impl<S: StepSpec> EventStore<S> {
// index.
let root_event_index = RootEventIndex(event.event_index);

let actions =
self.recurse_for_step_event(&event, 0, None, root_event_index);
let actions = self.recurse_for_step_event(
&event,
0,
None,
root_event_index,
event.total_elapsed,
);
if let Some(new_execution) = actions.new_execution {
if new_execution.nest_level == 0 {
self.root_execution_id = Some(new_execution.execution_id);
Expand Down Expand Up @@ -312,6 +317,7 @@ impl<S: StepSpec> EventStore<S> {
nest_level: usize,
parent_sort_key: Option<&StepSortKey>,
root_event_index: RootEventIndex,
root_total_elapsed: Duration,
) -> RecurseActions {
let mut new_execution = None;
let (step_key, progress_key) = match &event.kind {
Expand Down Expand Up @@ -365,6 +371,8 @@ impl<S: StepSpec> EventStore<S> {
let info = CompletionInfo {
attempt: *attempt,
outcome,
root_total_elapsed,
leaf_total_elapsed: event.total_elapsed,
step_elapsed: *step_elapsed,
attempt_elapsed: *attempt_elapsed,
};
Expand Down Expand Up @@ -405,6 +413,8 @@ impl<S: StepSpec> EventStore<S> {
let info = CompletionInfo {
attempt: *last_attempt,
outcome,
root_total_elapsed,
leaf_total_elapsed: event.total_elapsed,
step_elapsed: *step_elapsed,
attempt_elapsed: *attempt_elapsed,
};
Expand Down Expand Up @@ -432,6 +442,8 @@ impl<S: StepSpec> EventStore<S> {
total_attempts: *total_attempts,
message: message.clone(),
causes: causes.clone(),
root_total_elapsed,
leaf_total_elapsed: event.total_elapsed,
step_elapsed: *step_elapsed,
attempt_elapsed: *attempt_elapsed,
};
Expand All @@ -456,6 +468,8 @@ impl<S: StepSpec> EventStore<S> {
let info = AbortInfo {
attempt: *attempt,
message: message.clone(),
root_total_elapsed,
leaf_total_elapsed: event.total_elapsed,
step_elapsed: *step_elapsed,
attempt_elapsed: *attempt_elapsed,
};
Expand All @@ -481,6 +495,7 @@ impl<S: StepSpec> EventStore<S> {
nest_level + 1,
parent_sort_key.as_ref(),
root_event_index,
root_total_elapsed,
);
if let Some(nested_new_execution) = &actions.new_execution {
// Add an edge from the parent node to the new execution's root node.
Expand Down Expand Up @@ -1164,6 +1179,8 @@ impl<S: StepSpec> StepStatus<S> {
pub struct CompletionInfo {
pub attempt: usize,
pub outcome: StepOutcome<NestedSpec>,
pub root_total_elapsed: Duration,
pub leaf_total_elapsed: Duration,
pub step_elapsed: Duration,
pub attempt_elapsed: Duration,
}
Expand All @@ -1179,11 +1196,23 @@ pub enum FailureReason {
},
}

impl FailureReason {
/// Returns the [`FailureInfo`] if present.
pub fn info(&self) -> Option<&FailureInfo> {
match self {
Self::StepFailed(info) => Some(info),
Self::ParentFailed { .. } => None,
}
}
}

#[derive(Clone, Debug)]
pub struct FailureInfo {
pub total_attempts: usize,
pub message: String,
pub causes: Vec<String>,
pub root_total_elapsed: Duration,
pub leaf_total_elapsed: Duration,
pub step_elapsed: Duration,
pub attempt_elapsed: Duration,
}
Expand All @@ -1199,6 +1228,16 @@ pub enum AbortReason {
},
}

impl AbortReason {
/// Returns the [`AbortInfo`] if present.
pub fn info(&self) -> Option<&AbortInfo> {
match self {
Self::StepAborted(info) => Some(info),
Self::ParentAborted { .. } => None,
}
}
}

#[derive(Clone, Debug)]
pub enum WillNotBeRunReason {
/// A preceding step failed.
Expand Down Expand Up @@ -1230,6 +1269,13 @@ pub enum WillNotBeRunReason {
pub struct AbortInfo {
pub attempt: usize,
pub message: String,

/// The total elapsed time as reported by the root event.
pub root_total_elapsed: Duration,

/// The total elapsed time as reported by the leaf execution event, for
/// nested events.
pub leaf_total_elapsed: Duration,
pub step_elapsed: Duration,
pub attempt_elapsed: Duration,
}
Expand Down Expand Up @@ -1261,14 +1307,61 @@ impl ExecutionSummary {
StepStatus::Running { .. } => {
execution_status = ExecutionStatus::Running { step_key };
}
StepStatus::Completed { .. } => {
execution_status = ExecutionStatus::Completed { step_key };
StepStatus::Completed { info } => {
let (root_total_elapsed, leaf_total_elapsed) = match info {
Some(info) => (
Some(info.root_total_elapsed),
Some(info.leaf_total_elapsed),
),
None => (None, None),
};

let terminal_status = ExecutionTerminalInfo {
kind: TerminalKind::Completed,
root_total_elapsed,
leaf_total_elapsed,
step_key,
};
execution_status =
ExecutionStatus::Terminal(terminal_status);
}
StepStatus::Failed { .. } => {
execution_status = ExecutionStatus::Failed { step_key };
StepStatus::Failed { reason } => {
let (root_total_elapsed, leaf_total_elapsed) =
match reason.info() {
Some(info) => (
Some(info.root_total_elapsed),
Some(info.leaf_total_elapsed),
),
None => (None, None),
};

let terminal_status = ExecutionTerminalInfo {
kind: TerminalKind::Failed,
root_total_elapsed,
leaf_total_elapsed,
step_key,
};
execution_status =
ExecutionStatus::Terminal(terminal_status);
}
StepStatus::Aborted { .. } => {
execution_status = ExecutionStatus::Aborted { step_key };
StepStatus::Aborted { reason, .. } => {
let (root_total_elapsed, leaf_total_elapsed) =
match reason.info() {
Some(info) => (
Some(info.root_total_elapsed),
Some(info.leaf_total_elapsed),
),
None => (None, None),
};

let terminal_status = ExecutionTerminalInfo {
kind: TerminalKind::Aborted,
root_total_elapsed,
leaf_total_elapsed,
step_key,
};
execution_status =
ExecutionStatus::Terminal(terminal_status);
}
StepStatus::WillNotBeRun { .. } => {
// Ignore steps that will not be run -- a prior step failed.
Expand Down Expand Up @@ -1306,7 +1399,7 @@ impl StepSortKey {
/// Status about a single execution ID.
///
/// Part of [`ExecutionSummary`].
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum ExecutionStatus {
/// This execution has not been started yet.
NotStarted,
Expand All @@ -1319,27 +1412,50 @@ pub enum ExecutionStatus {
step_key: StepKey,
},

/// This execution completed running.
Completed {
/// The last step that completed.
step_key: StepKey,
},
/// Execution has finished.
Terminal(ExecutionTerminalInfo),
}

/// This execution failed.
Failed {
/// The step key that failed.
///
/// Use [`EventBuffer::get`] to get more information about this step.
step_key: StepKey,
},
/// Terminal status about a single execution ID.
///
/// Part of [`ExecutionStatus`].
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct ExecutionTerminalInfo {
/// The way in which this execution reached a terminal state.
pub kind: TerminalKind,

/// Total elapsed time (root) for this execution.
///
/// The total elapsed time may not be available if execution was interrupted
/// and we inferred that it was terminated.
pub root_total_elapsed: Option<Duration>,

/// Total elapsed time (leaf) for this execution.
///
/// The total elapsed time may not be available if execution was interrupted
/// and we inferred that it was terminated.
pub leaf_total_elapsed: Option<Duration>,

/// The step key that was running when this execution was terminated.
///
/// * For completed executions, this is the last step that completed.
/// * For failed or aborted executions, this is the step that failed.
/// * For aborted executions, this is the step that was running when the
/// abort happened.
pub step_key: StepKey,
}

/// The way in which an execution was terminated.
///
/// Part of [`ExecutionStatus`].
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum TerminalKind {
/// This execution completed running.
Completed,
/// This execution failed.
Failed,
/// This execution was aborted.
Aborted {
/// The step that was running when the abort happened.
///
/// Use [`EventBuffer::get`] to get more information about this step.
step_key: StepKey,
},
Aborted,
}

/// Keys for the event tree.
Expand Down Expand Up @@ -1925,8 +2041,9 @@ mod tests {
if is_last_event {
ensure!(
matches!(
summary[&root_execution_id].execution_status,
ExecutionStatus::Completed { .. },
&summary[&root_execution_id].execution_status,
ExecutionStatus::Terminal(info)
if info.kind == TerminalKind::Completed
),
"this is the last event so ExecutionStatus must be completed"
);
Expand All @@ -1941,8 +2058,9 @@ mod tests {
.expect("this is the first nested engine");
ensure!(
matches!(
nested_summary.execution_status,
ExecutionStatus::Failed { .. },
&nested_summary.execution_status,
ExecutionStatus::Terminal(info)
if info.kind == TerminalKind::Failed
),
"for this engine, the ExecutionStatus must be failed"
);
Expand All @@ -1952,8 +2070,9 @@ mod tests {
.expect("this is the second nested engine");
ensure!(
matches!(
nested_summary.execution_status,
ExecutionStatus::Completed { .. },
&nested_summary.execution_status,
ExecutionStatus::Terminal(info)
if info.kind == TerminalKind::Completed
),
"for this engine, the ExecutionStatus must be succeeded"
);
Expand Down
32 changes: 20 additions & 12 deletions wicket/src/state/inventory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use anyhow::anyhow;
use once_cell::sync::Lazy;
use ratatui::text::Text;
use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;
use std::fmt::Display;
Expand Down Expand Up @@ -185,7 +184,7 @@ impl Component {
}
}

// The component type and its slot.
/// The component type and its slot.
#[derive(
Debug,
Clone,
Expand All @@ -205,27 +204,24 @@ pub enum ComponentId {
}

impl ComponentId {
pub fn name(&self) -> String {
self.to_string()
pub fn to_string_uppercase(&self) -> String {
let mut s = self.to_string();
s.make_ascii_uppercase();
s
}
}

/// Prints the component type in standard case.
impl Display for ComponentId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
ComponentId::Sled(i) => write!(f, "SLED {}", i),
ComponentId::Switch(i) => write!(f, "SWITCH {}", i),
ComponentId::Sled(i) => write!(f, "sled {}", i),
ComponentId::Switch(i) => write!(f, "switch {}", i),
ComponentId::Psc(i) => write!(f, "PSC {}", i),
}
}
}

impl From<ComponentId> for Text<'_> {
fn from(value: ComponentId) -> Self {
value.to_string().into()
}
}

pub struct ParsableComponentId<'a> {
pub sp_type: &'a str,
pub i: &'a str,
Expand Down Expand Up @@ -269,3 +265,15 @@ impl PowerState {
}
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn component_id_display() {
assert_eq!(ComponentId::Sled(0).to_string(), "sled 0");
assert_eq!(ComponentId::Switch(1).to_string(), "switch 1");
assert_eq!(ComponentId::Psc(2).to_string(), "PSC 2");
}
}
2 changes: 1 addition & 1 deletion wicket/src/ui/panes/overview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ impl Control for InventoryView {
let title_bar = Paragraph::new(Line::from(vec![
Span::styled("OXIDE RACK / ", border_style),
Span::styled(
state.rack_state.selected.to_string(),
state.rack_state.selected.to_string_uppercase(),
component_style,
),
]))
Expand Down
Loading

0 comments on commit 4ac14da

Please sign in to comment.