From 642a9061ce7e6fbb87cf2c00b70048cae8c8beb5 Mon Sep 17 00:00:00 2001 From: Daniel Wagner-Hall Date: Mon, 8 Feb 2021 15:06:44 +0000 Subject: [PATCH] And mnemonic and label to remote metadata This reflects https://github.com/bazelbuild/remote-apis/pull/186 --- .../ByteStreamBuildEventArtifactUploader.java | 4 ++-- .../lib/remote/RemoteActionInputFetcher.java | 2 +- .../remote/RemoteRepositoryRemoteExecutor.java | 2 +- .../lib/remote/RemoteServerCapabilities.java | 2 +- .../build/lib/remote/RemoteSpawnCache.java | 2 +- .../build/lib/remote/RemoteSpawnRunner.java | 2 +- .../remote/downloader/GrpcRemoteDownloader.java | 2 +- .../google/devtools/build/lib/remote/util/BUILD | 1 + .../lib/remote/util/TracingMetadataUtils.java | 15 +++++++++++---- .../build/lib/remote/ByteStreamUploaderTest.java | 6 ++++-- .../build/lib/remote/GrpcCacheClientTest.java | 2 +- .../build/lib/remote/RemoteCacheTests.java | 2 +- .../downloader/GrpcRemoteDownloaderTest.java | 3 ++- .../lib/remote/http/HttpCacheClientTest.java | 2 +- 14 files changed, 29 insertions(+), 18 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 29f89d47cff5fd..488105b91e1a88 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 @@ -154,7 +154,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 00fd0fb30c1a04..92027b8410e5ff 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 @@ -257,7 +257,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/BUILD b/src/main/java/com/google/devtools/build/lib/remote/util/BUILD index 22134fa44a79eb..9afc158cfbad38 100644 --- a/src/main/java/com/google/devtools/build/lib/remote/util/BUILD +++ b/src/main/java/com/google/devtools/build/lib/remote/util/BUILD @@ -19,6 +19,7 @@ java_library( "//src/main/java/com/google/devtools/build/lib/actions:execution_requirements", "//src/main/java/com/google/devtools/build/lib/analysis:blaze_version_info", "//src/main/java/com/google/devtools/build/lib/authandtls", + "//src/main/java/com/google/devtools/build/lib/cmdline", "//src/main/java/com/google/devtools/build/lib/remote:ExecutionStatusException", "//src/main/java/com/google/devtools/build/lib/remote/common", "//src/main/java/com/google/devtools/build/lib/remote/options", 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..fe0f2fb60d10ad 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,7 +17,9 @@ 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.cmdline.Label; import com.google.devtools.build.lib.remote.options.RemoteOptions; import io.grpc.ClientInterceptor; import io.grpc.Context; @@ -46,19 +48,24 @@ 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() + RequestMetadata.Builder builder = RequestMetadata.newBuilder() .setCorrelatedInvocationsId(buildRequestId) .setToolInvocationId(commandId) .setActionId(actionId) .setToolDetails( ToolDetails.newBuilder() .setToolName("bazel") - .setToolVersion(BlazeVersionInfo.instance().getVersion())) - .build(); + .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 d775c8bdde3f55..9f66a839f16ceb 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,7 @@ 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 9a3ba38864d3db..83be015bef82d5 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 @@ -115,7 +115,7 @@ 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/main"); 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 abd53e95ece91d..699076407647c2 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