aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build
diff options
context:
space:
mode:
authorGravatar Googler <noreply@google.com>2017-08-04 20:20:09 +0200
committerGravatar Jakob Buchgraber <buchgr@google.com>2017-08-07 11:22:14 +0200
commit4928abff40ca37271973589489dc5015e44c88c0 (patch)
treef5180afa63c5f2370e3010a1e8a89e592cdf4ae8 /src/main/java/com/google/devtools/build
parent6c31578a7128f783b0c4bf2416aa8a0c8d4ea58e (diff)
Add keywords to BES PublishBuildToolEventStreamRequest.
Notification keywords published BES include:command_name and protocol_name. These keywords can be used by subscribers to filter BES streams of interest. This change also cleans up use of deprecated fields in in PublishBuildToolEventStreamRequest. RELEASE_NOTES: None. Change-Id: I331fc9a818728ad6986230ebdea7d4019e8e49fc PiperOrigin-RevId: 164285745
Diffstat (limited to 'src/main/java/com/google/devtools/build')
-rw-r--r--src/main/java/com/google/devtools/build/lib/buildeventservice/BuildEventServiceModule.java35
-rw-r--r--src/main/java/com/google/devtools/build/lib/buildeventservice/BuildEventServiceProtoUtil.java33
-rw-r--r--src/main/java/com/google/devtools/build/lib/buildeventservice/BuildEventServiceTransport.java11
3 files changed, 61 insertions, 18 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/buildeventservice/BuildEventServiceModule.java b/src/main/java/com/google/devtools/build/lib/buildeventservice/BuildEventServiceModule.java
index 19b3e966c8..513909123d 100644
--- a/src/main/java/com/google/devtools/build/lib/buildeventservice/BuildEventServiceModule.java
+++ b/src/main/java/com/google/devtools/build/lib/buildeventservice/BuildEventServiceModule.java
@@ -85,7 +85,8 @@ public abstract class BuildEventServiceModule<T extends BuildEventServiceOptions
commandEnvironment.getRuntime().getPathToUriConverter(),
commandEnvironment.getReporter(),
commandEnvironment.getClientEnv().get("BAZEL_INTERNAL_BUILD_REQUEST_ID"),
- commandEnvironment.getCommandId().toString());
+ commandEnvironment.getCommandId().toString(),
+ commandEnvironment.getCommandName());
if (streamer != null) {
commandEnvironment.getReporter().addHandler(streamer);
commandEnvironment.getEventBus().register(streamer);
@@ -124,7 +125,7 @@ public abstract class BuildEventServiceModule<T extends BuildEventServiceOptions
/**
* Returns {@code null} if no stream could be created.
*
- * @param buildRequestId if {@code null} or {@code ""} a random UUID is used instead.
+ * @param buildRequestId if {@code null} or {@code ""} a random UUID is used instead.
*/
@Nullable
@VisibleForTesting
@@ -136,7 +137,8 @@ public abstract class BuildEventServiceModule<T extends BuildEventServiceOptions
PathConverter pathConverter,
Reporter reporter,
String buildRequestId,
- String invocationId) {
+ String invocationId,
+ String commandName) {
try {
T besOptions =
checkNotNull(
@@ -151,8 +153,17 @@ public abstract class BuildEventServiceModule<T extends BuildEventServiceOptions
BuildEventTransport besTransport = null;
try {
- besTransport = tryCreateBesTransport(besOptions, authTlsOptions, buildRequestId,
- invocationId, moduleEnvironment, clock, pathConverter, commandLineReporter);
+ besTransport =
+ tryCreateBesTransport(
+ besOptions,
+ authTlsOptions,
+ buildRequestId,
+ invocationId,
+ commandName,
+ moduleEnvironment,
+ clock,
+ pathConverter,
+ commandLineReporter);
} catch (Exception e) {
if (besOptions.besBestEffort) {
commandLineReporter.handle(Event.warn(format(UPLOAD_FAILED_MESSAGE, e.getMessage())));
@@ -183,9 +194,16 @@ public abstract class BuildEventServiceModule<T extends BuildEventServiceOptions
}
@Nullable
- private BuildEventTransport tryCreateBesTransport(T besOptions, AuthAndTLSOptions authTlsOptions,
- String buildRequestId, String invocationId, ModuleEnvironment moduleEnvironment, Clock clock,
- PathConverter pathConverter, EventHandler commandLineReporter) throws IOException {
+ private BuildEventTransport tryCreateBesTransport(
+ T besOptions,
+ AuthAndTLSOptions authTlsOptions,
+ String buildRequestId,
+ String invocationId,
+ String commandName,
+ ModuleEnvironment moduleEnvironment,
+ Clock clock,
+ PathConverter pathConverter,
+ EventHandler commandLineReporter) throws IOException {
if (isNullOrEmpty(besOptions.besBackend)) {
logger.fine("BuildEventServiceTransport is disabled.");
return null;
@@ -210,6 +228,7 @@ public abstract class BuildEventServiceModule<T extends BuildEventServiceOptions
besOptions.besLifecycleEvents,
buildRequestId,
invocationId,
+ commandName,
moduleEnvironment,
clock,
pathConverter,
diff --git a/src/main/java/com/google/devtools/build/lib/buildeventservice/BuildEventServiceProtoUtil.java b/src/main/java/com/google/devtools/build/lib/buildeventservice/BuildEventServiceProtoUtil.java
index 90209f0b15..2332bb8c82 100644
--- a/src/main/java/com/google/devtools/build/lib/buildeventservice/BuildEventServiceProtoUtil.java
+++ b/src/main/java/com/google/devtools/build/lib/buildeventservice/BuildEventServiceProtoUtil.java
@@ -17,6 +17,7 @@ package com.google.devtools.build.lib.buildeventservice;
import static com.google.devtools.build.v1.BuildEvent.BuildComponentStreamFinished.FinishType.FINISHED;
import com.google.common.annotations.VisibleForTesting;
+import com.google.common.collect.ImmutableList;
import com.google.devtools.build.lib.util.Clock;
import com.google.devtools.build.v1.BuildEvent;
import com.google.devtools.build.v1.BuildEvent.BuildComponentStreamFinished;
@@ -44,13 +45,19 @@ public final class BuildEventServiceProtoUtil {
private final String buildInvocationId;
private final String projectId;
private final AtomicInteger streamSequenceNumber;
+ private final String commandName;
private final Clock clock;
- public BuildEventServiceProtoUtil(String buildRequestId, String buildInvocationId,
- @Nullable String projectId, Clock clock) {
+ public BuildEventServiceProtoUtil(
+ String buildRequestId,
+ String buildInvocationId,
+ @Nullable String projectId,
+ String commandName,
+ Clock clock) {
this.buildRequestId = buildRequestId;
this.buildInvocationId = buildInvocationId;
this.projectId = projectId;
+ this.commandName = commandName;
this.clock = clock;
this.streamSequenceNumber = new AtomicInteger(1);
}
@@ -126,11 +133,18 @@ public final class BuildEventServiceProtoUtil {
@VisibleForTesting
public PublishBuildToolEventStreamRequest publishBuildToolEventStreamRequest(
int sequenceNumber, BuildEvent.Builder besEvent) {
- return PublishBuildToolEventStreamRequest.newBuilder()
- .setSequenceNumber(sequenceNumber)
- .setEvent(besEvent.setEventTime(Timestamps.fromMillis(clock.currentTimeMillis())))
- .setStreamId(streamId(besEvent.getEventCase()))
- .build();
+ PublishBuildToolEventStreamRequest.Builder builder =
+ PublishBuildToolEventStreamRequest.newBuilder()
+ .setOrderedBuildEvent(
+ OrderedBuildEvent.newBuilder()
+ .setSequenceNumber(sequenceNumber)
+ .setEvent(
+ besEvent.setEventTime(Timestamps.fromMillis(clock.currentTimeMillis())))
+ .setStreamId(streamId(besEvent.getEventCase())));
+ if (sequenceNumber == 1) {
+ builder.addAllNotificationKeywords(getKeywords());
+ }
+ return builder.build();
}
@VisibleForTesting
@@ -172,4 +186,9 @@ public final class BuildEventServiceProtoUtil {
}
return streamId.build();
}
+
+ /** Keywords used by BES subscribers to filter notifications */
+ private ImmutableList<String> getKeywords() {
+ return ImmutableList.of("command_name=" + commandName, "protocol_name=BEP");
+ }
}
diff --git a/src/main/java/com/google/devtools/build/lib/buildeventservice/BuildEventServiceTransport.java b/src/main/java/com/google/devtools/build/lib/buildeventservice/BuildEventServiceTransport.java
index ce2053c8b7..60c35302e8 100644
--- a/src/main/java/com/google/devtools/build/lib/buildeventservice/BuildEventServiceTransport.java
+++ b/src/main/java/com/google/devtools/build/lib/buildeventservice/BuildEventServiceTransport.java
@@ -118,6 +118,7 @@ public class BuildEventServiceTransport implements BuildEventTransport {
boolean publishLifecycleEvents,
String buildRequestId,
String invocationId,
+ String command,
ModuleEnvironment moduleEnvironment,
Clock clock,
PathConverter pathConverter,
@@ -129,7 +130,7 @@ public class BuildEventServiceTransport implements BuildEventTransport {
bestEffortUpload,
publishLifecycleEvents,
moduleEnvironment,
- new BuildEventServiceProtoUtil(buildRequestId, invocationId, projectId, clock),
+ new BuildEventServiceProtoUtil(buildRequestId, invocationId, projectId, command, clock),
pathConverter,
commandLineReporter);
}
@@ -434,14 +435,18 @@ public class BuildEventServiceTransport implements BuildEventTransport {
}
private static boolean isLastEvent(PublishBuildToolEventStreamRequest event) {
- return event != null && event.getEvent().getEventCase() == COMPONENT_STREAM_FINISHED;
+ return event != null
+ && event.getOrderedBuildEvent().getEvent().getEventCase() == COMPONENT_STREAM_FINISHED;
}
private static Function<PublishBuildToolEventStreamResponse, Void> ackCallback(
final Deque<PublishBuildToolEventStreamRequest> pendingAck,
final BuildEventServiceClient besClient) {
return ack -> {
- long pendingSeq = pendingAck.isEmpty() ? -1 : pendingAck.peekFirst().getSequenceNumber();
+ long pendingSeq =
+ pendingAck.isEmpty()
+ ? -1
+ : pendingAck.peekFirst().getOrderedBuildEvent().getSequenceNumber();
long ackSeq = ack.getSequenceNumber();
if (pendingSeq != ackSeq) {
besClient.abortStream(