Skip to content

Commit

Permalink
Include invocation ID in compact execution log
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 bazelbuild#24790.

PiperOrigin-RevId: 715017597
Change-Id: Ia8f6a3677a165a9f428b59ab8a19587a357b8803
  • Loading branch information
fmeum authored and copybara-github committed Jan 13, 2025
1 parent ccdffd2 commit fd6a983
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 @@ -63,6 +63,7 @@
import java.util.Comparator;
import java.util.List;
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 @@ -143,6 +144,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 @@ -166,14 +168,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 @@ -194,7 +198,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 @@ -47,6 +47,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 @@ -144,7 +145,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 @@ -244,7 +246,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 fd6a983

Please sign in to comment.