Add support for the Build Event Protocol to BuildGrid
Before raising this MR, consider whether the following are required, and complete if so:
-
Unit tests -
Metrics -
Documentation update(s)
All three of these are required, but its still WIP.
Description
The PublishBuildEvent service allows Bazel (or other tools which implement it) to publish events describing notable moments in a build to assist in debugging.
This MR adds a basic in-memory implementation of this service to BuildGrid. It also adds a QueryBuildEvents service based on a custom proto, which allows querying of the stored Build Event streams by clients. This enables us to add functionality to bgd browser to support displaying these event streams on the correlated invocations view, providing more insight into the context and progress of builds which use the BEP.
Verification
To try this MR out, first make sure you have access to Bazel and a project buildable with Bazel (https://github.com/abseil/abseil-hello is a good simple project I've been using to test with), using whatever approach is appropriate.
Next, start the Bazel BuildGrid example,
docker-compose -f docker-compose.all-in-one.yml up
This will start an all-in-one BuildGrid with a disk-backed CAS (stored on a docker volume), an SQL-backed scheduler, an in-memory ActionCache, and an in-memory Build Events Service.
Now configure Bazel to use the Build Events Service provided by BuildGrid,
cat > ~/.bazelrc <<EOF
build --bes_results_url=http://localhost:8081/tool-invocation/ # The value here doesn't really matter, we won't be using it for now
build --bes_backend=grpc://localhost:50051
build --remote_cache=grpc://localhost:50051
build --noremote_upload_local_results # Uploads logs & artifacts without writing to cache
build --remote_timeout=3600
EOF
Now build your Bazel project. You can do a local build or a remote build, but keep in mind that a remote build will require your project to be buildable inside the buildgrid:local docker image that the worker is running in. If using abseil-hello, this means you need the same version of gcc in both that docker image and your host environment.
eg.
cd abseil-hello/bazel-hello
bazel run --remote_executor=grpc://localhost:50051 //:hello_main
Your BuildGrid logs should contain a bunch of information about the Build Events that were recorded. Part of this information is the build_id, which is also the correlated invocations ID of the Bazel command.
Start bgd browser-backend (leaving the docker-compose environment running) to test the next part of this work.
tox -e venv -- bgd browser-backend serve -p 8080 -v
The bgd-browser!54 (merged) MR adds support for the Build Events Service to the correlated invocations view. For this next step, checkout that MR in a local copy of the bgd-browser repo. Then, build and serve it using npm,
npm i
npm run serve
This will likely result in the UI being served at http://localhost:8081/, but if not the output of that command will point you to the location.
Find the correlated invocations ID (build_id part of the stream ID in any of the Build Event Stream log messages) in your BuildGrid logs, then navigate to http://localhost:8081/correlated-invocations/$correlated_invocations_id. There may or may not be a list of operations on this view, but the Build Events tab should be populated with a number of events containing various bits of information about your build. Any issues with the bgd-browser part of this work should be reported in bgd-browser!54 (merged).