Skip to content

Commit

Permalink
Add flag --check_preceding_lifecycle_events_present.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 443737855
  • Loading branch information
Googler authored and copybara-github committed Apr 22, 2022
1 parent bc0eb51 commit 14b5c41
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,7 @@ private BuildEventServiceTransport createBesTransport(
.projectId(besOptions.instanceName)
.commandName(cmdEnv.getCommandName())
.keywords(getBesKeywords(besOptions, cmdEnv.getRuntime().getStartupOptionsProvider()))
.checkPrecedingLifecycleEvents(besOptions.besCheckPrecedingLifecycleEvents)
.build();

return new BuildEventServiceTransport.Builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,18 @@ public class BuildEventServiceOptions extends OptionsBase {
+ " used to configure a Unix domain socket (unix:/path/to/socket).")
public String besProxy;

@Option(
name = "bes_check_preceding_lifecycle_events",
defaultValue = "false",
documentationCategory = OptionDocumentationCategory.LOGGING,
effectTags = {OptionEffectTag.AFFECTS_OUTPUTS},
help =
"Sets the field check_preceding_lifecycle_events_present on"
+ " PublishBuildToolEventStreamRequest which tells BES to check whether it previously"
+ " received InvocationAttemptStarted and BuildEnqueued events matching the current"
+ " tool event.")
public boolean besCheckPrecedingLifecycleEvents;

/** Determines the mode that will be used to upload data to the Build Event Service. */
public enum BesUploadMode {
/** Block at the end of the build waiting for the upload to complete */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,21 @@ public final class BuildEventServiceProtoUtil {
private final String projectId;
private final String commandName;
private final Set<String> additionalKeywords;
private final boolean checkPrecedingLifecycleEvents;

private BuildEventServiceProtoUtil(
String buildRequestId,
String buildInvocationId,
@Nullable String projectId,
String commandName,
Set<String> additionalKeywords) {
Set<String> additionalKeywords,
boolean checkPrecedingLifecycleEvents) {
this.buildRequestId = buildRequestId;
this.buildInvocationId = buildInvocationId;
this.projectId = projectId;
this.commandName = commandName;
this.additionalKeywords = ImmutableSet.copyOf(additionalKeywords);
this.checkPrecedingLifecycleEvents = checkPrecedingLifecycleEvents;
}

public PublishLifecycleEventRequest buildEnqueued(Timestamp timestamp) {
Expand Down Expand Up @@ -141,6 +144,7 @@ public PublishBuildToolEventStreamRequest publishBuildToolEventStreamRequest(
.setStreamId(streamId(besEvent.getEventCase())));
if (sequenceNumber == 1) {
builder.addAllNotificationKeywords(getKeywords());
builder.setCheckPrecedingLifecycleEventsPresent(checkPrecedingLifecycleEvents);
}
if (projectId != null) {
builder.setProjectId(projectId);
Expand Down Expand Up @@ -212,6 +216,7 @@ public static class Builder {
private String commandName;
private Set<String> keywords;
@Nullable private String projectId;
private boolean checkPrecedingLifecycleEvents;

public Builder buildRequestId(String value) {
this.buildRequestId = value;
Expand All @@ -238,13 +243,19 @@ public Builder keywords(Set<String> value) {
return this;
}

public Builder checkPrecedingLifecycleEvents(boolean value) {
this.checkPrecedingLifecycleEvents = value;
return this;
}

public BuildEventServiceProtoUtil build() {
return new BuildEventServiceProtoUtil(
checkNotNull(buildRequestId),
checkNotNull(invocationId),
projectId,
checkNotNull(commandName),
checkNotNull(keywords));
checkNotNull(keywords),
checkPrecedingLifecycleEvents);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -229,4 +229,33 @@ public void testStreamEvents() {
.build())
.build());
}

@Test
public void testStreamEventsWithCheckPrecedingLifecycleEventsEnabled() {
Any anything = Any.getDefaultInstance();
BuildEventServiceProtoUtil besProtoUtil =
new BuildEventServiceProtoUtil.Builder()
.buildRequestId(BUILD_REQUEST_ID)
.invocationId(BUILD_INVOCATION_ID)
.commandName(COMMAND_NAME)
.checkPrecedingLifecycleEvents(true)
.keywords(ImmutableSet.of(ADDITIONAL_KEYWORD))
.build();
assertThat(
besProtoUtil
.bazelEvent(1, Timestamps.fromMillis(100), anything)
.getCheckPrecedingLifecycleEventsPresent())
.isTrue();
// check_preceding_lifecycle_events_present is always false for events with sequence_number > 1.
assertThat(
besProtoUtil
.bazelEvent(2, Timestamps.fromMillis(100), anything)
.getCheckPrecedingLifecycleEventsPresent())
.isFalse();
assertThat(
besProtoUtil
.bazelEvent(3, Timestamps.fromMillis(100), anything)
.getCheckPrecedingLifecycleEventsPresent())
.isFalse();
}
}

0 comments on commit 14b5c41

Please sign in to comment.