Skip to content

Commit

Permalink
fix: add extra detail to summary showing items from remote cache
Browse files Browse the repository at this point in the history
  • Loading branch information
arlyon committed Mar 11, 2024
1 parent b322676 commit a96c6db
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 17 deletions.
2 changes: 1 addition & 1 deletion crates/turborepo-cache/src/lib.rs
Expand Up @@ -86,7 +86,7 @@ impl From<turborepo_api_client::Error> for CacheError {
}
}

#[derive(Debug, Clone, PartialEq, Copy)]
#[derive(Debug, Clone, PartialEq, Copy, Serialize)]
pub enum CacheSource {
Local,
Remote,
Expand Down
40 changes: 27 additions & 13 deletions crates/turborepo-lib/src/run/summary/execution.rs
Expand Up @@ -4,6 +4,7 @@ use chrono::{DateTime, Local};
use serde::Serialize;
use tokio::sync::mpsc;
use turbopath::{AbsoluteSystemPathBuf, AnchoredSystemPath};
use turborepo_cache::CacheSource;
use turborepo_ui::{color, cprintln, BOLD, BOLD_GREEN, BOLD_RED, MAGENTA, UI, YELLOW};

use super::TurboDuration;
Expand Down Expand Up @@ -35,7 +36,8 @@ pub struct ExecutionSummary<'a> {
// number of tasks that exited with failure
failed: usize,
// number of tasks that had a cache hit
cached: usize,
cached_local: usize,
cached_remote: usize,
// number of tasks that started
attempted: usize,
pub(crate) start_time: i64,
Expand All @@ -59,7 +61,8 @@ impl<'a> ExecutionSummary<'a> {
command,
success: state.success,
failed: state.failed,
cached: state.cached,
cached_local: state.cached_local,
cached_remote: state.cached_remote,
attempted: state.attempted,
// We're either at some path in the repo, or at the root, which is an empty path
repo_path: package_inference_root.unwrap_or_else(|| AnchoredSystemPath::empty()),
Expand All @@ -73,7 +76,7 @@ impl<'a> ExecutionSummary<'a> {
/// We implement this on `ExecutionSummary` and not `RunSummary` because
/// the `execution` field is nullable (due to normalize).
pub fn print(&self, ui: UI, path: AbsoluteSystemPathBuf, failed_tasks: Vec<&TaskSummary>) {
let maybe_full_turbo = if self.cached == self.attempted && self.attempted > 0 {
let maybe_full_turbo = if self.cached() == self.attempted && self.attempted > 0 {
match std::env::var("TERM_PROGRAM").as_deref() {
Ok("Apple_Terminal") => color!(ui, MAGENTA, ">>> FULL TURBO").to_string(),
_ => ui.rainbow(">>> FULL TURBO").to_string(),
Expand All @@ -82,6 +85,12 @@ impl<'a> ExecutionSummary<'a> {
String::new()
};

let cache_line = if self.cached_remote > 0 {
format!("{} (of which {} remote)", self.cached(), self.cached_remote)
} else {
self.cached().to_string()
};

let mut line_data = vec![
(
"Tasks",
Expand All @@ -95,10 +104,9 @@ impl<'a> ExecutionSummary<'a> {
"Cached",
format!(
"{}, {} total",
color!(ui, BOLD, "{} cached", self.cached),
color!(ui, BOLD, "{} cached", cache_line),
self.attempted
)
.to_string(),
),
),
(
"Time",
Expand Down Expand Up @@ -157,7 +165,11 @@ impl<'a> ExecutionSummary<'a> {
}

fn successful(&self) -> usize {
self.success + self.cached
self.success + self.cached()
}

fn cached(&self) -> usize {
self.cached_local + self.cached_remote
}
}

Expand All @@ -166,7 +178,8 @@ impl<'a> ExecutionSummary<'a> {
pub struct SummaryState {
pub attempted: usize,
pub failed: usize,
pub cached: usize,
pub cached_local: usize,
pub cached_remote: usize,
pub success: usize,
pub tasks: Vec<TaskState>,
}
Expand All @@ -182,7 +195,8 @@ impl SummaryState {
match event {
Event::Building => self.attempted += 1,
Event::BuildFailed => self.failed += 1,
Event::Cached => self.cached += 1,
Event::Cached(CacheSource::Local) => self.cached_local += 1,
Event::Cached(CacheSource::Remote) => self.cached_remote += 1,
Event::Built => self.success += 1,
Event::Canceled => (),
}
Expand All @@ -208,7 +222,7 @@ struct TrackerMessage {
enum Event {
Building,
BuildFailed,
Cached,
Cached(CacheSource),
Built,
// Canceled due to external signal or internal failure
Canceled,
Expand Down Expand Up @@ -329,7 +343,7 @@ impl TaskTracker<chrono::DateTime<Local>> {
// internal turbo error
pub fn cancel(self) {}

pub async fn cached(self) -> TaskExecutionSummary {
pub async fn cached(self, source: CacheSource) -> TaskExecutionSummary {
let Self {
sender,
started_at,
Expand All @@ -351,7 +365,7 @@ impl TaskTracker<chrono::DateTime<Local>> {
};
sender
.send(TrackerMessage {
event: Event::Cached,
event: Event::Cached(source),
state: Some(state),
})
.await
Expand Down Expand Up @@ -472,7 +486,7 @@ mod test {

let state = summary.finish().await.unwrap();
assert_eq!(state.attempted, 4);
assert_eq!(state.cached, 1);
assert_eq!(state.cached_local, 1);
assert_eq!(state.failed, 1);
assert_eq!(state.success, 1);
let foo_state = state.tasks.iter().find(|task| task.task_id == foo).unwrap();
Expand Down
8 changes: 5 additions & 3 deletions crates/turborepo-lib/src/task_graph/visitor.rs
Expand Up @@ -12,6 +12,7 @@ use regex::Regex;
use tokio::sync::{mpsc, oneshot};
use tracing::{debug, error, Instrument, Span};
use turbopath::{AbsoluteSystemPath, AbsoluteSystemPathBuf, AnchoredSystemPath};
use turborepo_cache::CacheSource;
use turborepo_ci::{Vendor, VendorBehavior};
use turborepo_env::{EnvironmentVariableMap, ResolvedEnvMode};
use turborepo_repository::{
Expand Down Expand Up @@ -663,7 +664,8 @@ enum ExecOutcome {
}

enum SuccessOutcome {
CacheHit,
/// The task was a cache hit, from the given source
CacheHit(CacheSource),
Run,
}

Expand Down Expand Up @@ -709,7 +711,7 @@ impl ExecContext {
match result {
ExecOutcome::Success(outcome) => {
let task_summary = match outcome {
SuccessOutcome::CacheHit => tracker.cached().await,
SuccessOutcome::CacheHit(source) => tracker.cached(source).await,
SuccessOutcome::Run => tracker.build_succeeded(0).await,
};
callback.send(Ok(())).ok();
Expand Down Expand Up @@ -784,7 +786,7 @@ impl ExecContext {
);
self.hash_tracker
.insert_cache_status(self.task_id.clone(), status);
return ExecOutcome::Success(SuccessOutcome::CacheHit);
return ExecOutcome::Success(SuccessOutcome::CacheHit(status.source));
}
Ok(None) => (),
Err(e) => {
Expand Down

0 comments on commit a96c6db

Please sign in to comment.