From 92955e617b5c41713a5163dc0437c2a024b31815 Mon Sep 17 00:00:00 2001 From: Googler Date: Wed, 27 Jan 2021 20:42:16 -0800 Subject: [PATCH] Remote: Use parameters instead of thread-local storage to provide tracing metadata. (Part 2) Change RemoteCacheClient#uploadActionResult to use RemoteActionExecutionContext. PiperOrigin-RevId: 354233348 --- .../build/lib/remote/GrpcCacheClient.java | 11 ++++-- .../build/lib/remote/RemoteCache.java | 7 +++- .../build/lib/remote/RemoteSpawnCache.java | 8 +++- .../build/lib/remote/RemoteSpawnRunner.java | 39 +++++++++++++++++-- .../lib/remote/common/RemoteCacheClient.java | 3 +- .../remote/disk/DiskAndRemoteCacheClient.java | 9 +++-- .../lib/remote/disk/DiskCacheClient.java | 3 +- .../lib/remote/http/HttpCacheClient.java | 3 +- .../build/lib/remote/GrpcCacheClientTest.java | 6 ++- .../build/lib/remote/RemoteCacheTests.java | 13 +++++++ .../lib/remote/RemoteSpawnCacheTest.java | 10 +++++ .../lib/remote/RemoteSpawnRunnerTest.java | 37 ++++++++++++++---- .../lib/remote/util/InMemoryCacheClient.java | 3 +- .../remote/worker/ActionCacheServer.java | 6 ++- .../build/remote/worker/ExecutionServer.java | 13 +++++-- .../remote/worker/OnDiskBlobStoreCache.java | 6 ++- 16 files changed, 143 insertions(+), 34 deletions(-) diff --git a/src/main/java/com/google/devtools/build/lib/remote/GrpcCacheClient.java b/src/main/java/com/google/devtools/build/lib/remote/GrpcCacheClient.java index a88ab82c20f8ed..85da6b014aadce 100644 --- a/src/main/java/com/google/devtools/build/lib/remote/GrpcCacheClient.java +++ b/src/main/java/com/google/devtools/build/lib/remote/GrpcCacheClient.java @@ -136,9 +136,11 @@ private ByteStreamStub bsAsyncStub() { .withDeadlineAfter(options.remoteTimeout.getSeconds(), TimeUnit.SECONDS); } - private ActionCacheBlockingStub acBlockingStub() { + private ActionCacheBlockingStub acBlockingStub(RemoteActionExecutionContext context) { return ActionCacheGrpc.newBlockingStub(channel) - .withInterceptors(TracingMetadataUtils.attachMetadataFromContextInterceptor()) + .withInterceptors( + TracingMetadataUtils.attachMetadataInterceptor(context.getRequestMetadata()), + new NetworkTimeInterceptor(context::getNetworkTime)) .withCallCredentials(callCredentialsProvider.getCallCredentials()) .withDeadlineAfter(options.remoteTimeout.getSeconds(), TimeUnit.SECONDS); } @@ -259,14 +261,15 @@ public ListenableFuture downloadActionResult( } @Override - public void uploadActionResult(ActionKey actionKey, ActionResult actionResult) + public void uploadActionResult( + RemoteActionExecutionContext context, ActionKey actionKey, ActionResult actionResult) throws IOException, InterruptedException { try { Utils.refreshIfUnauthenticated( () -> retrier.execute( () -> - acBlockingStub() + acBlockingStub(context) .updateActionResult( UpdateActionResultRequest.newBuilder() .setInstanceName(options.remoteInstanceName) diff --git a/src/main/java/com/google/devtools/build/lib/remote/RemoteCache.java b/src/main/java/com/google/devtools/build/lib/remote/RemoteCache.java index 59138b5a3c1c79..8e68aaba540cb1 100644 --- a/src/main/java/com/google/devtools/build/lib/remote/RemoteCache.java +++ b/src/main/java/com/google/devtools/build/lib/remote/RemoteCache.java @@ -129,6 +129,7 @@ public ActionResult downloadActionResult( * @throws ExecException if uploading any of the action outputs is not supported */ public ActionResult upload( + RemoteActionExecutionContext context, ActionKey actionKey, Action action, Command command, @@ -142,12 +143,13 @@ public ActionResult upload( resultBuilder.setExitCode(exitCode); ActionResult result = resultBuilder.build(); if (exitCode == 0 && !action.getDoNotCache()) { - cacheProtocol.uploadActionResult(actionKey, result); + cacheProtocol.uploadActionResult(context, actionKey, result); } return result; } public ActionResult upload( + RemoteActionExecutionContext context, ActionKey actionKey, Action action, Command command, @@ -155,7 +157,8 @@ public ActionResult upload( Collection outputs, FileOutErr outErr) throws ExecException, IOException, InterruptedException { - return upload(actionKey, action, command, execRoot, outputs, outErr, /* exitCode= */ 0); + return upload( + context, actionKey, action, command, execRoot, outputs, outErr, /* exitCode= */ 0); } private void uploadOutputs( 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 5bdda3e57d8008..a7bc727238bd35 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 @@ -291,7 +291,13 @@ public void store(SpawnResult result) throws ExecException, InterruptedException RemoteSpawnRunner.resolveActionInputs(execRoot, spawn.getOutputFiles()); try (SilentCloseable c = prof.profile(ProfilerTask.UPLOAD_TIME, "upload outputs")) { remoteCache.upload( - actionKey, action, command, execRoot, files, context.getFileOutErr()); + remoteActionExecutionContext, + actionKey, + action, + command, + execRoot, + files, + context.getFileOutErr()); } catch (IOException e) { String errorMessage; if (!verboseFailures) { 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 c72d9c05cf7c33..fdce7c5dfb90e1 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 @@ -298,7 +298,15 @@ public SpawnResult exec(Spawn spawn, SpawnExecutionContext context) } } catch (IOException e) { return execLocallyAndUploadOrFail( - spawn, context, inputMap, actionKey, action, command, uploadLocalResults, e); + remoteActionExecutionContext, + spawn, + context, + inputMap, + actionKey, + action, + command, + uploadLocalResults, + e); } ExecuteRequest.Builder requestBuilder = @@ -383,7 +391,15 @@ public SpawnResult exec(Spawn spawn, SpawnExecutionContext context) }); } catch (IOException e) { return execLocallyAndUploadOrFail( - spawn, context, inputMap, actionKey, action, command, uploadLocalResults, e); + remoteActionExecutionContext, + spawn, + context, + inputMap, + actionKey, + action, + command, + uploadLocalResults, + e); } } finally { withMetadata.detach(previous); @@ -556,6 +572,7 @@ private SpawnResult execLocally(Spawn spawn, SpawnExecutionContext context) } private SpawnResult execLocallyAndUploadOrFail( + RemoteActionExecutionContext remoteActionExecutionContext, Spawn spawn, SpawnExecutionContext context, SortedMap inputMap, @@ -572,7 +589,14 @@ private SpawnResult execLocallyAndUploadOrFail( } if (remoteOptions.remoteLocalFallback && !RemoteRetrierUtils.causedByExecTimeout(cause)) { return execLocallyAndUpload( - spawn, context, inputMap, actionKey, action, command, uploadLocalResults); + remoteActionExecutionContext, + spawn, + context, + inputMap, + actionKey, + action, + command, + uploadLocalResults); } return handleError(cause, context.getFileOutErr(), actionKey, context); } @@ -724,6 +748,7 @@ private Map getInputCtimes(SortedMap inpu @VisibleForTesting SpawnResult execLocallyAndUpload( + RemoteActionExecutionContext remoteActionExecutionContext, Spawn spawn, SpawnExecutionContext context, SortedMap inputMap, @@ -751,7 +776,13 @@ SpawnResult execLocallyAndUpload( Collection outputFiles = resolveActionInputs(execRoot, spawn.getOutputFiles()); try (SilentCloseable c = Profiler.instance().profile(UPLOAD_TIME, "upload outputs")) { remoteCache.upload( - actionKey, action, command, execRoot, outputFiles, context.getFileOutErr()); + remoteActionExecutionContext, + actionKey, + action, + command, + execRoot, + outputFiles, + context.getFileOutErr()); } catch (IOException e) { if (verboseFailures) { report(Event.debug("Upload to remote cache failed: " + e.getMessage())); diff --git a/src/main/java/com/google/devtools/build/lib/remote/common/RemoteCacheClient.java b/src/main/java/com/google/devtools/build/lib/remote/common/RemoteCacheClient.java index 11fa078357ca8b..2f3c74b0fa04cd 100644 --- a/src/main/java/com/google/devtools/build/lib/remote/common/RemoteCacheClient.java +++ b/src/main/java/com/google/devtools/build/lib/remote/common/RemoteCacheClient.java @@ -83,7 +83,8 @@ ListenableFuture downloadActionResult( * @throws IOException If there is an error uploading the action result. * @throws InterruptedException In case the thread */ - void uploadActionResult(ActionKey actionKey, ActionResult actionResult) + void uploadActionResult( + RemoteActionExecutionContext context, ActionKey actionKey, ActionResult actionResult) throws IOException, InterruptedException; /** diff --git a/src/main/java/com/google/devtools/build/lib/remote/disk/DiskAndRemoteCacheClient.java b/src/main/java/com/google/devtools/build/lib/remote/disk/DiskAndRemoteCacheClient.java index d188191652d12d..74c19bdcf15d5b 100644 --- a/src/main/java/com/google/devtools/build/lib/remote/disk/DiskAndRemoteCacheClient.java +++ b/src/main/java/com/google/devtools/build/lib/remote/disk/DiskAndRemoteCacheClient.java @@ -49,11 +49,12 @@ public DiskAndRemoteCacheClient( } @Override - public void uploadActionResult(ActionKey actionKey, ActionResult actionResult) + public void uploadActionResult( + RemoteActionExecutionContext context, ActionKey actionKey, ActionResult actionResult) throws IOException, InterruptedException { - diskCache.uploadActionResult(actionKey, actionResult); + diskCache.uploadActionResult(context, actionKey, actionResult); if (!options.incompatibleRemoteResultsIgnoreDisk || options.remoteUploadLocalResults) { - remoteCache.uploadActionResult(actionKey, actionResult); + remoteCache.uploadActionResult(context, actionKey, actionResult); } } @@ -177,7 +178,7 @@ public ListenableFuture downloadActionResult( if (actionResult == null) { return Futures.immediateFuture(null); } else { - diskCache.uploadActionResult(actionKey, actionResult); + diskCache.uploadActionResult(context, actionKey, actionResult); return Futures.immediateFuture(actionResult); } }, diff --git a/src/main/java/com/google/devtools/build/lib/remote/disk/DiskCacheClient.java b/src/main/java/com/google/devtools/build/lib/remote/disk/DiskCacheClient.java index 3722cc56716523..9cef499ab4942b 100644 --- a/src/main/java/com/google/devtools/build/lib/remote/disk/DiskCacheClient.java +++ b/src/main/java/com/google/devtools/build/lib/remote/disk/DiskCacheClient.java @@ -108,7 +108,8 @@ public ListenableFuture downloadActionResult( } @Override - public void uploadActionResult(ActionKey actionKey, ActionResult actionResult) + public void uploadActionResult( + RemoteActionExecutionContext context, ActionKey actionKey, ActionResult actionResult) throws IOException { try (InputStream data = actionResult.toByteString().newInput()) { saveFile(actionKey.getDigest().getHash(), data, /* actionResult= */ true); diff --git a/src/main/java/com/google/devtools/build/lib/remote/http/HttpCacheClient.java b/src/main/java/com/google/devtools/build/lib/remote/http/HttpCacheClient.java index c35d9f074a88cf..9a55733bdbccea 100644 --- a/src/main/java/com/google/devtools/build/lib/remote/http/HttpCacheClient.java +++ b/src/main/java/com/google/devtools/build/lib/remote/http/HttpCacheClient.java @@ -705,7 +705,8 @@ private boolean reset(InputStream in) throws IOException { } @Override - public void uploadActionResult(ActionKey actionKey, ActionResult actionResult) + public void uploadActionResult( + RemoteActionExecutionContext context, ActionKey actionKey, ActionResult actionResult) throws IOException, InterruptedException { ByteString serialized = actionResult.toByteString(); ListenableFuture uploadFuture = 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 6d8af4281a60f5..878920b0bcb4aa 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 @@ -700,7 +700,8 @@ private ActionResult uploadDirectory(RemoteCache remoteCache, List outputs Action action = Action.getDefaultInstance(); ActionKey actionKey = DIGEST_UTIL.computeActionKey(action); Command cmd = Command.getDefaultInstance(); - return remoteCache.upload(actionKey, action, cmd, execRoot, outputs, outErr); + return remoteCache.upload( + remoteActionExecutionContext, actionKey, action, cmd, execRoot, outputs, outErr); } @Test @@ -826,6 +827,7 @@ public void updateActionResult( ActionResult result = remoteCache.upload( + remoteActionExecutionContext, DIGEST_UTIL.asActionKey(actionDigest), action, command, @@ -888,6 +890,7 @@ public void updateActionResult( ActionResult result = remoteCache.upload( + remoteActionExecutionContext, DIGEST_UTIL.asActionKey(actionDigest), action, command, @@ -1036,6 +1039,7 @@ public void onError(Throwable t) { .when(mockByteStreamImpl) .queryWriteStatus(any(), any()); remoteCache.upload( + remoteActionExecutionContext, actionKey, Action.getDefaultInstance(), Command.getDefaultInstance(), 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 2fb158a112300e..abe594dc914cb4 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 @@ -55,10 +55,14 @@ import com.google.devtools.build.lib.clock.JavaClock; import com.google.devtools.build.lib.remote.RemoteCache.OutputFilesLocker; import com.google.devtools.build.lib.remote.RemoteCache.UploadManifest; +import com.google.devtools.build.lib.remote.common.NetworkTime; +import com.google.devtools.build.lib.remote.common.RemoteActionExecutionContext; +import com.google.devtools.build.lib.remote.common.RemoteActionExecutionContextImpl; import com.google.devtools.build.lib.remote.common.RemoteCacheClient.ActionKey; import com.google.devtools.build.lib.remote.options.RemoteOptions; import com.google.devtools.build.lib.remote.util.DigestUtil; import com.google.devtools.build.lib.remote.util.InMemoryCacheClient; +import com.google.devtools.build.lib.remote.util.TracingMetadataUtils; import com.google.devtools.build.lib.remote.util.Utils; import com.google.devtools.build.lib.remote.util.Utils.InMemoryOutput; import com.google.devtools.build.lib.skyframe.TreeArtifactValue; @@ -99,6 +103,7 @@ public class RemoteCacheTests { @Mock private OutputFilesLocker outputFilesLocker; + private RemoteActionExecutionContext remoteActionExecutionContext; private FileSystem fs; private Path execRoot; ArtifactRoot artifactRoot; @@ -110,6 +115,11 @@ public class RemoteCacheTests { @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); + remoteActionExecutionContext = + new RemoteActionExecutionContextImpl( + TracingMetadataUtils.buildMetadata( + "none", "none", Digest.getDefaultInstance().getHash()), + new NetworkTime()); fs = new InMemoryFileSystem(new JavaClock(), DigestHashFunction.SHA256); execRoot = fs.getPath("/execroot"); execRoot.createDirectoryAndParents(); @@ -1426,6 +1436,7 @@ public void testUploadDirectory() throws Exception { InMemoryRemoteCache remoteCache = newRemoteCache(); ActionResult result = remoteCache.upload( + remoteActionExecutionContext, digestUtil.asActionKey(actionDigest), action, cmd, @@ -1462,6 +1473,7 @@ public void testUploadEmptyDirectory() throws Exception { InMemoryRemoteCache remoteCache = newRemoteCache(); ActionResult result = remoteCache.upload( + remoteActionExecutionContext, actionDigest, action, cmd, @@ -1518,6 +1530,7 @@ public void testUploadNestedDirectory() throws Exception { InMemoryRemoteCache remoteCache = newRemoteCache(); ActionResult result = remoteCache.upload( + remoteActionExecutionContext, actionDigest, action, cmd, diff --git a/src/test/java/com/google/devtools/build/lib/remote/RemoteSpawnCacheTest.java b/src/test/java/com/google/devtools/build/lib/remote/RemoteSpawnCacheTest.java index fc168ac9b99667..47e7dd132ab849 100644 --- a/src/test/java/com/google/devtools/build/lib/remote/RemoteSpawnCacheTest.java +++ b/src/test/java/com/google/devtools/build/lib/remote/RemoteSpawnCacheTest.java @@ -270,6 +270,7 @@ public Void answer(InvocationOnMock invocation) { verify(remoteCache).download(eq(actionResult), eq(execRoot), eq(outErr), any()); verify(remoteCache, never()) .upload( + any(RemoteActionExecutionContext.class), any(ActionKey.class), any(Action.class), any(Command.class), @@ -309,6 +310,7 @@ public Void answer(InvocationOnMock invocation) { }) .when(remoteCache) .upload( + any(RemoteActionExecutionContext.class), any(ActionKey.class), any(Action.class), any(Command.class), @@ -318,6 +320,7 @@ public Void answer(InvocationOnMock invocation) { entry.store(result); verify(remoteCache) .upload( + any(RemoteActionExecutionContext.class), any(ActionKey.class), any(Action.class), any(Command.class), @@ -485,6 +488,7 @@ public void failedActionsAreNotUploaded() throws Exception { entry.store(result); verify(remoteCache, never()) .upload( + any(RemoteActionExecutionContext.class), any(ActionKey.class), any(Action.class), any(Command.class), @@ -510,6 +514,7 @@ public void printWarningIfUploadFails() throws Exception { doThrow(new IOException("cache down")) .when(remoteCache) .upload( + any(RemoteActionExecutionContext.class), any(ActionKey.class), any(Action.class), any(Command.class), @@ -520,6 +525,7 @@ public void printWarningIfUploadFails() throws Exception { entry.store(result); verify(remoteCache) .upload( + any(RemoteActionExecutionContext.class), any(ActionKey.class), any(Action.class), any(Command.class), @@ -566,6 +572,7 @@ public Void answer(InvocationOnMock invocation) { }) .when(remoteCache) .upload( + any(RemoteActionExecutionContext.class), any(ActionKey.class), any(Action.class), any(Command.class), @@ -575,6 +582,7 @@ public Void answer(InvocationOnMock invocation) { entry.store(result); verify(remoteCache) .upload( + any(RemoteActionExecutionContext.class), any(ActionKey.class), any(Action.class), any(Command.class), @@ -637,6 +645,7 @@ public Void answer(InvocationOnMock invocation) { }) .when(remoteCache) .upload( + any(RemoteActionExecutionContext.class), any(ActionKey.class), any(Action.class), any(Command.class), @@ -646,6 +655,7 @@ public Void answer(InvocationOnMock invocation) { entry.store(result); verify(remoteCache) .upload( + any(RemoteActionExecutionContext.class), any(ActionKey.class), any(Action.class), any(Command.class), diff --git a/src/test/java/com/google/devtools/build/lib/remote/RemoteSpawnRunnerTest.java b/src/test/java/com/google/devtools/build/lib/remote/RemoteSpawnRunnerTest.java index 4e9cdceab39978..3ca3fd7c68d321 100644 --- a/src/test/java/com/google/devtools/build/lib/remote/RemoteSpawnRunnerTest.java +++ b/src/test/java/com/google/devtools/build/lib/remote/RemoteSpawnRunnerTest.java @@ -212,7 +212,7 @@ public void nonCachableSpawnsShouldNotBeCached_remote() throws Exception { any(RemoteActionExecutionContext.class), any(ActionKey.class), /* inlineOutErr= */ eq(false)); - verify(cache, never()).upload(any(), any(), any(), any(), any(), any()); + verify(cache, never()).upload(any(), any(), any(), any(), any(), any(), any()); verifyNoMoreInteractions(localRunner); } @@ -282,8 +282,15 @@ public void cachableSpawnsShouldBeCached_localFallback() throws Exception { verify(localRunner).exec(eq(spawn), eq(policy)); verify(runner) .execLocallyAndUpload( - eq(spawn), eq(policy), any(), any(), any(), any(), /* uploadLocalResults= */ eq(true)); - verify(cache).upload(any(), any(), any(), any(), any(), any()); + any(), + eq(spawn), + eq(policy), + any(), + any(), + any(), + any(), + /* uploadLocalResults= */ eq(true)); + verify(cache).upload(any(), any(), any(), any(), any(), any(), any()); } @Test @@ -312,8 +319,15 @@ public void failedLocalActionShouldNotBeUploaded() throws Exception { verify(localRunner).exec(eq(spawn), eq(policy)); verify(runner) .execLocallyAndUpload( - eq(spawn), eq(policy), any(), any(), any(), any(), /* uploadLocalResults= */ eq(true)); - verify(cache, never()).upload(any(), any(), any(), any(), any(), any()); + any(), + eq(spawn), + eq(policy), + any(), + any(), + any(), + any(), + /* uploadLocalResults= */ eq(true)); + verify(cache, never()).upload(any(), any(), any(), any(), any(), any(), any()); } @Test @@ -352,8 +366,15 @@ public void treatFailedCachedActionAsCacheMiss_local() throws Exception { verify(localRunner).exec(eq(spawn), eq(policy)); verify(runner) .execLocallyAndUpload( - eq(spawn), eq(policy), any(), any(), any(), any(), /* uploadLocalResults= */ eq(true)); - verify(cache).upload(any(), any(), any(), any(), any(), any()); + any(), + eq(spawn), + eq(policy), + any(), + any(), + any(), + any(), + /* uploadLocalResults= */ eq(true)); + verify(cache).upload(any(), any(), any(), any(), any(), any(), any()); verify(cache, never()).download(any(ActionResult.class), any(Path.class), eq(outErr), any()); } @@ -414,7 +435,7 @@ public void printWarningIfCacheIsDown() throws Exception { doThrow(new IOException("cache down")) .when(cache) - .upload(any(), any(), any(), any(), any(), any()); + .upload(any(), any(), any(), any(), any(), any(), any()); SpawnResult res = new SpawnResult.Builder() diff --git a/src/test/java/com/google/devtools/build/lib/remote/util/InMemoryCacheClient.java b/src/test/java/com/google/devtools/build/lib/remote/util/InMemoryCacheClient.java index 63d0d5965b6aed..d932ddf56e5bb8 100644 --- a/src/test/java/com/google/devtools/build/lib/remote/util/InMemoryCacheClient.java +++ b/src/test/java/com/google/devtools/build/lib/remote/util/InMemoryCacheClient.java @@ -100,7 +100,8 @@ public ListenableFuture downloadActionResult( } @Override - public void uploadActionResult(ActionKey actionKey, ActionResult actionResult) { + public void uploadActionResult( + RemoteActionExecutionContext context, ActionKey actionKey, ActionResult actionResult) { ac.put(actionKey, actionResult); } diff --git a/src/tools/remote/src/main/java/com/google/devtools/build/remote/worker/ActionCacheServer.java b/src/tools/remote/src/main/java/com/google/devtools/build/remote/worker/ActionCacheServer.java index 8eda8fc4e8dcaf..a077c8d19aaf8b 100644 --- a/src/tools/remote/src/main/java/com/google/devtools/build/remote/worker/ActionCacheServer.java +++ b/src/tools/remote/src/main/java/com/google/devtools/build/remote/worker/ActionCacheServer.java @@ -70,8 +70,12 @@ public void getActionResult( public void updateActionResult( UpdateActionResultRequest request, StreamObserver responseObserver) { try { + RequestMetadata requestMetadata = TracingMetadataUtils.fromCurrentContext(); + RemoteActionExecutionContext context = + new RemoteActionExecutionContextImpl(requestMetadata, new NetworkTime()); + ActionKey actionKey = digestUtil.asActionKey(request.getActionDigest()); - cache.uploadActionResult(actionKey, request.getActionResult()); + cache.uploadActionResult(context, actionKey, request.getActionResult()); responseObserver.onNext(request.getActionResult()); responseObserver.onCompleted(); } catch (Exception e) { diff --git a/src/tools/remote/src/main/java/com/google/devtools/build/remote/worker/ExecutionServer.java b/src/tools/remote/src/main/java/com/google/devtools/build/remote/worker/ExecutionServer.java index 000176f908beac..0257ee281bb236 100644 --- a/src/tools/remote/src/main/java/com/google/devtools/build/remote/worker/ExecutionServer.java +++ b/src/tools/remote/src/main/java/com/google/devtools/build/remote/worker/ExecutionServer.java @@ -37,6 +37,9 @@ import com.google.devtools.build.lib.actions.ExecException; import com.google.devtools.build.lib.remote.ExecutionStatusException; import com.google.devtools.build.lib.remote.common.CacheNotFoundException; +import com.google.devtools.build.lib.remote.common.NetworkTime; +import com.google.devtools.build.lib.remote.common.RemoteActionExecutionContext; +import com.google.devtools.build.lib.remote.common.RemoteActionExecutionContextImpl; import com.google.devtools.build.lib.remote.common.RemoteCacheClient.ActionKey; import com.google.devtools.build.lib.remote.util.DigestUtil; import com.google.devtools.build.lib.remote.util.TracingMetadataUtils; @@ -221,7 +224,9 @@ private ActionResult execute(ExecuteRequest request, String id) "build-request-id: %s command-id: %s action-id: %s", meta.getCorrelatedInvocationsId(), meta.getToolInvocationId(), meta.getActionId()); logger.atFine().log("Received work for: %s", workDetails); - ActionResult result = execute(request.getActionDigest(), tempRoot); + RemoteActionExecutionContext context = + new RemoteActionExecutionContextImpl(meta, new NetworkTime()); + ActionResult result = execute(context, request.getActionDigest(), tempRoot); logger.atFine().log("Completed %s", workDetails); return result; } catch (Exception e) { @@ -240,7 +245,8 @@ private ActionResult execute(ExecuteRequest request, String id) } } - private ActionResult execute(Digest actionDigest, Path execRoot) + private ActionResult execute( + RemoteActionExecutionContext context, Digest actionDigest, Path execRoot) throws IOException, InterruptedException, StatusException { Command command; Action action; @@ -327,7 +333,8 @@ private ActionResult execute(Digest actionDigest, Path execRoot) ActionResult result = null; try { - result = cache.upload(actionKey, action, command, execRoot, outputs, outErr, exitCode); + result = + cache.upload(context, actionKey, action, command, execRoot, outputs, outErr, exitCode); } catch (ExecException e) { if (errStatus == null) { errStatus = diff --git a/src/tools/remote/src/main/java/com/google/devtools/build/remote/worker/OnDiskBlobStoreCache.java b/src/tools/remote/src/main/java/com/google/devtools/build/remote/worker/OnDiskBlobStoreCache.java index 424d805edc22d6..829d863d3297a1 100644 --- a/src/tools/remote/src/main/java/com/google/devtools/build/remote/worker/OnDiskBlobStoreCache.java +++ b/src/tools/remote/src/main/java/com/google/devtools/build/remote/worker/OnDiskBlobStoreCache.java @@ -20,6 +20,7 @@ import build.bazel.remote.execution.v2.FileNode; import com.google.common.util.concurrent.ListenableFuture; import com.google.devtools.build.lib.remote.RemoteCache; +import com.google.devtools.build.lib.remote.common.RemoteActionExecutionContext; import com.google.devtools.build.lib.remote.common.RemoteCacheClient.ActionKey; import com.google.devtools.build.lib.remote.disk.DiskCacheClient; import com.google.devtools.build.lib.remote.options.RemoteOptions; @@ -66,9 +67,10 @@ public ListenableFuture uploadBlob(Digest digest, ByteString data) { return cacheProtocol.uploadBlob(digest, data); } - public void uploadActionResult(ActionKey actionKey, ActionResult actionResult) + public void uploadActionResult( + RemoteActionExecutionContext context, ActionKey actionKey, ActionResult actionResult) throws IOException, InterruptedException { - cacheProtocol.uploadActionResult(actionKey, actionResult); + cacheProtocol.uploadActionResult(context, actionKey, actionResult); } public DigestUtil getDigestUtil() {