Skip to content

Commit 17b8e44

Browse files
exosoncopybara-github
authored andcommitted
Upload all logs in BEP even with minimal upload
When using --experimental_remote_build_event_upload=minimal, build action logs won't get uploaded. These logs are still very useful as when a build action fails, one would need to inspect them to figure out what has gone wrong. Forcing uploading stdout and stderr with this change. Closes bazelbuild#17110. PiperOrigin-RevId: 500723770 Change-Id: I5e2edb6356b55549cd160379273af9a1580945d3
1 parent f7f8a34 commit 17b8e44

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

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

+6-3
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@
6363
class ByteStreamBuildEventArtifactUploader extends AbstractReferenceCounted
6464
implements BuildEventArtifactUploader {
6565
private static final Pattern TEST_LOG_PATTERN = Pattern.compile(".*/bazel-out/[^/]*/testlogs/.*");
66+
private static final Pattern BUILD_LOG_PATTERN =
67+
Pattern.compile(".*/bazel-out/_tmp/actions/std(err|out)-.*");
6668

6769
private final Executor executor;
6870
private final ExtendedEventHandler reporter;
@@ -216,14 +218,15 @@ private boolean shouldUpload(PathMetadata path) {
216218
path.getDigest() != null && !path.isRemote() && !path.isDirectory() && !path.isOmitted();
217219

218220
if (remoteBuildEventUploadMode == RemoteBuildEventUploadMode.MINIMAL) {
219-
result = result && (isTestLog(path) || isProfile(path));
221+
result = result && (isLog(path) || isProfile(path));
220222
}
221223

222224
return result;
223225
}
224226

225-
private boolean isTestLog(PathMetadata path) {
226-
return TEST_LOG_PATTERN.matcher(path.getPath().getPathString()).matches();
227+
private boolean isLog(PathMetadata path) {
228+
return TEST_LOG_PATTERN.matcher(path.getPath().getPathString()).matches()
229+
|| BUILD_LOG_PATTERN.matcher(path.getPath().getPathString()).matches();
227230
}
228231

229232
private boolean isProfile(PathMetadata path) {

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

+24-1
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,29 @@ EOF
269269
expect_log "command.profile.gz.*bytestream://" || fail "should upload profile data"
270270
}
271271

272+
function test_upload_minimal_upload_buildlogs() {
273+
mkdir -p a
274+
cat > a/BUILD <<EOF
275+
genrule(
276+
name = 'foo',
277+
outs = ['foo.txt'],
278+
cmd = 'echo "stdout" && echo "stderr" >&2 && exit 1',
279+
tags = ['no-remote'],
280+
)
281+
EOF
282+
283+
bazel build \
284+
--remote_executor=grpc://localhost:${worker_port} \
285+
--experimental_remote_build_event_upload=minimal \
286+
--build_event_json_file=bep.json \
287+
//a:foo >& $TEST_log || true
288+
289+
cat bep.json > $TEST_log
290+
expect_log "stdout.*bytestream://" || fail "should upload stdout"
291+
expect_log "stderr.*bytestream://" || fail "should upload stderr"
292+
expect_log "command.profile.gz.*bytestream://" || fail "should upload profile data"
293+
}
294+
272295
function test_upload_minimal_upload_profile() {
273296
mkdir -p a
274297
cat > a/BUILD <<EOF
@@ -290,4 +313,4 @@ EOF
290313
expect_log "mycommand.profile.gz.*bytestream://" || fail "should upload profile data"
291314
}
292315

293-
run_suite "Remote build event uploader tests"
316+
run_suite "Remote build event uploader tests"

0 commit comments

Comments
 (0)