Nikasa, home Request an invite
DocsSaved baselines

Saved baselines

Keep the old build's runs, and a later compare of the same old build runs only the new one.

On this page

This is an optional speed-up. Compares work without it, and each one then runs the old build in full. With it, the measurement on the home page found each comparison after the first took about half the time. A first run does not need it.

Turn it on in CI #

A CI job starts with nothing, so it needs a stable key and a place to keep the runs.

  1. Make a secret key, once:

    shell
    openssl rand -hex 32
  2. Keep it as a CI secret, never in the repository or the cache.

  3. Give it to your CI, which then keeps the runs. The table shows how, and where:

CI Give the key as The runs are kept in
GitHub Actions The secret-key input The Actions cache, or your own storage
GitLab CI NK_CI_SECRET_KEY A baseline store
Jenkins The secretKeyId parameter Job Cacher or a store
Azure Pipelines NK_CI_SECRET_KEY Azure's cache or a store
Any other CI NK_CI_SECRET_KEY Your CI's cache or a store

On your machine #

Add --baseline to the compare, and name a folder:

shell
nk compare myapp:old myapp:new out --baseline .nk-baseline

The first compare saves the old build's runs in that folder. A later compare of the same old build reads them instead of running the old build again.

The secret key #

Nikasa shows secrets as markers keyed by one secret key. It also encrypts the outside calls in a saved baseline under a key derived from it.

A baseline saved under one secret key does not match a compare under another.

Where you run nk yourself #

The first nk compare makes this key and keeps it at $HOME/.config/nk/secret.key, so there is nothing to do.

In a CI job #

A CI job would make a new key each time. That is why you make one once and keep it as a CI secret.

Where neither of these fits, NK_SECRET_KEY_FILE names a file that holds the key.

In the GitHub Actions cache #

With secret-key set, the Action keeps the old build's runs in the repository's Actions cache. Each job does this:

  1. Key. It works out the baseline key. This pulls the old build's images first, as the compare would, so a cache hit still pays that pull.
  2. Restore. It finds the newest entry saved under nk-baseline-<key>-.
  3. Compare. It runs with --baseline and --baseline-expiry.
  4. Save. When Nikasa built, extended, checked or marked the baseline (what each means), it saves a new entry. GitHub never changes an entry once saved.

Where a shared baseline comes from #

A job restores caches saved on its own branch and on the default branch. A pull request also restores from its base branch.

A cache saved by a pull request helps only that pull request's re-runs. So a baseline that many pull requests share must be saved by a run on the default branch: the nightly workflow, a push to main, or the merge queue's base.

Limits #

  • GitHub keeps 10 GB of cache per repository.
  • GitHub removes an entry that nobody restored for 7 days. That removal is GitHub's own. It is not the check age below, though both are 7 days by default.
  • A saved baseline is a few MB for a small app, and up to about 100 MB for a large one.
  • A pull request from a fork gets no secrets, so it always runs in full.

Who can read it #

What a saved baseline holds #

A saved baseline holds:

  • what Nikasa read from each old run, with values masked;
  • each call to an outside host, encrypted.

It never holds the capture, TLS keys or logs. The security reference lists each file.

How it decides #

This section explains what makes a saved baseline match, how old it may be, and what changes it. You do not need it to turn a baseline on.

The baseline key #

The baseline key decides a match. It is a hash of everything that decides what an old run observes:

  • Nikasa's version;
  • the old build's images, by Docker image id;
  • the resolved compose files, and every file they bind-mount;
  • the driver, and its requests or pack;
  • the starting state;
  • the options that change what a run sees.

It also takes in a hash made with your secret key. So the same old build under another secret key gets another baseline key, and the secret key itself never reaches it.

The new build is not in the key.

When the key differs, the report says which part changed. The old runs are made again and replace what the folder held. A folder holds one baseline.

To see a key, run the compare with --print-baseline-key. It prints key=<hash> for the same arguments and runs nothing, so you can use it as a CI cache key.

Recorded tests use no saved baseline #

A job that records your tests makes a new pack each time, which never matches a saved one. So its compare makes its old runs. A compare with no recording keeps its saved baseline.

A compare that stopped early #

A compare that stopped early saves no baseline, and extends none. See When a compare stops early.

How old it may be #

--baseline-expiry sets the check age, how old a baseline may be. It defaults to 7 days.

A baseline that old is checked. One fresh old run is made and compared with the saved runs:

  • If it would count nothing, the baseline is kept, and its age starts again.
  • If it would count something, a second fresh old run is made, and only what both show counts. Then the baseline is made again in full.

The old runs it holds #

The compare that saves a baseline makes 8 old runs. That is the most a compare ever makes to confirm a change (How many runs). So a later compare that reads the baseline never makes old runs to confirm one.

A baseline that holds fewer gets the rest made and saved into it.

What changes a baseline #

A compare saves its baseline again after one of four things:

It What happened
Built one The old runs were made in full.
Extended one Runs were added to a baseline that held fewer than it should.
Checked one A fresh old run found nothing to count, and the baseline's age starts again.
Marked one The drift guard, below, found a counted change that the old build shows too. The baseline is checked at its next use.

The drift guard #

Something outside the images can change what the old build does within the check age. Examples are a date-based value, or an outside service reached live.

So before a compare that read a young baseline counts any change, one fresh old run is made. A counted change that it also shows is not counted. It is listed under this line:

output
changes the old build shows too now (drift since the baseline was saved)

--no-drift-guard turns this off.

What the report says #

A line under the header says how the baseline was used. It is one of these:

  • read;
  • checked and kept;
  • made again after a check;
  • made because none matched, and why.

report.json holds the same under baseline.

Next steps #

Written for nk 0.3.14. Something wrong or unclear? Write to hello@nikasa.dev.