Webhook icon
WorkingDirectory icon
Clone icon
Commands icon
Docker icon
OutputValues icon
Log icon
If icon
Comment icon
Fail icon

Block a Go pull request that makes benchmarks slower

Benchmark both sides of a Go pull request with Kestra, compare them with benchstat, comment the report on GitHub and block slow changes.

Categories
Infrastructure

A Go change can pass every test and still make a hot path twice as slow. Benchmarks catch that, but only when someone runs them on both sides of the change and reads the numbers with statistics, because a single run is mostly noise. This flow does it for every pull request: it benchmarks the base and the head on the same machine, compares them with benchstat, posts the table on the pull request, and fails the run when the code got slower than you allow.

It runs with no setup. The defaults compare two releases of google/uuid, a small pure Go library, which reads PASS. Set head_goflags to -gcflags=all=-N to build the head without compiler optimizations and watch the gate block it.

This blueprint was created by ashish6123.

How it works

  1. github_pull_request (io.kestra.plugin.core.trigger.Webhook) receives GitHub pull request events. Its when condition only starts a run for opened, reopened and synchronize; any other event gets a 204 and no execution. A manual run uses the inputs instead.
  2. clone_base and clone_head (io.kestra.plugin.git.Clone) check out both commits inside one WorkingDirectory. The head is cloned from the head repository, so pull requests from forks work.
  3. bench (io.kestra.plugin.scripts.shell.Commands, golang:1.26) runs go test -bench with count samples on each side in the same container, then compares them with a pinned benchstat. summarize.awk reads the sec/op table and returns the number of benchmarks, the geometric mean change, and the worst significant slowdown as outputs. The script only receives inputs, through env; nothing from the webhook body is placed in commands.
  4. verdict (io.kestra.plugin.core.output.OutputValues) reads REGRESSED when the geometric mean got slower than max_geomean_regression_pct, or when one significant change is above max_single_regression_pct. It reads NO_BENCHMARKS when nothing matched bench, and PASS otherwise.
  5. comment_on_pr (io.kestra.plugin.core.flow.If) posts the benchstat table on the pull request with io.kestra.plugin.github.issues.Comment. updateTag keeps a single comment that is updated on every push instead of a new one each time.
  6. gate ends the run as FAILED with io.kestra.plugin.core.execution.Fail on any verdict other than PASS.

What you get

  • A benchmark report on every pull request, kept in one comment.
  • A failed execution when the code got slower than allowed, which a required check or your CI can use to block the merge.
  • Two limits, so one noisy benchmark does not block a release while a large slowdown on a single hot path still does.
  • report.txt, base.txt and head.txt as execution outputs, ready to open in benchstat locally.

Who it's for

  • Go teams that maintain performance-sensitive libraries or services.
  • Platform teams that want a performance check next to unit tests without adding it to every CI pipeline.

Why orchestrate this with Kestra

  • Benchmarks take minutes, so they run outside the CI job that has to stay fast, with their own timeout and history.
  • Every run keeps its raw benchmark files, so a regression can be checked again later.
  • The same flow serves every repository: point another webhook at it.

Prerequisites

  • A Kestra worker that can run Docker containers.
  • For the pull request trigger, a GitHub webhook on the repository with the "Pull requests" event and content type application/json, pointing at /api/v1/main/executions/webhook/company.engineering/go-benchmark-regression-gate/<key>.
  • go test runs the code of the pull request, including pull requests from forks. Treat it like CI on untrusted code: run it on an isolated worker, and on a public repository consider adding the author's association to the when condition. The webhook key in the URL is the only authentication, so keep it secret.

Secrets

  • GITHUB_TOKEN: a token that can comment on pull requests in the repository. Only needed when a pull request number is known, which is always the case for webhook runs.

Quick start

  1. Run the flow with the defaults. It benchmarks google/uuid v1.5.0 against v1.6.0 in about 90 seconds and reads PASS, with an overall change of a few percent at most. On a busy machine that noise can come close to the 5% limit; raise max_geomean_regression_pct or count if it does.
  2. Run it again with head_goflags set to -gcflags=all=-N. The head is now built without optimizations, the overall change jumps above 100%, and the run reads REGRESSED and fails.
  3. To gate your own repository, add the GITHUB_TOKEN secret, replace the webhook key with a long random value, and create the GitHub webhook described in Prerequisites.

How to extend

  • Compare B/op and allocs/op the same way by adding -benchmem and reading those tables in summarize.awk.
  • Evaluate a build change on its own by keeping the same ref on both sides and setting head_goflags, for example -pgo=auto or -tags=purego.
  • Run on a dedicated worker group so benchmarks are not disturbed by other tasks.
  • Send the verdict to Slack or set a GitHub commit status.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.