Skip to content

Commit

Permalink
Add BESModule#constructAndMaybeReportBuildRequestIdUrl to print infor…
Browse files Browse the repository at this point in the history
…mation about the build_request_id.

PiperOrigin-RevId: 236413267
  • Loading branch information
lfpino authored and copybara-github committed Mar 2, 2019
1 parent 326eb1a commit 1bc7d14
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,9 @@ protected String getInvocationIdPrefix() {
? besOptions.besResultsUrl
: besOptions.besResultsUrl + "/";
}

@Override
protected String getBuildRequestIdPrefix() {
return "";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public abstract class BuildEventServiceModule<BESOptionsT extends BuildEventServ
private BuildEventStreamOptions besStreamOptions;
private ImmutableSet<BuildEventTransport> bepTransports;
private String invocationId;
private String buildRequestId;
private EventHandler cmdLineReporter;

protected BESOptionsT besOptions;
Expand Down Expand Up @@ -110,6 +111,7 @@ public Iterable<Class<? extends OptionsBase>> getCommonCommandOptions() {
@Override
public void beforeCommand(CommandEnvironment cmdEnv) {
this.invocationId = cmdEnv.getCommandId().toString();
this.buildRequestId = cmdEnv.getBuildRequestId();
this.cmdLineReporter = cmdEnv.getReporter();
// Reset to null in case afterCommand was not called.
// TODO(lpino): Remove this statement once {@link BlazeModule#afterCommmand()} is guaranteed
Expand Down Expand Up @@ -229,7 +231,18 @@ private void constructAndMaybeReportInvocationIdUrl() {
}
}

private void constructAndReportIds(String buildRequestId) {
private void constructAndMaybeReportBuildRequestIdUrl() {
if (!getBuildRequestIdPrefix().isEmpty()) {
cmdLineReporter.handle(
Event.info(
"See "
+ getBuildRequestIdPrefix()
+ buildRequestId
+ " for more information about your request."));
}
}

private void constructAndReportIds() {
cmdLineReporter.handle(
Event.info(
String.format(
Expand All @@ -248,7 +261,7 @@ private BuildEventServiceTransport createBesTransport(
return null;
}

constructAndReportIds(cmdEnv.getBuildRequestId());
constructAndReportIds();

final BuildEventServiceClient besClient;
try {
Expand All @@ -265,8 +278,8 @@ private BuildEventServiceTransport createBesTransport(

BuildEventServiceProtoUtil besProtoUtil =
new BuildEventServiceProtoUtil.Builder()
.buildRequestId(cmdEnv.getBuildRequestId())
.invocationId(cmdEnv.getCommandId().toString())
.buildRequestId(buildRequestId)
.invocationId(invocationId)
.projectId(besOptions.projectId)
.commandName(cmdEnv.getCommandName())
.keywords(getBesKeywords(besOptions, cmdEnv.getRuntime().getStartupOptionsProvider()))
Expand Down Expand Up @@ -387,6 +400,7 @@ private ImmutableSet<BuildEventTransport> createBepTransports(
createBesTransport(cmdEnv, uploaderSupplier, artifactGroupNamer);
if (besTransport != null) {
constructAndMaybeReportInvocationIdUrl();
constructAndMaybeReportBuildRequestIdUrl();
bepTransportsBuilder.add(besTransport);
}

Expand All @@ -413,6 +427,9 @@ protected Set<String> getBesKeywords(
/** A prefix used when printing the invocation ID in the command line */
protected abstract String getInvocationIdPrefix();

/** A prefix used when printing the build request ID in the command line */
protected abstract String getBuildRequestIdPrefix();

// TODO(b/115961387): This method shouldn't exist. It only does because some tests are relying on
// the transport creation logic of this module directly.
@VisibleForTesting
Expand Down

0 comments on commit 1bc7d14

Please sign in to comment.