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

chore(logging): Improved logs when using errors-only. #8889

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
45 changes: 35 additions & 10 deletions crates/turborepo-lib/src/run/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,6 @@ impl TaskCache {

pub fn on_error(&self, terminal_output: &mut impl CacheOutput) -> Result<(), Error> {
if self.task_output_logs == OutputLogsMode::ErrorsOnly {
terminal_output.status(
&format!(
"cache miss, executing {}",
color!(self.ui, GREY, "{}", self.hash)
),
CacheResult::Miss,
);
self.replay_log_file(terminal_output)?;
}

Expand Down Expand Up @@ -205,6 +198,17 @@ impl TaskCache {
telemetry: &PackageTaskEventBuilder,
) -> Result<Option<CacheHitMetadata>, Error> {
if self.caching_disabled || self.run_cache.reads_disabled {
if matches!(self.task_output_logs, OutputLogsMode::ErrorsOnly) {
terminal_output.status(
&format!(
"cache bypass, force executing {} {}",
color!(self.ui, GREY, "{}", self.hash),
color!(self.ui, GREY, "{}", "(only logging errors)")
),
CacheResult::Miss,
);
}

if !matches!(
self.task_output_logs,
OutputLogsMode::None | OutputLogsMode::ErrorsOnly
Expand Down Expand Up @@ -256,6 +260,17 @@ impl TaskCache {
.await?;

let Some((cache_hit_metadata, restored_files)) = cache_status else {
if matches!(self.task_output_logs, OutputLogsMode::ErrorsOnly) {
terminal_output.status(
&format!(
"cache miss, executing {} {}",
color!(self.ui, GREY, "{}", self.hash),
color!(self.ui, GREY, "{}", "(only logging errors)")
),
CacheResult::Miss,
);
}

if !matches!(
self.task_output_logs,
OutputLogsMode::None | OutputLogsMode::ErrorsOnly
Expand Down Expand Up @@ -332,9 +347,19 @@ impl TaskCache {
);
self.replay_log_file(terminal_output)?;
}
// Note that if we're restoring from cache, the task succeeded
// so we know we don't need to print anything for errors
OutputLogsMode::ErrorsOnly | OutputLogsMode::None => {}
OutputLogsMode::ErrorsOnly => {
debug!("log file path: {}", self.log_file_path);
terminal_output.status(
&format!(
"cache hit{}, replaying logs {} {}",
more_context,
color!(self.ui, GREY, "{}", self.hash),
color!(self.ui, GREY, "{}", "(no errors in logs)")
),
CacheResult::Hit,
);
}
OutputLogsMode::None => {}
}

Ok(cache_status)
Expand Down
6 changes: 4 additions & 2 deletions turborepo-tests/integration/tests/run-logging/errors-only.t
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Setup
\xe2\x80\xa2 Packages in scope: app-a (esc)
\xe2\x80\xa2 Running build in 1 packages (esc)
\xe2\x80\xa2 Remote caching disabled (esc)
app-a:build: cache miss, executing 612027951a2848ce (only logging errors)

Tasks: 1 successful, 1 total
Cached: 0 cached, 1 total
Expand All @@ -23,6 +24,7 @@ Setup
\xe2\x80\xa2 Packages in scope: app-a (esc)
\xe2\x80\xa2 Running buildsuccess in 1 packages (esc)
\xe2\x80\xa2 Remote caching disabled (esc)
app-a:buildsuccess: cache miss, executing 7ac84282f5a5b151 (only logging errors)

Tasks: 1 successful, 1 total
Cached: 0 cached, 1 total
Expand All @@ -37,7 +39,7 @@ Setup
\xe2\x80\xa2 Packages in scope: app-a (esc)
\xe2\x80\xa2 Running builderror in 1 packages (esc)
\xe2\x80\xa2 Remote caching disabled (esc)
app-a:builderror: cache miss, executing 7e337a3261100818
app-a:builderror: cache miss, executing 7e337a3261100818 (only logging errors)
app-a:builderror:
app-a:builderror: > builderror
app-a:builderror: > echo error-builderror-app-a && exit 1
Expand Down Expand Up @@ -67,7 +69,7 @@ Setup
\xe2\x80\xa2 Packages in scope: app-a (esc)
\xe2\x80\xa2 Running builderror2 in 1 packages (esc)
\xe2\x80\xa2 Remote caching disabled (esc)
app-a:builderror2: cache miss, executing 3731518fa339b920
app-a:builderror2: cache miss, executing 3731518fa339b920 (only logging errors)
app-a:builderror2:
app-a:builderror2: > builderror2
app-a:builderror2: > echo error-builderror2-app-a && exit 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ Run with --output-logs=errors-only
$ ${TURBO} run test --output-logs=errors-only
\xe2\x80\xa2 Running test (esc)
\xe2\x80\xa2 Remote caching disabled (esc)
build: cache hit, replaying logs 7ece7b62aad25615 (no errors in logs)
test: cache hit, replaying logs cb5839f7284aa5f3 (no errors in logs)

Tasks: 2 successful, 2 total
Cached: 2 cached, 2 total
Expand Down
Loading