Skip to content

solver/llbsolver: emit native build-completion metrics - #6736

Merged
tonistiigi merged 2 commits into
moby:masterfrom
asbarron:asbarron/buildkit-build-metrics
Jun 3, 2026
Merged

tonistiigi merged 2 commits into
moby:masterfrom
asbarron:asbarron/buildkit-build-metrics

Conversation

@asbarron

@asbarron asbarron commented May 3, 2026

Copy link
Copy Markdown
Contributor

Threads the existing OTEL MeterProvider through llbsolver.Opt and emits three build-event instruments from the recordBuildHistory finalizer:

  • buildkit.builds (counter; labels: status, error_code)
  • buildkit.builds.steps (counter; labels: kind)
  • buildkit.build.duration (Base2 exponential histogram; labels: status)

The duration histogram uses an exponential aggregation, rendered as a Prometheus native histogram by the existing exporter, to avoid the "tens of millions of series" cardinality blow-up reported by #5777.

MeterProvider is passed explicitly through the constructor; buildkit policy (from the #4957 review) prohibits relying on the OTel global provider in library packages.

error_code uses gRPC codes.Code.String() for a bounded set; rec.Error.Message is intentionally never used as a label.

The frontend label is intentionally omitted because client.Build clears req.Frontend on the wire, so the field is empty for every caller that goes through the gateway-client API (buildctl, buildx). The metric is forward-compatible with a future buildkit change that populates rec.Frontend on that path.

A follow-up PR will add observable gauges for worker count and cache state, and an operator guide at docs/metrics.md.

Refs #1544; addresses discussion #5777.

@asbarron
asbarron marked this pull request as ready for review May 3, 2026 21:04
@tonistiigi
tonistiigi requested a review from jsternberg May 4, 2026 17:38
@github-actions github-actions Bot added the area/dependencies Pull requests that update a dependency file label May 5, 2026
@asbarron
asbarron force-pushed the asbarron/buildkit-build-metrics branch from 06abd34 to c2a5c1d Compare May 5, 2026 19:10

@jsternberg jsternberg left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few suggested changes but I like the direction this is going.

Comment thread solver/llbsolver/metrics.go Resolved
Comment thread solver/llbsolver/metrics.go Resolved
Comment thread solver/llbsolver/solver.go Resolved
@asbarron
asbarron force-pushed the asbarron/buildkit-build-metrics branch from c2a5c1d to 2784489 Compare May 23, 2026 00:53
@asbarron

asbarron commented May 23, 2026 •

Copy link
Copy Markdown
Contributor Author

Addressing @jsternberg's review feedback:

  • Extracted "status", "error_code", and "kind" attribute keys to typed attribute.Key constants so renames are compiler-checked and call sites use Key.String() helpers rather than raw attribute.String.
  • Extracted the corresponding attribute values ("success", "failure", "completed", "cached", "total", "warnings") to package-level const strings.
  • Dropped the multi-line comment on Opt.MeterProvider in solver/llbsolver/solver.go.

@asbarron
asbarron force-pushed the asbarron/buildkit-build-metrics branch from 2784489 to 1e3882e Compare May 23, 2026 01:04
@thompson-shaun thompson-shaun added this to the v0.31.0 milestone May 27, 2026
@jsternberg

Copy link
Copy Markdown
Collaborator

Please rebase and resolve the conflicts and then this should be good to go.

asbarron added 2 commits May 28, 2026 12:57
Threads the existing OTEL MeterProvider through llbsolver.Opt and emits
three build-event instruments from the recordBuildHistory finalizer:

  - buildkit.builds (counter; labels: status, error_code)
  - buildkit.builds.steps (counter; labels: kind)
  - buildkit.build.duration (Base2 exponential histogram; labels: status)

The duration histogram uses an exponential aggregation, rendered as a
Prometheus native histogram by the existing exporter, to avoid the
"tens of millions of series" cardinality blow-up reported in moby#5777.

MeterProvider is passed explicitly through the constructor — buildkit
policy (per the moby#4957 review) prohibits relying on the OTel global
provider in library packages.

error_code uses gRPC codes.Code.String() for a bounded set;
rec.Error.Message is intentionally never used as a label. The frontend
label is intentionally omitted — client.Build clears req.Frontend on
the wire, so the field is empty for every caller that goes through the
gateway-client API (buildctl, buildx). The metric is forward-compatible
with a future buildkit change that populates rec.Frontend on that path.

A follow-up PR will add observable gauges for worker count and cache
state, plus an operator guide at docs/metrics.md.

Refs moby#1544; addresses discussion moby#5777.

Signed-off-by: Ava Barron <abarron@coreweave.com>
Signed-off-by: Ava Barron <abarron@coreweave.com>
@asbarron
asbarron force-pushed the asbarron/buildkit-build-metrics branch from 1e3882e to d89811c Compare May 28, 2026 16:59
@asbarron
asbarron requested a review from jsternberg June 1, 2026 16:21
@tonistiigi
tonistiigi merged commit d66f849 into moby:master Jun 3, 2026
192 checks passed
chagui added a commit to chagui/buildkit that referenced this pull request Jul 22, 2026
Adds buildkit.active_solves, an asynchronous observable gauge reporting
the count of currently in-flight non-internal Solve RPCs. The metric is
intended as a live, per-pod autoscaling signal: every existing buildkit
metric either lags long solves (RPC counters fire only at completion,
including the buildkit.builds counter introduced in moby#6736) or sits at a
fixed pool size (goroutine, thread, runc worker counts).

The gauge is backed by an atomic.Int64 on buildMetrics, incremented at
Solver.Solve entry and decremented via defer. Internal sub-solves (gateway
frontends invoking the solver recursively) are excluded to avoid
double-counting work that nests under a parent RPC.

The instrument is registered against the MeterProvider plumbed through
llbsolver.Opt by moby#6736; the OTel global provider is intentionally not
used, per buildkit library-package policy.

Stacks on moby#6736.

Signed-off-by: Guilhem Charles <guilhem.charles@gmail.com>
asbarron added a commit to asbarron/buildkit that referenced this pull request Aug 13, 2026
Adds docs/metrics.md documenting the OpenTelemetry metric instruments
exported by buildkitd (the build-completion metrics from moby#6736) and how
to scrape them over Prometheus (--debugaddr /metrics) or OTLP, linked
from the README.

Refs moby#1544

Signed-off-by: Ava Barron <abarron@coreweave.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants