Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide feedback if it takes a while to download a remote component on spin up #2226

Merged
merged 3 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
11 changes: 10 additions & 1 deletion crates/loader/src/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::path::{Path, PathBuf};
use anyhow::{bail, ensure, Context, Result};
use futures::future::try_join_all;
use reqwest::Url;
use spin_common::{paths::parent_dir, ui::quoted_path};
use spin_common::{paths::parent_dir, sloth, ui::quoted_path};
use spin_locked_app::{
locked::{
self, ContentPath, ContentRef, LockedApp, LockedComponent, LockedComponentSource,
Expand Down Expand Up @@ -94,6 +94,8 @@ impl LocalLoader {
})
.collect::<Result<Vec<_>>>()?;

warn_if_component_load_slothful();
Archisman-Mridha marked this conversation as resolved.
Show resolved Hide resolved

// Load all components concurrently
let components = try_join_all(components.into_iter().map(|(id, c)| async move {
self.load_component(&id, c)
Expand Down Expand Up @@ -516,3 +518,10 @@ fn file_url(path: impl AsRef<Path>) -> Result<String> {
.with_context(|| format!("Couldn't resolve `{}`", path.display()))?;
Ok(Url::from_file_path(abs_path).unwrap().to_string())
}

const SLOTH_WARNING_DELAY_MILLIS: u64 = 1250;

fn warn_if_component_load_slothful() -> sloth::SlothGuard {
let message = "WASM components loading is taking a few seconds...";
Archisman-Mridha marked this conversation as resolved.
Show resolved Hide resolved
sloth::warn_if_slothful(SLOTH_WARNING_DELAY_MILLIS, format!("{message}\n"))
}
3 changes: 3 additions & 0 deletions crates/oci/src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ impl OciLoader {

/// Pulls and loads an OCI Artifact and returns a LockedApp with the given OCI client and reference
pub async fn load_app(&self, client: &mut Client, reference: &str) -> Result<LockedApp> {
// Fix: https://github.com/fermyon/spin/issues/2109.
println!("pulling spin application from registry reference {reference:?}...");
Archisman-Mridha marked this conversation as resolved.
Show resolved Hide resolved

// Fetch app
client.pull(reference).await.with_context(|| {
format!("cannot pull Spin application from registry reference {reference:?}")
Expand Down
Loading