Skip to content

Commit ad17b44

Browse files
exosonckolli5
andauthored
Print remote execution message when the action times out (bazelbuild#15772)
Closes bazelbuild#15710. PiperOrigin-RevId: 456227285 Change-Id: I7d938bde6482151d96cb7cfe65242e659a6fb4a2 Co-authored-by: Chenchu K <[email protected]>
1 parent aedca1d commit ad17b44

File tree

2 files changed

+49
-7
lines changed

2 files changed

+49
-7
lines changed

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

+16-7
Original file line numberDiff line numberDiff line change
@@ -272,11 +272,7 @@ public SpawnResult exec(Spawn spawn, SpawnExecutionContext context)
272272
// It's already late at this stage, but we should at least report once.
273273
reporter.reportExecutingIfNot();
274274

275-
FileOutErr outErr = context.getFileOutErr();
276-
String message = result.getMessage();
277-
if (!result.success() && !message.isEmpty()) {
278-
outErr.printErr(message + "\n");
279-
}
275+
maybePrintExecutionMessages(context, result.getMessage(), result.success());
280276

281277
profileAccounting(result.getExecutionMetadata());
282278
spawnMetricsAccounting(spawnMetrics, result.getExecutionMetadata());
@@ -444,6 +440,17 @@ public boolean handlesCaching() {
444440
return true;
445441
}
446442

443+
private void maybePrintExecutionMessages(
444+
SpawnExecutionContext context, String message, boolean success) {
445+
FileOutErr outErr = context.getFileOutErr();
446+
boolean printMessage =
447+
remoteOptions.remotePrintExecutionMessages.shouldPrintMessages(success)
448+
&& !message.isEmpty();
449+
if (printMessage) {
450+
outErr.printErr(message + "\n");
451+
}
452+
}
453+
447454
private void maybeWriteParamFilesLocally(Spawn spawn) throws IOException {
448455
if (!executionOptions.shouldMaterializeParamFiles()) {
449456
return;
@@ -500,10 +507,11 @@ private SpawnResult execLocallyAndUploadOrFail(
500507
if (remoteOptions.remoteLocalFallback && !RemoteRetrierUtils.causedByExecTimeout(cause)) {
501508
return execLocallyAndUpload(action, spawn, context, uploadLocalResults);
502509
}
503-
return handleError(action, cause);
510+
return handleError(action, cause, context);
504511
}
505512

506-
private SpawnResult handleError(RemoteAction action, IOException exception)
513+
private SpawnResult handleError(
514+
RemoteAction action, IOException exception, SpawnExecutionContext context)
507515
throws ExecException, InterruptedException, IOException {
508516
boolean remoteCacheFailed =
509517
BulkTransferException.isOnlyCausedByCacheNotFoundException(exception);
@@ -522,6 +530,7 @@ private SpawnResult handleError(RemoteAction action, IOException exception)
522530
}
523531
}
524532
if (e.isExecutionTimeout()) {
533+
maybePrintExecutionMessages(context, e.getResponse().getMessage(), /* success = */ false);
525534
return new SpawnResult.Builder()
526535
.setRunnerName(getName())
527536
.setStatus(Status.TIMEOUT)

src/main/java/com/google/devtools/build/lib/remote/options/RemoteOptions.java

+33
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,19 @@ public RemoteOutputsStrategyConverter() {
566566
+ "that loads objects from the CAS on demand.")
567567
public String remoteDownloadSymlinkTemplate;
568568

569+
@Option(
570+
name = "remote_print_execution_messages",
571+
defaultValue = "failure",
572+
converter = ExecutionMessagePrintMode.Converter.class,
573+
category = "remote",
574+
documentationCategory = OptionDocumentationCategory.LOGGING,
575+
effectTags = {OptionEffectTag.TERMINAL_OUTPUT},
576+
help =
577+
"Choose when to print remote execution messages. Valid values are `failure`, "
578+
+ "to print only on failures, `success` to print only on successes and "
579+
+ "`all` to print always.")
580+
public ExecutionMessagePrintMode remotePrintExecutionMessages;
581+
569582
// The below options are not configurable by users, only tests.
570583
// This is part of the effort to reduce the overall number of flags.
571584

@@ -635,4 +648,24 @@ private static FailureDetail createFailureDetail(String message, Code detailedCo
635648
.setRemoteExecution(RemoteExecution.newBuilder().setCode(detailedCode))
636649
.build();
637650
}
651+
652+
/** An enum for specifying different modes for printing remote execution messages. */
653+
public enum ExecutionMessagePrintMode {
654+
FAILURE, // Print execution messages only on failure
655+
SUCCESS, // Print execution messages only on success
656+
ALL; // Print execution messages always
657+
658+
/** Converts to {@link ExecutionMessagePrintMode}. */
659+
public static class Converter extends EnumConverter<ExecutionMessagePrintMode> {
660+
public Converter() {
661+
super(ExecutionMessagePrintMode.class, "execution message print mode");
662+
}
663+
}
664+
665+
public boolean shouldPrintMessages(boolean success) {
666+
return ((!success && this == ExecutionMessagePrintMode.FAILURE)
667+
|| (success && this == ExecutionMessagePrintMode.SUCCESS)
668+
|| this == ExecutionMessagePrintMode.ALL);
669+
}
670+
}
638671
}

0 commit comments

Comments
 (0)