Skip to content

Commit 2edab73

Browse files
ulrfacopybara-github
authored andcommitted
Avoid too verbose warnings in terminal when cache issues
Deduplicate warnings in terminal. This was working in earlier bazel versions both for read and write, but become broken when write was moved to RemoteExecutionService.java by the "Remote: Async upload" set of commits, completed by commit 581c81a. Use same phrase "Remote Cache" for both read and write, for deduplication to work better. Avoid printing short warnings on multiple lines for reads, as it already was for writes. Closes bazelbuild#14442. PiperOrigin-RevId: 419442535
1 parent 732e9ef commit 2edab73

File tree

5 files changed

+23
-33
lines changed

5 files changed

+23
-33
lines changed

src/main/java/com/google/devtools/build/lib/remote/RemoteActionContextProvider.java

-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,6 @@ public void registerSpawnCache(ModuleActionContextRegistry.Builder registryBuild
192192
env.getExecRoot(),
193193
checkNotNull(env.getOptions().getOptions(RemoteOptions.class)),
194194
checkNotNull(env.getOptions().getOptions(ExecutionOptions.class)).verboseFailures,
195-
env.getReporter(),
196195
getRemoteExecutionService());
197196
registryBuilder.register(SpawnCache.class, spawnCache, "remote-cache");
198197
}

src/main/java/com/google/devtools/build/lib/remote/RemoteExecutionService.java

+16-3
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,12 @@
132132
import java.util.Collections;
133133
import java.util.Comparator;
134134
import java.util.HashMap;
135+
import java.util.HashSet;
135136
import java.util.List;
136137
import java.util.Map;
137138
import java.util.Map.Entry;
138139
import java.util.Objects;
140+
import java.util.Set;
139141
import java.util.SortedMap;
140142
import java.util.TreeSet;
141143
import java.util.concurrent.ConcurrentLinkedQueue;
@@ -161,6 +163,7 @@ public class RemoteExecutionService {
161163
private final ImmutableSet<PathFragment> filesToDownload;
162164
@Nullable private final Path captureCorruptedOutputsDir;
163165
private final Cache<Object, MerkleTree> merkleTreeCache;
166+
private final Set<String> reportedErrors = new HashSet<>();
164167

165168
private final Scheduler scheduler;
166169

@@ -1186,10 +1189,9 @@ private void reportUploadError(Throwable error) {
11861189
return;
11871190
}
11881191

1189-
String errorMessage =
1190-
"Writing to Remote Cache: " + grpcAwareErrorMessage(error, verboseFailures);
1192+
String errorMessage = "Remote Cache: " + grpcAwareErrorMessage(error, verboseFailures);
11911193

1192-
reporter.handle(Event.warn(errorMessage));
1194+
report(Event.warn(errorMessage));
11931195
}
11941196

