Repository: bazelbuild/bazel
Issue: BEP: Add a config option for results base URL (feature request)
Labels: P1

When streaming results to a BEP endpoint, we should notify the user as to where they can view those results. (Currently, the user has to manually construct the URL from the invocation ID reported in Bazel CLI and a base URL of the BEP server.)

**Please add a flag:** `--results_url_base`

...this will be used like: `bazel build //... --results_url_base=https://example.com/results/invocations/`

when this flag is present, Bazel will print to the log (as soon as the invocation ID is known:)
`streaming results to ${results_url_base}${invocation_id}`

e.g. `streaming results to https://example.com/results/invocations/XXXX-YYYY-ZZZZ`

Issue comments:
We should expect that most users will want to specify this flag in a .bazelrc file
Over to @buchgr who wrote the current notification about streaming target and identifier.
Hi Dave,

I am not convinced that a flag is the right way to go about this. I think instead we should extend the BES protocol to be able to return a URL that the user can look at. This would be a much nicer user experience in my opinion. What do you think?
Ya I agree that would be ideal - but we discussed this idea with the BES team and they were not on board with it. BES does not know what the URL should be since it's up to the post processors of the BES data to generate results from it. For example, there could be multiple URLs or none depending on what's done with the data once it's uploaded to BES.

I think having as a convenience the ability to provide this via flag is the only path forward for now.
Thanks willsc79 for the background. @buchgr can we proceed to implement the flag?
Ping?
any update on this?
I apologize it slipped through my radar. Will implement asap.

Pull request review comments:

Patch that resolved the issue:
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 bc806be07cac74..e59707fac184f1 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
@@ -20,6 +20,7 @@
 import static java.lang.String.format;
 
 import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Strings;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableSet;
 import com.google.devtools.build.lib.authandtls.AuthAndTLSOptions;
@@ -218,11 +219,17 @@ private BuildEventTransport tryCreateBesTransport(
       logger.fine(format("Will create BuildEventServiceTransport streaming to '%s'",
           besOptions.besBackend));
 
-      commandLineReporter.handle(
-          Event.info(
-              format(
-                  "Streaming Build Event Protocol to %s build_request_id: %s invocation_id: %s",
-                  besOptions.besBackend, buildRequestId, invocationId)));
+      final String message;
+      if (!Strings.isNullOrEmpty(besOptions.besResultsUrl)) {
+        String url = besOptions.besResultsUrl.endsWith("/")
+            ? besOptions.besResultsUrl
+            : besOptions.besResultsUrl + "/";
+        message = "Streaming Build Event Protocol to " + url + invocationId;
+      } else {
+        message = format("Streaming Build Event Protocol to %s build_request_id: %s "
+                + "invocation_id: %s", besOptions.besBackend, buildRequestId, invocationId);
+      }
+      commandLineReporter.handle(Event.info(message));
 
       BuildEventTransport besTransport =
           new BuildEventServiceTransport(
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 0d1adae2430ed1..d32547e88dc96f 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
@@ -104,4 +104,15 @@ public class BuildEventServiceOptions extends OptionsBase {
             + "event, even if larger than the specified value."
   )
   public long besOuterrBufferSize;
+
+  @Option(
+      name = "bes_results_url",
+      defaultValue = "",
+      documentationCategory = OptionDocumentationCategory.LOGGING,
+      effectTags = {OptionEffectTag.TERMINAL_OUTPUT},
+      help = "Specifies the base URL where a user can view the information streamed to the BES backend. "
+          + "Bazel will output the URL appended by the invocation id to the terminal."
+
+  )
+  public String besResultsUrl;
 }


Test patch: