Skip to content

Commit

Permalink
Upload all logs in BEP even with minimal upload (#17299)
Browse files Browse the repository at this point in the history
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 #17110.

PiperOrigin-RevId: 500723770
Change-Id: I5e2edb6356b55549cd160379273af9a1580945d3

Co-authored-by: Emil Kattainen <emilkattainen@gmail.com>
  • Loading branch information
ShreeM01 and exoson authored Jan 24, 2023
1 parent b0726cb commit 950e755
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
class ByteStreamBuildEventArtifactUploader extends AbstractReferenceCounted
implements BuildEventArtifactUploader {
private static final Pattern TEST_LOG_PATTERN = Pattern.compile(".*/bazel-out/[^/]*/testlogs/.*");
private static final Pattern BUILD_LOG_PATTERN =
Pattern.compile(".*/bazel-out/_tmp/actions/std(err|out)-.*");

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

if (remoteBuildEventUploadMode == RemoteBuildEventUploadMode.MINIMAL) {
result = result && (isTestLog(path) || isProfile(path));
result = result && (isLog(path) || isProfile(path));
}

return result;
}

private boolean isTestLog(PathMetadata path) {
return TEST_LOG_PATTERN.matcher(path.getPath().getPathString()).matches();
private boolean isLog(PathMetadata path) {
return TEST_LOG_PATTERN.matcher(path.getPath().getPathString()).matches()
|| BUILD_LOG_PATTERN.matcher(path.getPath().getPathString()).matches();
}

private boolean isProfile(PathMetadata path) {
Expand Down
25 changes: 24 additions & 1 deletion src/test/shell/bazel/remote/remote_build_event_uploader_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,29 @@ EOF
expect_log "command.profile.gz.*bytestream://" || fail "should upload profile data"
}

function test_upload_minimal_upload_buildlogs() {
mkdir -p a
cat > a/BUILD <<EOF
genrule(
name = 'foo',
outs = ['foo.txt'],
cmd = 'echo "stdout" && echo "stderr" >&2 && exit 1',
tags = ['no-remote'],
)
EOF

bazel build \
--remote_executor=grpc://localhost:${worker_port} \
--experimental_remote_build_event_upload=minimal \
--build_event_json_file=bep.json \
//a:foo >& $TEST_log || true

cat bep.json > $TEST_log
expect_log "stdout.*bytestream://" || fail "should upload stdout"
expect_log "stderr.*bytestream://" || fail "should upload stderr"
expect_log "command.profile.gz.*bytestream://" || fail "should upload profile data"
}

function test_upload_minimal_upload_profile() {
mkdir -p a
cat > a/BUILD <<EOF
Expand All @@ -290,4 +313,4 @@ EOF
expect_log "mycommand.profile.gz.*bytestream://" || fail "should upload profile data"
}

run_suite "Remote build event uploader tests"
run_suite "Remote build event uploader tests"

0 comments on commit 950e755

Please sign in to comment.