Skip to content

Commit

Permalink
Attach action mnemonics to execute requests
Browse files Browse the repository at this point in the history
This is a partial application of a pending pull request against Bazel
HEAD:
bazelbuild#13109

Unfortunately, the PR does not apply to Bazel 3.7 at all due to
extensive changes in how metadata is propagated through the remote
execution stack.

Change-Id: I99e98f32fd460df03fb57838e2a7327646a22940
  • Loading branch information
ulfjack committed Mar 5, 2021
1 parent 97740de commit 8dd0a70
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,8 @@ public SpawnResult exec(Spawn spawn, SpawnExecutionContext context)
// Look up action cache, and reuse the action output if it is found.
ActionKey actionKey = digestUtil.computeActionKey(action);
Context withMetadata =
TracingMetadataUtils.contextWithMetadata(buildRequestId, commandId, actionKey)
TracingMetadataUtils.contextWithMetadata(
buildRequestId, commandId, actionKey, getActionMnemonicOrNull(spawn))
.withValue(NetworkTime.CONTEXT_KEY, networkTime);
Context previous = withMetadata.attach();
Profiler prof = Profiler.instance();
Expand Down Expand Up @@ -445,6 +446,11 @@ public SpawnResult exec(Spawn spawn, SpawnExecutionContext context)
}
}

private String getActionMnemonicOrNull(Spawn spawn) {
ActionExecutionMetadata metadata = spawn.getResourceOwner();
return metadata == null ? null : metadata.getMnemonic();
}

/** conversion utility for protobuf Timestamp difference to java.time.Duration */
private static Duration between(Timestamp from, Timestamp to) {
return Duration.ofNanos(Durations.toNanos(Timestamps.between(from, to)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,12 @@ private TracingMetadataUtils() {}
*/
public static Context contextWithMetadata(
String buildRequestId, String commandId, ActionKey actionKey) {
return contextWithMetadata(buildRequestId, commandId, actionKey.getDigest().getHash());
return contextWithMetadata(buildRequestId, commandId, actionKey.getDigest().getHash(), null);
}

public static Context contextWithMetadata(
String buildRequestId, String commandId, ActionKey actionKey, String actionMnemonic) {
return contextWithMetadata(buildRequestId, commandId, actionKey.getDigest().getHash(), actionMnemonic);
}

/**
Expand All @@ -67,6 +72,11 @@ public static Context contextWithMetadata(
*/
public static Context contextWithMetadata(
String buildRequestId, String commandId, String actionId) {
return contextWithMetadata(buildRequestId, commandId, actionId, null);
}

public static Context contextWithMetadata(
String buildRequestId, String commandId, String actionId, String actionMnemonic) {
Preconditions.checkNotNull(buildRequestId);
Preconditions.checkNotNull(commandId);
Preconditions.checkNotNull(actionId);
Expand All @@ -79,6 +89,8 @@ public static Context contextWithMetadata(
ToolDetails.newBuilder()
.setToolName("bazel")
.setToolVersion(BlazeVersionInfo.instance().getVersion()))
// The default value for proto strings is "".
.setActionMnemonic(actionMnemonic == null ? "" : actionMnemonic)
.build();
return contextWithMetadata(metadata);
}
Expand Down

0 comments on commit 8dd0a70

Please sign in to comment.