Adds option bes_keywords BEP publishing.
PiperOrigin-RevId: 170121049
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 088c731..0df5994 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
@@ -229,7 +229,8 @@
clock,
pathConverter,
commandLineReporter,
- besOptions.projectId);
+ besOptions.projectId,
+ besOptions.besKeywords);
logger.fine("BuildEventServiceTransport was created successfully");
return besTransport;
}
diff --git a/src/main/java/com/google/devtools/build/lib/buildeventservice/BuildEventServiceOptions.java b/src/main/java/com/google/devtools/build/lib/buildeventservice/BuildEventServiceOptions.java
index e24c204..e0c86e2 100644
--- a/src/main/java/com/google/devtools/build/lib/buildeventservice/BuildEventServiceOptions.java
+++ b/src/main/java/com/google/devtools/build/lib/buildeventservice/BuildEventServiceOptions.java
@@ -19,6 +19,7 @@
import com.google.devtools.common.options.OptionEffectTag;
import com.google.devtools.common.options.OptionsBase;
import java.time.Duration;
+import java.util.List;
/** Options used by {@link BuildEventServiceModule}. */
public class BuildEventServiceOptions extends OptionsBase {
@@ -76,4 +77,17 @@
help = "Specifies the BES project identifier. Defaults to null."
)
public String projectId;
+
+ @Option(
+ name = "bes_keywords",
+ defaultValue = "",
+ documentationCategory = OptionDocumentationCategory.LOGGING,
+ effectTags = {OptionEffectTag.AFFECTS_OUTPUTS},
+ allowMultiple = true,
+ help =
+ "Specifies a list of notification keywords to be added the default set of keywords "
+ + "published to BES (\"command_name=<command_name> \", \"protocol_name=BEP\"). "
+ + "Defaults to none."
+ )
+ public List<String> besKeywords;
}
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 636f873..022d292 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
@@ -35,6 +35,7 @@
import com.google.devtools.build.v1.StreamId.BuildComponent;
import com.google.protobuf.Any;
import com.google.protobuf.util.Timestamps;
+import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import javax.annotation.Nullable;
@@ -47,18 +48,21 @@
private final AtomicInteger streamSequenceNumber;
private final String commandName;
private final Clock clock;
+ private final List<String> additionalKeywords;
public BuildEventServiceProtoUtil(
String buildRequestId,
String buildInvocationId,
@Nullable String projectId,
String commandName,
- Clock clock) {
+ Clock clock,
+ List<String> additionalKeywords) {
this.buildRequestId = buildRequestId;
this.buildInvocationId = buildInvocationId;
this.projectId = projectId;
this.commandName = commandName;
this.clock = clock;
+ this.additionalKeywords = additionalKeywords;
this.streamSequenceNumber = new AtomicInteger(1);
}
@@ -189,6 +193,10 @@
/** Keywords used by BES subscribers to filter notifications */
private ImmutableList<String> getKeywords() {
- return ImmutableList.of("command_name=" + commandName, "protocol_name=BEP");
+ return ImmutableList.<String>builder()
+ .add("command_name=" + commandName)
+ .add("protocol_name=BEP")
+ .addAll(additionalKeywords)
+ .build();
}
}
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 5df6580..be2ee4d 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
@@ -58,6 +58,7 @@
import io.grpc.Status;
import java.time.Duration;
import java.util.Deque;
+import java.util.List;
import java.util.concurrent.BlockingDeque;
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentLinkedDeque;
@@ -129,10 +130,11 @@
Clock clock,
PathConverter pathConverter,
EventHandler commandLineReporter,
- @Nullable String projectId) {
+ @Nullable String projectId,
+ List<String> keywords) {
this(besClient, uploadTimeout, bestEffortUpload, publishLifecycleEvents, buildRequestId,
invocationId, command, moduleEnvironment, clock, pathConverter, commandLineReporter,
- projectId, new JavaSleeper());
+ projectId, keywords, new JavaSleeper());
}
@VisibleForTesting
@@ -149,10 +151,11 @@
PathConverter pathConverter,
EventHandler commandLineReporter,
@Nullable String projectId,
+ List<String> keywords,
Sleeper sleeper) {
this.besClient = besClient;
- this.besProtoUtil =
- new BuildEventServiceProtoUtil(buildRequestId, invocationId, projectId, command, clock);
+ this.besProtoUtil = new BuildEventServiceProtoUtil(
+ buildRequestId, invocationId, projectId, command, clock, keywords);
this.publishLifecycleEvents = publishLifecycleEvents;
this.moduleEnvironment = moduleEnvironment;
this.commandLineReporter = commandLineReporter;
diff --git a/src/test/java/com/google/devtools/build/lib/buildeventservice/BuildEventServiceProtoUtilTest.java b/src/test/java/com/google/devtools/build/lib/buildeventservice/BuildEventServiceProtoUtilTest.java
index 3d8b5b6..9091c9b 100644
--- a/src/test/java/com/google/devtools/build/lib/buildeventservice/BuildEventServiceProtoUtilTest.java
+++ b/src/test/java/com/google/devtools/build/lib/buildeventservice/BuildEventServiceProtoUtilTest.java
@@ -47,12 +47,18 @@
private static final String BUILD_INVOCATION_ID = "feedbeef-dead-4444-beef-deaddeaddead";
private static final String PROJECT_ID = "my_project";
private static final String COMMAND_NAME = "test";
- private static final ImmutableList<String> KEYWORDS =
- ImmutableList.of("command_name=" + COMMAND_NAME, "protocol_name=BEP");
+ private static final String ADDITIONAL_KEYWORD = "keyword=foo";
+ private static final ImmutableList<String> EXPECTED_KEYWORDS =
+ ImmutableList.of("command_name=" + COMMAND_NAME, "protocol_name=BEP", ADDITIONAL_KEYWORD);
private final ManualClock clock = new ManualClock();
private final BuildEventServiceProtoUtil besProtocol =
new BuildEventServiceProtoUtil(
- BUILD_REQUEST_ID, BUILD_INVOCATION_ID, PROJECT_ID, COMMAND_NAME, clock);
+ BUILD_REQUEST_ID,
+ BUILD_INVOCATION_ID,
+ PROJECT_ID,
+ COMMAND_NAME,
+ clock,
+ ImmutableList.of(ADDITIONAL_KEYWORD));
@Test
public void testBuildEnqueued() {
@@ -160,7 +166,7 @@
assertThat(besProtocol.bazelEvent(1, anything))
.isEqualTo(
PublishBuildToolEventStreamRequest.newBuilder()
- .addAllNotificationKeywords(KEYWORDS)
+ .addAllNotificationKeywords(EXPECTED_KEYWORDS)
.setOrderedBuildEvent(
OrderedBuildEvent.newBuilder()
.setStreamId(