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

Avoid too verbose warnings in terminal when cache issues #14442

Closed
wants to merge 2 commits into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ public void registerSpawnCache(ModuleActionContextRegistry.Builder registryBuild
env.getExecRoot(),
checkNotNull(env.getOptions().getOptions(RemoteOptions.class)),
checkNotNull(env.getOptions().getOptions(ExecutionOptions.class)).verboseFailures,
env.getReporter(),
getRemoteExecutionService());
registryBuilder.register(SpawnCache.class, spawnCache, "remote-cache");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,12 @@
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Set;
import java.util.SortedMap;
import java.util.TreeSet;
import java.util.concurrent.ConcurrentLinkedQueue;
Expand All @@ -161,6 +163,7 @@ public class RemoteExecutionService {
private final ImmutableSet<PathFragment> filesToDownload;
@Nullable private final Path captureCorruptedOutputsDir;
private final Cache<Object, MerkleTree> merkleTreeCache;
private final Set<String> reportedErrors = new HashSet<>();

private final Scheduler scheduler;

Expand Down Expand Up @@ -1192,9 +1195,9 @@ private void reportUploadError(Throwable error) {
}

String errorMessage =
"Writing to Remote Cache: " + grpcAwareErrorMessage(error, verboseFailures);
"Remote Cache: " + grpcAwareErrorMessage(error, verboseFailures);

reporter.handle(Event.warn(errorMessage));
report(Event.warn(errorMessage));
}

/**
Expand Down Expand Up @@ -1317,4 +1320,15 @@ public void shutdown() {
remoteExecutor.close();
}
}

void report(Event evt) {

synchronized (this) {
if (reportedErrors.contains(evt.getMessage())) {
return;
}
reportedErrors.add(evt.getMessage());
reporter.handle(evt);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,16 @@ final class RemoteSpawnCache implements SpawnCache {
private final Path execRoot;
private final RemoteOptions options;
private final boolean verboseFailures;
@Nullable private final Reporter cmdlineReporter;
private final Set<String> reportedErrors = new HashSet<>();
private final RemoteExecutionService remoteExecutionService;

RemoteSpawnCache(
Path execRoot,
RemoteOptions options,
boolean verboseFailures,
@Nullable Reporter cmdlineReporter,
RemoteExecutionService remoteExecutionService) {
this.execRoot = execRoot;
this.options = options;
this.verboseFailures = verboseFailures;
this.cmdlineReporter = cmdlineReporter;
this.remoteExecutionService = remoteExecutionService;
}

Expand Down Expand Up @@ -150,13 +146,13 @@ public CacheHandle lookup(Spawn spawn, SpawnExecutionContext context)
errorMessage = Utils.grpcAwareErrorMessage(e);
} else {
// On --verbose_failures print the whole stack trace
errorMessage = Throwables.getStackTraceAsString(e);
errorMessage = "\n" + Throwables.getStackTraceAsString(e);
}
if (isNullOrEmpty(errorMessage)) {
errorMessage = e.getClass().getSimpleName();
}
errorMessage = "Reading from Remote Cache:\n" + errorMessage;
report(Event.warn(errorMessage));
errorMessage = "Remote Cache: " + errorMessage;
remoteExecutionService.report(Event.warn(errorMessage));
}
}
}
Expand Down Expand Up @@ -193,7 +189,7 @@ public void store(SpawnResult result) throws ExecException, InterruptedException
try (SilentCloseable c = prof.profile("RemoteCache.checkForConcurrentModifications")) {
checkForConcurrentModifications();
} catch (IOException | ForbiddenActionInputException e) {
report(Event.warn(e.getMessage()));
remoteExecutionService.report(Event.warn(e.getMessage()));
return;
}
}
Expand Down Expand Up @@ -223,20 +219,6 @@ private void checkForConcurrentModifications()
}
}

private void report(Event evt) {
if (cmdlineReporter == null) {
return;
}

synchronized (this) {
if (reportedErrors.contains(evt.getMessage())) {
return;
}
reportedErrors.add(evt.getMessage());
cmdlineReporter.handle(evt);
}
}

@Override
public boolean usefulInDynamicExecution() {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ private RemoteSpawnCache remoteSpawnCacheWithOptions(RemoteOptions options) {
null,
ImmutableSet.of(),
/* captureCorruptedOutputsDir= */ null));
return new RemoteSpawnCache(execRoot, options, /* verboseFailures=*/ true, reporter, service);
return new RemoteSpawnCache(execRoot, options, /* verboseFailures=*/ true, service);
}

@Before
Expand Down
4 changes: 2 additions & 2 deletions src/test/shell/bazel/remote/remote_execution_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3264,14 +3264,14 @@ EOF

# Check the error message when failed to upload
bazel build --remote_cache=http://nonexistent.example.org //a:foo >& $TEST_log || fail "Failed to build"
expect_log "WARNING: Writing to Remote Cache:"
expect_log "WARNING: Remote Cache:"

bazel test \
--remote_cache=grpc://localhost:${worker_port} \
--experimental_remote_cache_async \
--flaky_test_attempts=2 \
//a:test >& $TEST_log && fail "expected failure" || true
expect_not_log "WARNING: Writing to Remote Cache:"
expect_not_log "WARNING: Remote Cache:"
}

function test_download_toplevel_when_turn_remote_cache_off() {
Expand Down