From 71be4ea9e3d20bf90129e34a6a2899fe8401be36 Mon Sep 17 00:00:00 2001 From: Daniel Wagner-Hall Date: Thu, 15 Apr 2021 19:16:44 -0700 Subject: [PATCH] And mnemonic and label to remote metadata This reflects https://github.com/bazelbuild/remote-apis/pull/186 Closes #13109. PiperOrigin-RevId: 368763391 --- .../ByteStreamBuildEventArtifactUploader.java | 4 +-- .../lib/remote/RemoteActionInputFetcher.java | 2 +- .../RemoteRepositoryRemoteExecutor.java | 2 +- .../lib/remote/RemoteServerCapabilities.java | 2 +- .../build/lib/remote/RemoteSpawnCache.java | 2 +- .../build/lib/remote/RemoteSpawnRunner.java | 2 +- .../downloader/GrpcRemoteDownloader.java | 2 +- .../lib/remote/util/TracingMetadataUtils.java | 30 ++++++++++++------- .../lib/remote/ByteStreamUploaderTest.java | 6 ++-- .../build/lib/remote/GrpcCacheClientTest.java | 3 +- .../build/lib/remote/RemoteCacheTests.java | 3 +- .../downloader/GrpcRemoteDownloaderTest.java | 3 +- .../lib/remote/http/HttpCacheClientTest.java | 2 +- 13 files changed, 39 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/google/devtools/build/lib/remote/ByteStreamBuildEventArtifactUploader.java b/src/main/java/com/google/devtools/build/lib/remote/ByteStreamBuildEventArtifactUploader.java index c52d19989a28af..71e12f027613af 100644 --- a/src/main/java/com/google/devtools/build/lib/remote/ByteStreamBuildEventArtifactUploader.java +++ b/src/main/java/com/google/devtools/build/lib/remote/ByteStreamBuildEventArtifactUploader.java @@ -152,7 +152,7 @@ private static List processQueryResult( private ListenableFuture> queryRemoteCache( ImmutableList> allPaths) throws Exception { RequestMetadata metadata = - TracingMetadataUtils.buildMetadata(buildRequestId, commandId, "bes-upload"); + TracingMetadataUtils.buildMetadata(buildRequestId, commandId, "bes-upload", null); RemoteActionExecutionContext context = RemoteActionExecutionContext.create(metadata); List knownRemotePaths = new ArrayList<>(allPaths.size()); @@ -188,7 +188,7 @@ private ListenableFuture> queryRemoteCache( private ListenableFuture> uploadLocalFiles( ImmutableIterable allPaths) { RequestMetadata metadata = - TracingMetadataUtils.buildMetadata(buildRequestId, commandId, "bes-upload"); + TracingMetadataUtils.buildMetadata(buildRequestId, commandId, "bes-upload", null); RemoteActionExecutionContext context = RemoteActionExecutionContext.create(metadata); ImmutableList.Builder> allPathsUploaded = diff --git a/src/main/java/com/google/devtools/build/lib/remote/RemoteActionInputFetcher.java b/src/main/java/com/google/devtools/build/lib/remote/RemoteActionInputFetcher.java index f726e85d2b4d55..6817e924432ba5 100644 --- a/src/main/java/com/google/devtools/build/lib/remote/RemoteActionInputFetcher.java +++ b/src/main/java/com/google/devtools/build/lib/remote/RemoteActionInputFetcher.java @@ -154,7 +154,7 @@ private Completable downloadFileAsync(Path path, FileArtifactValue metadata) { () -> { RequestMetadata requestMetadata = TracingMetadataUtils.buildMetadata( - buildRequestId, commandId, metadata.getActionId()); + buildRequestId, commandId, metadata.getActionId(), null); RemoteActionExecutionContext context = RemoteActionExecutionContext.create(requestMetadata); diff --git a/src/main/java/com/google/devtools/build/lib/remote/RemoteRepositoryRemoteExecutor.java b/src/main/java/com/google/devtools/build/lib/remote/RemoteRepositoryRemoteExecutor.java index ba8331f612aff6..54e200b6de7f80 100644 --- a/src/main/java/com/google/devtools/build/lib/remote/RemoteRepositoryRemoteExecutor.java +++ b/src/main/java/com/google/devtools/build/lib/remote/RemoteRepositoryRemoteExecutor.java @@ -106,7 +106,7 @@ public ExecutionResult execute( Duration timeout) throws IOException, InterruptedException { RequestMetadata metadata = - TracingMetadataUtils.buildMetadata(buildRequestId, commandId, "repository_rule"); + TracingMetadataUtils.buildMetadata(buildRequestId, commandId, "repository_rule", null); RemoteActionExecutionContext context = RemoteActionExecutionContext.create(metadata); Platform platform = PlatformUtils.buildPlatformProto(executionProperties); diff --git a/src/main/java/com/google/devtools/build/lib/remote/RemoteServerCapabilities.java b/src/main/java/com/google/devtools/build/lib/remote/RemoteServerCapabilities.java index 2cc9d813b99c54..8e99ec7dc91c28 100644 --- a/src/main/java/com/google/devtools/build/lib/remote/RemoteServerCapabilities.java +++ b/src/main/java/com/google/devtools/build/lib/remote/RemoteServerCapabilities.java @@ -69,7 +69,7 @@ private CapabilitiesBlockingStub capabilitiesBlockingStub(RemoteActionExecutionC public ServerCapabilities get(String buildRequestId, String commandId) throws IOException, InterruptedException { RequestMetadata metadata = - TracingMetadataUtils.buildMetadata(buildRequestId, commandId, "capabilities"); + TracingMetadataUtils.buildMetadata(buildRequestId, commandId, "capabilities", null); RemoteActionExecutionContext context = RemoteActionExecutionContext.create(metadata); try { GetCapabilitiesRequest request = diff --git a/src/main/java/com/google/devtools/build/lib/remote/RemoteSpawnCache.java b/src/main/java/com/google/devtools/build/lib/remote/RemoteSpawnCache.java index 00581e34a583f3..15273c27f84c65 100644 --- a/src/main/java/com/google/devtools/build/lib/remote/RemoteSpawnCache.java +++ b/src/main/java/com/google/devtools/build/lib/remote/RemoteSpawnCache.java @@ -153,7 +153,7 @@ public CacheHandle lookup(Spawn spawn, SpawnExecutionContext context) RequestMetadata metadata = TracingMetadataUtils.buildMetadata( - buildRequestId, commandId, actionKey.getDigest().getHash()); + buildRequestId, commandId, actionKey.getDigest().getHash(), spawn.getResourceOwner()); RemoteActionExecutionContext remoteActionExecutionContext = RemoteActionExecutionContext.create(metadata); diff --git a/src/main/java/com/google/devtools/build/lib/remote/RemoteSpawnRunner.java b/src/main/java/com/google/devtools/build/lib/remote/RemoteSpawnRunner.java index e1976b6f8a9a0b..c893c8fabbf949 100644 --- a/src/main/java/com/google/devtools/build/lib/remote/RemoteSpawnRunner.java +++ b/src/main/java/com/google/devtools/build/lib/remote/RemoteSpawnRunner.java @@ -250,7 +250,7 @@ public SpawnResult exec(Spawn spawn, SpawnExecutionContext context) RequestMetadata metadata = TracingMetadataUtils.buildMetadata( - buildRequestId, commandId, actionKey.getDigest().getHash()); + buildRequestId, commandId, actionKey.getDigest().getHash(), spawn.getResourceOwner()); RemoteActionExecutionContext remoteActionExecutionContext = RemoteActionExecutionContext.create(metadata); Profiler prof = Profiler.instance(); diff --git a/src/main/java/com/google/devtools/build/lib/remote/downloader/GrpcRemoteDownloader.java b/src/main/java/com/google/devtools/build/lib/remote/downloader/GrpcRemoteDownloader.java index 71b22c7782e3c6..a0bc56b0b12d6e 100644 --- a/src/main/java/com/google/devtools/build/lib/remote/downloader/GrpcRemoteDownloader.java +++ b/src/main/java/com/google/devtools/build/lib/remote/downloader/GrpcRemoteDownloader.java @@ -114,7 +114,7 @@ public void download( com.google.common.base.Optional type) throws IOException, InterruptedException { RequestMetadata metadata = - TracingMetadataUtils.buildMetadata(buildRequestId, commandId, "remote_downloader"); + TracingMetadataUtils.buildMetadata(buildRequestId, commandId, "remote_downloader", null); RemoteActionExecutionContext remoteActionExecutionContext = RemoteActionExecutionContext.create(metadata); diff --git a/src/main/java/com/google/devtools/build/lib/remote/util/TracingMetadataUtils.java b/src/main/java/com/google/devtools/build/lib/remote/util/TracingMetadataUtils.java index 93cf8a36a5ff9d..557973832636f3 100644 --- a/src/main/java/com/google/devtools/build/lib/remote/util/TracingMetadataUtils.java +++ b/src/main/java/com/google/devtools/build/lib/remote/util/TracingMetadataUtils.java @@ -17,6 +17,7 @@ import build.bazel.remote.execution.v2.ToolDetails; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Preconditions; +import com.google.devtools.build.lib.actions.ActionExecutionMetadata; import com.google.devtools.build.lib.analysis.BlazeVersionInfo; import com.google.devtools.build.lib.remote.options.RemoteOptions; import io.grpc.ClientInterceptor; @@ -46,19 +47,28 @@ private TracingMetadataUtils() {} ProtoUtils.keyForProto(RequestMetadata.getDefaultInstance()); public static RequestMetadata buildMetadata( - String buildRequestId, String commandId, String actionId) { + String buildRequestId, + String commandId, + String actionId, + @Nullable ActionExecutionMetadata actionMetadata) { Preconditions.checkNotNull(buildRequestId); Preconditions.checkNotNull(commandId); Preconditions.checkNotNull(actionId); - return RequestMetadata.newBuilder() - .setCorrelatedInvocationsId(buildRequestId) - .setToolInvocationId(commandId) - .setActionId(actionId) - .setToolDetails( - ToolDetails.newBuilder() - .setToolName("bazel") - .setToolVersion(BlazeVersionInfo.instance().getVersion())) - .build(); + RequestMetadata.Builder builder = + RequestMetadata.newBuilder() + .setCorrelatedInvocationsId(buildRequestId) + .setToolInvocationId(commandId) + .setActionId(actionId) + .setToolDetails( + ToolDetails.newBuilder() + .setToolName("bazel") + .setToolVersion(BlazeVersionInfo.instance().getVersion())); + if (actionMetadata != null) { + builder.setActionMnemonic(actionMetadata.getMnemonic()); + builder.setTargetId(actionMetadata.getOwner().getLabel().getCanonicalForm()); + builder.setConfigurationId(actionMetadata.getOwner().getConfigurationChecksum()); + } + return builder.build(); } /** diff --git a/src/test/java/com/google/devtools/build/lib/remote/ByteStreamUploaderTest.java b/src/test/java/com/google/devtools/build/lib/remote/ByteStreamUploaderTest.java index 9cd30be310e126..604e87c42aa46c 100644 --- a/src/test/java/com/google/devtools/build/lib/remote/ByteStreamUploaderTest.java +++ b/src/test/java/com/google/devtools/build/lib/remote/ByteStreamUploaderTest.java @@ -132,7 +132,8 @@ public int maxConcurrency() { TracingMetadataUtils.buildMetadata( "none", "none", - DIGEST_UTIL.asActionKey(Digest.getDefaultInstance()).getDigest().getHash()); + DIGEST_UTIL.asActionKey(Digest.getDefaultInstance()).getDigest().getHash(), + null); context = RemoteActionExecutionContext.create(metadata); retryService = MoreExecutors.listeningDecorator(Executors.newScheduledThreadPool(1)); @@ -679,7 +680,8 @@ public void queryWriteStatus( TracingMetadataUtils.buildMetadata( "build-req-id", "command-id", - DIGEST_UTIL.asActionKey(actionDigest).getDigest().getHash()); + DIGEST_UTIL.asActionKey(actionDigest).getDigest().getHash(), + null); RemoteActionExecutionContext remoteActionExecutionContext = RemoteActionExecutionContext.create(metadata); uploads.add( diff --git a/src/test/java/com/google/devtools/build/lib/remote/GrpcCacheClientTest.java b/src/test/java/com/google/devtools/build/lib/remote/GrpcCacheClientTest.java index 8ac9c31bdff46c..88586f56dee070 100644 --- a/src/test/java/com/google/devtools/build/lib/remote/GrpcCacheClientTest.java +++ b/src/test/java/com/google/devtools/build/lib/remote/GrpcCacheClientTest.java @@ -156,7 +156,8 @@ public final void setUp() throws Exception { FileSystemUtils.createDirectoryAndParents(stderr.getParentDirectory()); outErr = new FileOutErr(stdout, stderr); RequestMetadata metadata = - TracingMetadataUtils.buildMetadata("none", "none", Digest.getDefaultInstance().getHash()); + TracingMetadataUtils.buildMetadata( + "none", "none", Digest.getDefaultInstance().getHash(), null); context = RemoteActionExecutionContext.create(metadata); retryService = MoreExecutors.listeningDecorator(Executors.newScheduledThreadPool(1)); } diff --git a/src/test/java/com/google/devtools/build/lib/remote/RemoteCacheTests.java b/src/test/java/com/google/devtools/build/lib/remote/RemoteCacheTests.java index 38cbfd93e2a73f..7cb6b91bce0cbc 100644 --- a/src/test/java/com/google/devtools/build/lib/remote/RemoteCacheTests.java +++ b/src/test/java/com/google/devtools/build/lib/remote/RemoteCacheTests.java @@ -114,7 +114,8 @@ public class RemoteCacheTests { public void setUp() throws Exception { MockitoAnnotations.initMocks(this); RequestMetadata metadata = - TracingMetadataUtils.buildMetadata("none", "none", Digest.getDefaultInstance().getHash()); + TracingMetadataUtils.buildMetadata( + "none", "none", Digest.getDefaultInstance().getHash(), null); context = RemoteActionExecutionContext.create(metadata); fs = new InMemoryFileSystem(new JavaClock(), DigestHashFunction.SHA256); execRoot = fs.getPath("/execroot"); diff --git a/src/test/java/com/google/devtools/build/lib/remote/downloader/GrpcRemoteDownloaderTest.java b/src/test/java/com/google/devtools/build/lib/remote/downloader/GrpcRemoteDownloaderTest.java index 980f6187105f55..f8a24ff79ec90d 100644 --- a/src/test/java/com/google/devtools/build/lib/remote/downloader/GrpcRemoteDownloaderTest.java +++ b/src/test/java/com/google/devtools/build/lib/remote/downloader/GrpcRemoteDownloaderTest.java @@ -99,7 +99,8 @@ public final void setUp() throws Exception { TracingMetadataUtils.buildMetadata( "none", "none", - DIGEST_UTIL.asActionKey(Digest.getDefaultInstance()).getDigest().getHash()); + DIGEST_UTIL.asActionKey(Digest.getDefaultInstance()).getDigest().getHash(), + null); context = RemoteActionExecutionContext.create(metadata); retryService = MoreExecutors.listeningDecorator(Executors.newScheduledThreadPool(1)); diff --git a/src/test/java/com/google/devtools/build/lib/remote/http/HttpCacheClientTest.java b/src/test/java/com/google/devtools/build/lib/remote/http/HttpCacheClientTest.java index 5ef61527910e81..bcf5ce984bf954 100644 --- a/src/test/java/com/google/devtools/build/lib/remote/http/HttpCacheClientTest.java +++ b/src/test/java/com/google/devtools/build/lib/remote/http/HttpCacheClientTest.java @@ -301,7 +301,7 @@ public void setUp() throws Exception { remoteActionExecutionContext = RemoteActionExecutionContext.create( TracingMetadataUtils.buildMetadata( - "none", "none", Digest.getDefaultInstance().getHash())); + "none", "none", Digest.getDefaultInstance().getHash(), null)); } @Test