Skip to content

Commit

Permalink
[π˜€π—½π—Ώ] initial version
Browse files Browse the repository at this point in the history
Created using spr 1.3.5
  • Loading branch information
sunshowers committed Nov 7, 2023
2 parents 6db8819 + 81be6de commit afc99eb
Show file tree
Hide file tree
Showing 37 changed files with 3,215 additions and 326 deletions.
25 changes: 25 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ lazy_static = "1.4.0"
libc = "0.2.150"
linear-map = "1.2.0"
macaddr = { version = "1.0.1", features = ["serde_std"] }
maplit = "1.0.2"
mime_guess = "2.0.4"
mockall = "0.11"
newtype_derive = "0.1.6"
Expand Down Expand Up @@ -345,6 +346,7 @@ static_assertions = "1.1.0"
steno = "0.4.0"
strum = { version = "0.25", features = [ "derive" ] }
subprocess = "0.2.9"
supports-color = "2.1.0"
swrite = "0.1.0"
libsw = { version = "3.3.0", features = ["tokio"] }
syn = { version = "2.0" }
Expand Down
3 changes: 3 additions & 0 deletions clients/wicketd-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ progenitor::generate_api!(
Ipv6Network = ipnetwork::Ipv6Network,
IpNetwork = ipnetwork::IpNetwork,
PutRssUserConfigInsensitive = wicket_common::rack_setup::PutRssUserConfigInsensitive,
ClearUpdateStateResponse = wicket_common::rack_update::ClearUpdateStateResponse,
SpIdentifier = wicket_common::rack_update::SpIdentifier,
SpType = wicket_common::rack_update::SpType,
EventReportForWicketdEngineSpec = wicket_common::update_events::EventReport,
StepEventForWicketdEngineSpec = wicket_common::update_events::StepEvent,
ProgressEventForWicketdEngineSpec = wicket_common::update_events::ProgressEvent,
Expand Down
5 changes: 5 additions & 0 deletions update-engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@ either.workspace = true
futures.workspace = true
indexmap.workspace = true
linear-map.workspace = true
owo-colors.workspace = true
petgraph.workspace = true
serde.workspace = true
serde_json.workspace = true
serde_with.workspace = true
schemars = { workspace = true, features = ["uuid1"] }
slog.workspace = true
swrite.workspace = true
tokio = { workspace = true, features = ["macros", "sync", "time", "rt-multi-thread"] }
unicode-width.workspace = true
uuid.workspace = true
omicron-workspace-hack.workspace = true

Expand All @@ -28,8 +31,10 @@ buf-list.workspace = true
bytes.workspace = true
camino.workspace = true
camino-tempfile.workspace = true
clap.workspace = true
indicatif.workspace = true
omicron-test-utils.workspace = true
owo-colors.workspace = true
supports-color.workspace = true
tokio = { workspace = true, features = ["io-util"] }
tokio-stream.workspace = true
123 changes: 115 additions & 8 deletions update-engine/examples/update-engine-basic/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,135 @@ use indexmap::{map::Entry, IndexMap};
use indicatif::{MultiProgress, ProgressBar, ProgressStyle};
use owo_colors::OwoColorize;
use tokio::{sync::mpsc, task::JoinHandle};
use update_engine::events::ProgressCounter;
use update_engine::{
display::{GroupDisplay, LineDisplay, LineDisplayStyles},
events::ProgressCounter,
};

use crate::spec::{
Event, ExampleComponent, ExampleStepId, ExampleStepMetadata, ProgressEvent,
ProgressEventKind, StepEventKind, StepInfoWithMetadata, StepOutcome,
use crate::{
spec::{
Event, EventBuffer, ExampleComponent, ExampleStepId,
ExampleStepMetadata, ProgressEvent, ProgressEventKind, StepEventKind,
StepInfoWithMetadata, StepOutcome,
},
DisplayStyle,
};

/// An example that displays an event stream on the command line.
pub(crate) fn make_displayer(
log: &slog::Logger,
display_style: DisplayStyle,
prefix: Option<String>,
) -> (JoinHandle<Result<()>>, mpsc::Sender<Event>) {
let (sender, receiver) = mpsc::channel(512);
let log = log.clone();
let join_handle =
tokio::task::spawn(
async move { display_messages(&log, receiver).await },
);
match display_style {
DisplayStyle::ProgressBar => tokio::task::spawn(async move {
display_progress_bar(&log, receiver).await
}),
DisplayStyle::Line => tokio::task::spawn(async move {
display_line(&log, receiver, prefix).await
}),
DisplayStyle::Group => tokio::task::spawn(async move {
display_group(&log, receiver).await
}),
};

(join_handle, sender)
}

async fn display_messages(
async fn display_line(
log: &slog::Logger,
mut receiver: mpsc::Receiver<Event>,
prefix: Option<String>,
) -> Result<()> {
slog::info!(log, "setting up display");
let mut buffer = EventBuffer::new(8);
let mut display = LineDisplay::new(std::io::stdout());
// For now, always colorize. TODO: figure out whether colorization should be
// done based on always/auto/never etc.
if supports_color::on(supports_color::Stream::Stdout).is_some() {
display.set_styles(LineDisplayStyles::colorized());
}
if let Some(prefix) = prefix {
display.set_prefix(prefix);
}
display.set_progress_interval(Duration::from_millis(50));
while let Some(event) = receiver.recv().await {
buffer.add_event(event);
display.write_event_buffer(&buffer)?;
}

Ok(())
}

#[derive(Clone, Copy, Debug, Eq, PartialEq, PartialOrd, Ord)]
enum GroupDisplayKey {
Example,
Other,
}

async fn display_group(
log: &slog::Logger,
mut receiver: mpsc::Receiver<Event>,
) -> Result<()> {
slog::info!(log, "setting up display");

let mut display = GroupDisplay::new(
[
(GroupDisplayKey::Example, "example"),
(GroupDisplayKey::Other, "other"),
],
std::io::stdout(),
);
// For now, always colorize. TODO: figure out whether colorization should be
// done based on always/auto/never etc.
if supports_color::on(supports_color::Stream::Stdout).is_some() {
display.set_styles(LineDisplayStyles::colorized());
}

display.set_progress_interval(Duration::from_millis(50));

let mut example_buffer = EventBuffer::default();
let mut example_buffer_last_seen = None;
let mut other_buffer = EventBuffer::default();
let mut other_buffer_last_seen = None;

let mut interval = tokio::time::interval(Duration::from_secs(2));
interval.tick().await;

loop {
tokio::select! {
_ = interval.tick() => {
// Print out status lines every 2 seconds.
display.write_stats("Status")?;
}
event = receiver.recv() => {
let Some(event) = event else { break };
example_buffer.add_event(event.clone());
other_buffer.add_event(event);

display.add_event_report(
&GroupDisplayKey::Example,
example_buffer.generate_report_since(&mut example_buffer_last_seen),
)?;
display.add_event_report(
&GroupDisplayKey::Other,
other_buffer.generate_report_since(&mut other_buffer_last_seen),
)?;
display.write_events()?;
}
}
}

// Print status at the end.
display.write_stats("Summary")?;

Ok(())
}

async fn display_progress_bar(
log: &slog::Logger,
mut receiver: mpsc::Receiver<Event>,
) -> Result<()> {
Expand Down
Loading

0 comments on commit afc99eb

Please sign in to comment.