blob: e1a3c50877d5728b8d7c3b7eaf7bd60655771788 [file] [view]
# Sample builds (baseline builds) in Fuchsia Infra
This guide explains how to find existing **sample builds** (also called
**baseline builds**), how to identify and order the revisions they tested, and
how to trigger new sample builds in Fuchsia Infra. It is intended as a
reference for people and AI agents and as a specification for programmatic
tooling (such as subcommands in [perfcompare.py](perfcompare.py)).
## Overview
Performance tests often exhibit variation across boots of the system. Normal
CI and CQ builds run each test shard once (`runs_per_shard=1`), which is
insufficient for calculating statistically significant confidence intervals on
a single revision.
A **sample build** is a Fuchsia Infra build that:
* Runs against a clean `integration.git` commit (no Gerrit CL applied).
* Runs each test shard multiple times across separate boots
(`runs_per_shard >= 5`, conventionally 5).
Reusing an existing sample build as a `without_cl` baseline avoids re-building
and re-running the baseline in every `perfcompare` tryjob, reducing Infra
capacity usage and turnaround time.
## Finding existing sample builds
There are three routes for finding existing sample builds, plus general search
options when looking for any revision with 5+ test runs.
### Route 1: Listing `global.sample` builds
Fuchsia Infra defines a `global.sample` bucket with builders that are
triggered regularly by LUCI Scheduler and which use `runs_per_shard=5`.
Example of listing recent `global.sample` builds for a builder using `bb ls`:
```sh
./prebuilt/tools/buildbucket/bb ls -n 20 -status success \
-fields id,status,create_time,input.gitiles_commit,input.properties,output.properties \
-json fuchsia/global.sample/terminal.x64-release
```
### Route 2: Listing `try`/`global.try` builds
Sample builds can also be triggered on demand on try builders
(`fuchsia/try/<builder>` or `turquoise/global.try/<builder>`).
#### Fast lookup using the `perfcompare_sample_build` tag
Sample builds triggered via `bb add` should include
`-t perfcompare_sample_build:`. You can filter directly on this tag using
`bb ls`. Example:
```sh
./prebuilt/tools/buildbucket/bb ls -n 20 -t perfcompare_sample_build: -status success \
-fields id,status,create_time,tags,input.gitiles_commit,input.gerrit_changes,input.properties,output.properties \
-json fuchsia/try/terminal.x64-release
```
Because `perfcompare_sample_build:` is only a convention and its meaning is
not enforced, callers should still apply the validation checks from the
general search section below.
#### General search for revisions with `>= 5` test runs
When searching more broadly for any build with `runs_per_shard >= 5` (including
untagged sample builds or historical `run_sample_builds.py` runs), query
`<project>/try/<builder>` or `<project>/global.try/<builder>` via `bb ls` and
check:
1. **Sample size:** `input.properties.runs_per_shard >= 5`.
2. **Clean baseline revision:** Only use builds where `input.gerritChanges`
in the JSON output (`input.gerrit_changes` in `-fields`) is absent or
empty, meaning no CL was applied. (`bb -json` outputs proto3 JSON with
lowerCamelCase keys such as `createTime`, `input.gitilesCommit`, and
`input.gerritChanges`, and omits empty repeated fields.)
3. **Usable metrics outputs:** `output.properties` contains `cas_instance` and
`perf_dataset_digest`, or `steps` contains task-output CAS links for partial
recovery.
### Route 3: `sample_builds_state.json` (deprecated)
`run_sample_builds.py` in the internal performance tools triggers daily builds
using `runs_per_shard=5` on `try` and `global.try` builders and records their
IDs in a Google-internal JSON file,
`/google/data/ro/teams/tq-performance/sample_builds_state.json`.
Each top-level key is a `YYYY-MM-DD` date containing `rev_info` (`commit_id`,
`public_commit_id`, `rev_num`, `commit_time`) and
`launched.<builder>.build_id`. Because `sample_builds_state.json` only records
launch-time status, callers must still run `bb get` to verify
`status == "SUCCESS"`.
## Finding the revisions used by sample builds
When choosing among sample builds (for example, finding the most recent sample
build or matching a revision range), one should not rely on the Buildbucket
`createTime` field (`create_time` in `-fields`), because manually triggered or
backfilled sample builds on older revisions may have newer creation times.
### Relevant build output properties
Check `output.properties` (from `bb get` or `bb ls`):
* **`got_revision`**: String containing the `integration.git` commit ID
actually checked out and tested by the build. Prefer `got_revision` over
`input.gitilesCommit.id` (and you can check
`output.properties.checkout_info.manifest_remote` if you need to know whether
the commit is from public `integration.git` or internal `integration.git`).
* **`integration-revision-count`**: Integer equal to
`git rev-list --count <got_revision>` in `integration.git` (a 1-based ancestor
count).
* For commits on the `main` branch (`refs/heads/main`),
`integration-revision-count` should match the commit position number in the
commit's `Cr-Commit-Position: refs/heads/main@{#<N>}` footer.
* **Caveat for non-`main` commits:** Because `git rev-list --count` counts
all ancestors of `<got_revision>`, a commit on a release branch or other
side branch that branched from `main` at `#N` and added `k` commits will
report `integration-revision-count = N + k`. That number can collide with or
appear newer than commits on `main`, so `integration-revision-count` alone
is misleading unless you verify the commit is on `main`.
* **Public vs. internal counts:** Public `fuchsia` builders check out the
public `integration.git`, while internal `turquoise` builders check out the
internal `integration.git` (which has additional internal commits). Avoid
comparing `got_revision` commit IDs or `integration-revision-count` values
directly across public and internal repositories.
### Checking commit times, commit positions, and `main`-branch membership
Given `<got_revision>` from `output.properties`, in a local `integration.git`
checkout (with `origin/main` fetched):
* Use `git show` to inspect the commit timestamp and commit message (including
any `Cr-Commit-Position:` footer).
* Use `git merge-base --is-ancestor` to check whether `<got_revision>` is an
ancestor of `origin/main` (i.e. whether the commit is on the `main` branch).
### Ordering revisions
1. Filter out builds whose `got_revision` is not on `refs/heads/main` (unless
explicitly looking for release-branch builds).
2. Within a single repository (public or internal `integration.git`), order
`main`-branch builds by their `Cr-Commit-Position` number (or
`integration-revision-count` once `main` membership is verified) descending
to find the most recent revision tested.
3. Do not rely on commit timestamps to order revisions, because multiple commits
can share the same commit timestamp. Commit timestamps can still be useful
for checking approximate revision age.
## Running New Sample Builds
### Triggering a sample build with `bb add`
Trigger manual or tool-initiated sample builds on `fuchsia/try/<builder>` or
`turquoise/global.try/<builder>` (**not** on `global.sample`, where
`BUILDBUCKET_TRIGGERER` permission is restricted to CI and LUCI Scheduler
service accounts).
Include the `-t perfcompare_sample_build:` tag so these builds are easy to
identify in LUCI and efficient to query later with `bb ls -t perfcompare_sample_build:`.
* **Public `fuchsia` builder:**
```sh
./prebuilt/tools/buildbucket/bb add -json \
-commit "https://fuchsia.googlesource.com/integration/+/<public_commit_id>" \
-ref refs/heads/main \
-t perfcompare_sample_build: \
-p runs_per_shard=5 \
-p perf_tests_only=true \
"fuchsia/try/<builder>"
```
* **Internal `turquoise` builder:**
```sh
./prebuilt/tools/buildbucket/bb add -json \
-commit "https://turquoise-internal.googlesource.com/integration/+/<commit_id>" \
-ref refs/heads/main \
-t perfcompare_sample_build: \
-p runs_per_shard=5 \
-p perf_tests_only=true \
"turquoise/global.try/<builder>"
```
Notes on `bb add` options:
* **`-commit` and `-ref`:** `-commit` must reference an `integration.git`
commit (not a `fuchsia.git` commit). Pass `-ref refs/heads/main` explicitly
when targeting `main`, because `bb add` defaults `-ref` to
`refs/heads/master`, which can cause bugs in LUCI Analysis (see
[https://fxbug.dev/530231392](https://fxbug.dev/530231392)).
* **`-p runs_per_shard=5`:** Sets the number of boots/runs per test shard (5 or
greater). Note that `bb add -p` parses valid JSON, so `5` is passed as an
integer.
* **`-p perf_tests_only=true`:** Optional, recommended when only performance
metrics are needed. It filters test tasks to shards containing performance
tests (the same filtering used by `perfcompare=true`), saving capacity and
avoiding unrelated test flakes.
* **Waiting for completion:** Use `bb collect` on the returned build ID to wait
for the build to finish.
* **Quiet hours:** When triggering large numbers of sample builds (especially on
scarce hardware pools), prefer off-peak hours (e.g. outside normal US working
hours).
### Testing a Gerrit CL against an existing sample build
`perfcompare.py perfcompare_cl` automates running a try build for a CL on the
same `integration.git` revision as an existing sample build and comparing the
two datasets:
```sh
fuchsia-vendored-python src/testing/perfcompare/perfcompare.py perfcompare_cl \
--builder <builder> --project <fuchsia|turquoise> <gerrit_url>
```
Note: `perfcompare_cl` (like `download_baseline`) currently discovers baselines
only from `sample_builds_state.json` (Route 3) via `_find_sample_build()` in
[local_workflow.py](local_workflow.py), so it does not yet find
`global.sample` or `perfcompare_sample_build:` builds and raises
`FileNotFoundError` if `sample_builds_state.json` is unavailable.