Skip to content

Commit

Permalink
add always mode for RemoteCacheWarningsBehavior (pantsbuild#20268)
Browse files Browse the repository at this point in the history
Looked at the configuration docs here for a Slack thread, and felt like
this would've been the most sensible option to use -- but it did not
exist. 🤷
  • Loading branch information
tgolsson authored Dec 7, 2023
1 parent ad14568 commit ee40ca3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/python/pants/option/global_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ class RemoteCacheWarningsBehavior(Enum):
ignore = "ignore"
first_only = "first_only"
backoff = "backoff"
always = "always"


@enum.unique
Expand Down
20 changes: 13 additions & 7 deletions src/rust/engine/process_execution/remote/src/remote_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pub enum RemoteCacheWarningsBehavior {
Ignore,
FirstOnly,
Backoff,
Always,
}

pub struct RemoteCacheRunnerOptions {
Expand Down Expand Up @@ -424,19 +425,24 @@ impl CommandRunner {
CacheErrorType::ReadError => "read from",
CacheErrorType::WriteError => "write to",
};
let log_msg = format!(
"Failed to {failure_desc} remote cache ({err_count} occurrences so far): {err}"
);

let log_at_warn = match self.warnings_behavior {
RemoteCacheWarningsBehavior::Ignore => false,
RemoteCacheWarningsBehavior::FirstOnly => err_count == 1,
RemoteCacheWarningsBehavior::Backoff => err_count.is_power_of_two(),
RemoteCacheWarningsBehavior::Always => true,
};
if log_at_warn {
log::warn!("{}", log_msg);

let level = if log_at_warn {
Level::Warn
} else {
log::debug!("{}", log_msg);
}
Level::Debug
};

log::log!(
level,
"Failed to {failure_desc} remote cache ({err_count} occurrences so far): {err}"
);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,17 @@ def write_err(i: int) -> str:
for err in [third_read_err, third_write_err]:
assert err not in backoff_result

always_result = run(RemoteCacheWarningsBehavior.always)
for err in [
first_read_err,
first_write_err,
third_read_err,
third_write_err,
fourth_read_err,
fourth_write_err,
]:
assert err in always_result, f"Not found in:\n{always_result}"


class ProcessOutputEntries(DigestEntries):
pass
Expand Down

0 comments on commit ee40ca3

Please sign in to comment.