11951197
/**
@@ -1312,4 +1314,15 @@ public void shutdown() {
13121314
remoteExecutor.close();
13131315
}
13141316
}
1317+
1318+
void report(Event evt) {
1319+
1320+
synchronized (this) {
1321+
if (reportedErrors.contains(evt.getMessage())) {
1322+
return;
1323+
}
1324+
reportedErrors.add(evt.getMessage());
1325+
reporter.handle(evt);
1326+
}
1327+
}
13151328
}

src/main/java/com/google/devtools/build/lib/remote/RemoteSpawnCache.java

+4-26
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import com.google.devtools.build.lib.actions.cache.VirtualActionInput;
3232
import com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadSafe;
3333
import com.google.devtools.build.lib.events.Event;
34-
import com.google.devtools.build.lib.events.Reporter;
3534
import com.google.devtools.build.lib.exec.SpawnCache;
3635
import com.google.devtools.build.lib.exec.SpawnCheckingCacheEvent;
3736
import com.google.devtools.build.lib.exec.SpawnExecutingEvent;
@@ -48,10 +47,7 @@
4847
import com.google.devtools.build.lib.remote.util.Utils.InMemoryOutput;
4948
import com.google.devtools.build.lib.vfs.Path;
5049
import java.io.IOException;
51-
import java.util.HashSet;
5250
import java.util.NoSuchElementException;
53-
import java.util.Set;
54-
import javax.annotation.Nullable;
5551

5652
/** A remote {@link SpawnCache} implementation. */
5753
@ThreadSafe // If the RemoteActionCache implementation is thread-safe.
@@ -66,20 +62,16 @@ final class RemoteSpawnCache implements SpawnCache {
6662
private final Path execRoot;
6763
private final RemoteOptions options;
6864
private final boolean verboseFailures;
69-
@Nullable private final Reporter cmdlineReporter;
70-
private final Set<String> reportedErrors = new HashSet<>();
7165
private final RemoteExecutionService remoteExecutionService;
7266

7367
RemoteSpawnCache(
7468
Path execRoot,
7569
RemoteOptions options,
7670
boolean verboseFailures,
77-
@Nullable Reporter cmdlineReporter,
7871
RemoteExecutionService remoteExecutionService) {
7972
this.execRoot = execRoot;
8073
this.options = options;
8174
this.verboseFailures = verboseFailures;
82-
this.cmdlineReporter = cmdlineReporter;
8375
this.remoteExecutionService = remoteExecutionService;
8476
}
8577

@@ -150,13 +142,13 @@ public CacheHandle lookup(Spawn spawn, SpawnExecutionContext context)
150142
errorMessage = Utils.grpcAwareErrorMessage(e);
151143
} else {
152144
// On --verbose_failures print the whole stack trace
153-
errorMessage = Throwables.getStackTraceAsString(e);
145+
errorMessage = "\n" + Throwables.getStackTraceAsString(e);
154146
}
155147
if (isNullOrEmpty(errorMessage)) {
156148
errorMessage = e.getClass().getSimpleName();
157149
}
158-
errorMessage = "Reading from Remote Cache:\n" + errorMessage;
159-
report(Event.warn(errorMessage));
150+
errorMessage = "Remote Cache: " + errorMessage;
151+
remoteExecutionService.report(Event.warn(errorMessage));
160152
}
161153
}
162154
}
@@ -193,7 +185,7 @@ public void store(SpawnResult result) throws ExecException, InterruptedException
193185
try (SilentCloseable c = prof.profile("RemoteCache.checkForConcurrentModifications")) {
194186
checkForConcurrentModifications();
195187
} catch (IOException | ForbiddenActionInputException e) {
196-
report(Event.warn(e.getMessage()));
188+
remoteExecutionService.report(Event.warn(e.getMessage()));
197189
return;
198190
}
199191
}
@@ -223,20 +215,6 @@ private void checkForConcurrentModifications()
223215
}
224216
}
225217

226-
private void report(Event evt) {
227-
if (cmdlineReporter == null) {
228-
return;
229-
}
230-
231-
synchronized (this) {
232-
if (reportedErrors.contains(evt.getMessage())) {
233-
return;
234-
}
235-
reportedErrors.add(evt.getMessage());
236-
cmdlineReporter.handle(evt);
237-
}
238-
}
239-
240218
@Override
241219
public boolean usefulInDynamicExecution() {
242220
return false;

src/test/java/com/google/devtools/build/lib/remote/RemoteSpawnCacheTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ private RemoteSpawnCache remoteSpawnCacheWithOptions(RemoteOptions options) {
226226
null,
227227
ImmutableSet.of(),
228228
/* captureCorruptedOutputsDir= */ null));
229-
return new RemoteSpawnCache(execRoot, options, /* verboseFailures=*/ true, reporter, service);
229+
return new RemoteSpawnCache(execRoot, options, /* verboseFailures=*/ true, service);
230230
}
231231

232232
@Before

src/test/shell/bazel/remote/remote_execution_test.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -3266,14 +3266,14 @@ EOF
32663266

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

32713271
bazel test \
32723272
--remote_cache=grpc://localhost:${worker_port} \
32733273
--experimental_remote_cache_async \
32743274
--flaky_test_attempts=2 \
32753275
//a:test >& $TEST_log && fail "expected failure" || true
3276-
expect_not_log "WARNING: Writing to Remote Cache:"
3276+
expect_not_log "WARNING: Remote Cache:"
32773277
}
32783278

32793279
function test_download_toplevel_when_turn_remote_cache_off() {

0 commit comments

Comments
 (0)