Remove unnecessary BuildEventLogger abstraction.
Instead, inline it in the BuildEventServiceUploader where it's actually used to
avoid an unnecessary layer of indirection that makes the code harder to read.
PiperOrigin-RevId: 234138204
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 9a30c0a..9a4dd8d 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
@@ -26,16 +26,13 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.devtools.build.lib.authandtls.AuthAndTLSOptions;
-import com.google.devtools.build.lib.buildeventservice.BuildEventServiceTransport.BuildEventLogger;
import com.google.devtools.build.lib.buildeventservice.BuildEventServiceTransport.ExitFunction;
import com.google.devtools.build.lib.buildeventservice.client.BuildEventServiceClient;
import com.google.devtools.build.lib.buildeventstream.ArtifactGroupNamer;
import com.google.devtools.build.lib.buildeventstream.BuildEventArtifactUploader;
import com.google.devtools.build.lib.buildeventstream.BuildEventProtocolOptions;
-import com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos;
import com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos.Aborted.AbortReason;
import com.google.devtools.build.lib.buildeventstream.BuildEventTransport;
-import com.google.devtools.build.lib.buildeventstream.LargeBuildEventSerializedEvent;
import com.google.devtools.build.lib.buildeventstream.transports.BuildEventStreamOptions;
import com.google.devtools.build.lib.events.Event;
import com.google.devtools.build.lib.events.EventHandler;
@@ -278,17 +275,6 @@
BuildEventServiceClient client = getBesClient(besOptions, authTlsOptions);
BuildEventArtifactUploader artifactUploader = uploaderSupplier.get();
- BuildEventLogger buildEventLogger =
- (BuildEventStreamProtos.BuildEvent bepEvent) -> {
- if (bepEvent.getSerializedSize()
- > LargeBuildEventSerializedEvent.SIZE_OF_LARGE_BUILD_EVENTS_IN_BYTES) {
- env.getEventBus()
- .post(
- new LargeBuildEventSerializedEvent(
- bepEvent.getId().toString(), bepEvent.getSerializedSize()));
- }
- };
-
BuildEventServiceProtoUtil besProtoUtil =
new BuildEventServiceProtoUtil(
env.getBuildRequestId(),
@@ -301,7 +287,7 @@
new BuildEventServiceTransport.Builder()
.closeTimeout(besOptions.besTimeout)
.publishLifecycleEvents(besOptions.besLifecycleEvents)
- .buildEventLogger(buildEventLogger)
+ .setEventBus(env.getEventBus())
.build(
client,
artifactUploader,
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 67084ee..2c38546 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
@@ -16,6 +16,8 @@
import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Preconditions;
+import com.google.common.eventbus.EventBus;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.MoreExecutors;
import com.google.common.util.concurrent.SettableFuture;
@@ -24,7 +26,6 @@
import com.google.devtools.build.lib.buildeventstream.BuildEvent;
import com.google.devtools.build.lib.buildeventstream.BuildEventArtifactUploader;
import com.google.devtools.build.lib.buildeventstream.BuildEventProtocolOptions;
-import com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos;
import com.google.devtools.build.lib.buildeventstream.BuildEventTransport;
import com.google.devtools.build.lib.clock.Clock;
import com.google.devtools.build.lib.util.ExitCode;
@@ -41,7 +42,7 @@
private boolean publishLifecycleEvents;
private Duration closeTimeout;
private Sleeper sleeper;
- private BuildEventLogger buildEventLogger;
+ private EventBus eventBus;
/** Whether to publish lifecycle events. */
public Builder publishLifecycleEvents(boolean publishLifecycleEvents) {
@@ -55,17 +56,17 @@
return this;
}
- public Builder buildEventLogger(BuildEventLogger buildEventLogger) {
- this.buildEventLogger = buildEventLogger;
- return this;
- }
-
@VisibleForTesting
public Builder sleeper(Sleeper sleeper) {
this.sleeper = sleeper;
return this;
}
+ public Builder setEventBus(EventBus eventBus) {
+ this.eventBus = eventBus;
+ return this;
+ }
+
public BuildEventServiceTransport build(
BuildEventServiceClient besClient,
BuildEventArtifactUploader localFileUploader,
@@ -74,6 +75,7 @@
Clock clock,
ExitFunction exitFunction,
ArtifactGroupNamer namer) {
+ Preconditions.checkNotNull(eventBus);
return new BuildEventServiceTransport(
besClient,
localFileUploader,
@@ -84,8 +86,8 @@
publishLifecycleEvents,
closeTimeout != null ? closeTimeout : Duration.ZERO,
sleeper != null ? sleeper : new JavaSleeper(),
- buildEventLogger != null ? buildEventLogger : (e) -> {},
- namer);
+ namer,
+ eventBus);
}
}
@@ -99,8 +101,8 @@
boolean publishLifecycleEvents,
Duration closeTimeout,
Sleeper sleeper,
- BuildEventLogger buildEventLogger,
- ArtifactGroupNamer namer) {
+ ArtifactGroupNamer namer,
+ EventBus eventBus) {
this.besUploader =
new BuildEventServiceUploader(
besClient,
@@ -112,8 +114,8 @@
exitFunc,
sleeper,
clock,
- buildEventLogger,
- namer);
+ namer,
+ eventBus);
}
@Override
@@ -146,12 +148,6 @@
return besUploader;
}
- /** BuildEventLogger can be used to log build event (stats). */
- @FunctionalInterface
- public interface BuildEventLogger {
- void log(BuildEventStreamProtos.BuildEvent buildEvent);
- }
-
/**
* Called by the {@link BuildEventServiceUploader} in case of error to asynchronously notify Bazel
* of an error.
diff --git a/src/main/java/com/google/devtools/build/lib/buildeventservice/BuildEventServiceUploader.java b/src/main/java/com/google/devtools/build/lib/buildeventservice/BuildEventServiceUploader.java
index 90b4181..140f2c8 100644
--- a/src/main/java/com/google/devtools/build/lib/buildeventservice/BuildEventServiceUploader.java
+++ b/src/main/java/com/google/devtools/build/lib/buildeventservice/BuildEventServiceUploader.java
@@ -23,12 +23,12 @@
import com.google.common.base.Preconditions;
import com.google.common.base.Throwables;
import com.google.common.collect.Iterables;
+import com.google.common.eventbus.EventBus;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.MoreExecutors;
import com.google.common.util.concurrent.SettableFuture;
-import com.google.devtools.build.lib.buildeventservice.BuildEventServiceTransport.BuildEventLogger;
import com.google.devtools.build.lib.buildeventservice.BuildEventServiceTransport.ExitFunction;
import com.google.devtools.build.lib.buildeventservice.BuildEventServiceUploaderCommands.AckReceivedCommand;
import com.google.devtools.build.lib.buildeventservice.BuildEventServiceUploaderCommands.EventLoopCommand;
@@ -47,6 +47,7 @@
import com.google.devtools.build.lib.buildeventstream.BuildEventContext;
import com.google.devtools.build.lib.buildeventstream.BuildEventProtocolOptions;
import com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos;
+import com.google.devtools.build.lib.buildeventstream.LargeBuildEventSerializedEvent;
import com.google.devtools.build.lib.buildeventstream.PathConverter;
import com.google.devtools.build.lib.clock.Clock;
import com.google.devtools.build.lib.util.ExitCode;
@@ -105,8 +106,8 @@
private final ExitFunction exitFunc;
private final Sleeper sleeper;
private final Clock clock;
- private final BuildEventLogger buildEventLogger;
private final ArtifactGroupNamer namer;
+ private final EventBus eventBus;
/**
* The event queue contains two types of events: - Build events, sorted by sequence number, that
@@ -157,8 +158,8 @@
ExitFunction exitFunc,
Sleeper sleeper,
Clock clock,
- BuildEventLogger buildEventLogger,
- ArtifactGroupNamer namer) {
+ ArtifactGroupNamer namer,
+ EventBus eventBus) {
this.besClient = Preconditions.checkNotNull(besClient);
this.localFileUploader = Preconditions.checkNotNull(localFileUploader);
this.besProtoUtil = Preconditions.checkNotNull(besProtoUtil);
@@ -168,8 +169,8 @@
this.exitFunc = Preconditions.checkNotNull(exitFunc);
this.sleeper = Preconditions.checkNotNull(sleeper);
this.clock = Preconditions.checkNotNull(clock);
- this.buildEventLogger = Preconditions.checkNotNull(buildEventLogger);
this.namer = namer;
+ this.eventBus = eventBus;
}
BuildEventArtifactUploader getLocalFileUploader() {
@@ -351,7 +352,16 @@
};
BuildEventStreamProtos.BuildEvent serializedBepEvent =
buildEvent.getEvent().asStreamProto(ctx);
- buildEventLogger.log(serializedBepEvent);
+
+ // TODO(lpino): Remove this logging once we can make every single event smaller than 1MB
+ // as protobuf recommends.
+ if (serializedBepEvent.getSerializedSize()
+ > LargeBuildEventSerializedEvent.SIZE_OF_LARGE_BUILD_EVENTS_IN_BYTES) {
+ eventBus.post(
+ new LargeBuildEventSerializedEvent(
+ serializedBepEvent.getId().toString(), serializedBepEvent.getSerializedSize()));
+ }
+
return serializedBepEvent;
}