Skip to content

Commit

Permalink
[7.5.0] Include invocation ID in compact execution log (#24915)
Browse files Browse the repository at this point in the history
This makes it possible to retroactively link an execution log file to a
particular build.

Closes #24790.

PiperOrigin-RevId: 715017597
Change-Id: Ia8f6a3677a165a9f428b59ab8a19587a357b8803

Commit
fd6a983

Co-authored-by: Fabian Meumertzheim <[email protected]>
  • Loading branch information
bazel-io and fmeum authored Jan 15, 2025
1 parent c427e34 commit 38dbf04
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ private void initOutputs(CommandEnvironment env) throws IOException {
.experimentalSiblingRepositoryLayout,
env.getOptions().getOptions(RemoteOptions.class),
env.getRuntime().getFileSystem().getDigestFunction(),
env.getXattrProvider());
env.getXattrProvider(),
env.getCommandId());
} catch (InterruptedException e) {
env.getReporter()
.handle(Event.error("Error while setting up the execution log: " + e.getMessage()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
import java.util.List;
import java.util.Map;
import java.util.SortedMap;
import java.util.UUID;
import java.util.concurrent.ForkJoinPool;
import javax.annotation.Nullable;
import javax.annotation.concurrent.GuardedBy;
Expand Down Expand Up @@ -145,6 +146,7 @@ private interface ExecLogEntrySupplier {
@Nullable private final RemoteOptions remoteOptions;
private final DigestHashFunction digestHashFunction;
private final XattrProvider xattrProvider;
private final UUID invocationId;

// Maps a key identifying an entry into its ID.
// Each key is either a NestedSet.Node or the String path of a file, directory, symlink or
Expand All @@ -168,14 +170,16 @@ public CompactSpawnLogContext(
boolean siblingRepositoryLayout,
@Nullable RemoteOptions remoteOptions,
DigestHashFunction digestHashFunction,
XattrProvider xattrProvider)
XattrProvider xattrProvider,
UUID invocationId)
throws IOException, InterruptedException {
this.execRoot = execRoot;
this.workspaceName = workspaceName;
this.siblingRepositoryLayout = siblingRepositoryLayout;
this.remoteOptions = remoteOptions;
this.digestHashFunction = digestHashFunction;
this.xattrProvider = xattrProvider;
this.invocationId = invocationId;
this.outputStream = getOutputStream(outputPath);

logInvocation();
Expand All @@ -196,7 +200,8 @@ private void logInvocation() throws IOException, InterruptedException {
ExecLogEntry.Invocation.newBuilder()
.setHashFunctionName(digestHashFunction.toString())
.setWorkspaceRunfilesDirectory(workspaceName)
.setSiblingRepositoryLayout(siblingRepositoryLayout)));
.setSiblingRepositoryLayout(siblingRepositoryLayout)
.setId(invocationId.toString())));
}

@Override
Expand Down
3 changes: 3 additions & 0 deletions src/main/protobuf/spawn.proto
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,9 @@ message ExecLogEntry {

// Whether --experimental_sibling_repository_layout is enabled.
bool sibling_repository_layout = 3;

// The ID of the invocation.
string id = 4;
}

// An input or output file.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.UUID;
import net.starlark.java.syntax.Location;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -155,7 +156,8 @@ public void testSymlinkAction() throws IOException, InterruptedException {
Protos.ExecLogEntry.Invocation.newBuilder()
.setHashFunctionName("SHA-256")
.setWorkspaceRunfilesDirectory(TestConstants.WORKSPACE_NAME)
.setSiblingRepositoryLayout(siblingRepositoryLayout))
.setSiblingRepositoryLayout(siblingRepositoryLayout)
.setId("00000000-0000-0000-0000-000000000000"))
.build(),
Protos.ExecLogEntry.newBuilder()
.setSymlinkAction(
Expand Down Expand Up @@ -265,7 +267,8 @@ protected SpawnLogContext createSpawnLogContext(ImmutableMap<String, String> pla
siblingRepositoryLayout,
remoteOptions,
DigestHashFunction.SHA256,
SyscallCache.NO_CACHE);
SyscallCache.NO_CACHE,
UUID.fromString("00000000-0000-0000-0000-000000000000"));
}

@Override
Expand Down

0 comments on commit 38dbf04

Please sign in to comment.