Skip to content

events: populate BuildCompletedEvent.DurationMs#46

Merged
bilby91 merged 1 commit into
mainfrom
fix/build-duration-ms
May 12, 2026
Merged

events: populate BuildCompletedEvent.DurationMs#46
bilby91 merged 1 commit into
mainfrom
fix/build-duration-ms

Conversation

@bilby91
Copy link
Copy Markdown
Member

@bilby91 bilby91 commented May 12, 2026

Summary

  • BuildCompletedEvent.DurationMs was declared but never set in translateBuildEvent, so every completion event shipped with DurationMs=0 for all BuildSource values (image pull, dockerfile, compose, features, uid_reconcile).
  • Observed in DAP: a uid_reconcile build whose actual wall-clock was 158.8s was logged as took 0ms, masking the very problem under investigation.
  • Fix: stamp buildStart in BuildChan (resetting on every call, including same-source re-entry) and compute time.Since(start).Milliseconds() in translateBuildEvent on completion. Measuring in the bus rather than at each call site means one change covers all five build sources without touching useruid.go / up.go / etc.

Test plan

  • TestBuildCompletedEvent_DurationMs — single-source build records non-zero DurationMs after a 20ms sleep
  • TestBuildCompletedEvent_DurationMs_ResetsPerSource — second BuildChan call resets the timer; second build's duration is not inflated by the first build's elapsed time
  • Full go test ./... green

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Build completed events now capture and report build duration in milliseconds.
  • Tests

    • Added test coverage to validate build duration measurement accuracy and per-build reset behavior.

Review Change Stack

The DurationMs field was declared on BuildCompletedEvent but never set
in translateBuildEvent, so every completion event shipped with
DurationMs=0 regardless of actual wall-clock duration. Downstream
consumers logging this field saw misleading "took 0ms" for builds
that ran for minutes.

Measure duration in the event bus rather than at each call site: the
bus is the single chokepoint where every BuildSource converges
(image pull, dockerfile, compose, features, uid_reconcile), so one
change covers all sources. BuildChan stamps buildStart on every call
(resetting on same-source re-entry so each build is timed
independently); translateLoop forwards it to translateBuildEvent,
which computes time.Since(start).Milliseconds() on completion.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 12, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6d6b36d8-0e05-4450-9e79-558e4b81ee55

📥 Commits

Reviewing files that changed from the base of the PR and between a76b581 and 1fcff40.

📒 Files selected for processing (2)
  • eventbus.go
  • eventbus_test.go

📝 Walkthrough

Walkthrough

The PR adds wall-clock duration tracking to build completion events in the event bus. A per-build buildStart timestamp is captured on each BuildChan call, snapshotted during event translation, and used to compute elapsed milliseconds for BuildCompletedEvent. Two regression tests verify correct duration measurement and per-source timestamp reset.

Changes

Build event duration tracking

Layer / File(s) Summary
Build timestamp state and reset
eventbus.go
Import time package and add buildStart field to track the current build's start time. BuildChan resets the timestamp on each call.
Duration computation in event translation
eventbus.go
Translator loop snapshots buildStart under mutex and passes it to translateBuildEvent, which computes DurationMs from elapsed wall-clock time for BuildEventCompleted.
Regression tests and test helpers
eventbus_test.go
Two regression tests validate elapsed duration (sleep-based lower bound) and per-source reset (starting two builds confirms durations reset per build). Helper functions waitForCompleted and drainCompleted wait for and drain target BuildCompletedEvent by ImageID.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 The event bus now ticks and tracks,
Each build's start time recorded in facts,
DurationMs blooms on completion's dawn,
Timestamps reset when each new build is drawn,
Tests hop around to prove it's done just right!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and specifically describes the main change: populating the BuildCompletedEvent.DurationMs field that was previously unset.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/build-duration-ms

Comment @coderabbitai help to get the list of available commands and usage tips.

@bilby91 bilby91 merged commit 398d0c5 into main May 12, 2026
5 checks passed
@bilby91 bilby91 mentioned this pull request May 12, 2026
2 tasks
bilby91 added a commit that referenced this pull request May 12, 2026
Documents the BuildKit-switch / pre-pull bundle (#47), the
useruid frontend-directive drop (#48), the BuildCompletedEvent
duration fix (#46), and the dependabot CI bumps (#40-#42) under
their respective Keep a Changelog sections.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@bilby91 bilby91 deleted the fix/build-duration-ms branch May 14, 2026 13:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant