Add --timings phase logs and named-env deploys #3

Merged
benvin merged 21 commits from benvin/timings into main 2026-11-08 21:55:08 +11:00
Member

Slow deploys give no hint where the time goes, and deploy <env> touched environments it was not asked for.

  • add --timings: one slog timing line per phase (lock, source, env, module, gc, run summary) with dur
  • label module phases cache=hit, miss or shared; keep unfinished flights across concurrent Deploys
  • report -j slot and worktree lock waits as wait on leaf phases only
  • count panics and source errors as failed in the run summary
  • resolve named deploys by env or branch across all sources; skip purge and GC for them
  • warn about corrected branch names only for envs being deployed
  • return gentypes.Generate counts as Stats
Slow deploys give no hint where the time goes, and `deploy <env>` touched environments it was not asked for. - add `--timings`: one slog `timing` line per phase (lock, source, env, module, gc, run summary) with `dur` - label module phases `cache=hit`, `miss` or `shared`; keep unfinished flights across concurrent Deploys - report `-j` slot and worktree lock waits as `wait` on leaf phases only - count panics and source errors as `failed` in the run summary - resolve named deploys by env or branch across all sources; skip purge and GC for them - warn about corrected branch names only for envs being deployed - return `gentypes.Generate` counts as `Stats`
Author
Member
  • internal/deploy/deploy.go:190 — named deploys skip GC, so a worktree they revive keeps its old gc mark; the next full deploy that replaces it deletes it with no grace (repro: TestNamedDeployRevivedWorktreeKeepsGrace below; passes on base, fails here; module dirs too) → on a named deploy, drop gc marks for the swapped-in worktree and its module dirs
  • internal/deploy/timing.go:26 — addWait adds every goroutine's slot wait to all ancestors, so run/env.total wait is summed across goroutines (seen run: wait 1.12s, dur 250ms at -j1, 9 envs) → add wait only to the innermost span, or rename it so it is not read as wall time
  • internal/deploy/deploy_test.go:797 — asserts gc state is byte-identical after a named deploy, which locks in the bug above → assert that live paths are unmarked instead
  • Scope: split into
    • --timings + gentypes.Stats
    • named-deploy scoping (Matches, filtered Environments, skip purge/GC) + completion. Completion is also not in the why
  • nit: internal/deploy/deploy.go:543 — module.download dur excludes wait, but every other phase's dur includes it → make them consistent
  • nit: internal/deploy/deploy.go:472 — present(dir) stats every git module even with --timings off → only compute it when d.Timings != nil
  • nit: TestTimingsPhases only greps for keys → also assert wait <= dur, and that there is no output with Timings nil
func TestNamedDeployRevivedWorktreeKeepsGrace(t *testing.T) {
	f := newFixture(t)
	a := commit(t, f.control, map[string]string{"Puppetfile": f.puppetfile(), "manifests/site.pp": "node a {}\n"})
	f.mustDeploy(false)
	wa := f.env("main")
	commit(t, f.control, map[string]string{"manifests/site.pp": "node b {}\n"})
	f.mustDeploy(false)
	f.clock = f.clock.Add(11 * time.Minute)
	gitT(t, f.control, "reset", "-q", "--hard", a)
	if err := f.deploy(false, "main"); err != nil || f.env("main") != wa {
		t.Fatalf("named deploy must revive wa: %v", err)
	}
	commit(t, f.control, map[string]string{"manifests/site.pp": "node c {}\n"})
	f.mustDeploy(false)
	if !exists(wa) {
		t.Fatal("replaced worktree GC'd on a stale mark; grace skipped")
	}
}
- internal/deploy/deploy.go:190 — named deploys skip GC, so a worktree they revive keeps its old gc mark; the next full deploy that replaces it deletes it with no grace (repro: `TestNamedDeployRevivedWorktreeKeepsGrace` below; passes on base, fails here; module dirs too) → on a named deploy, drop gc marks for the swapped-in worktree and its module dirs - internal/deploy/timing.go:26 — `addWait` adds every goroutine's slot wait to all ancestors, so `run`/`env.total` wait is summed across goroutines (seen `run: wait 1.12s, dur 250ms` at `-j1`, 9 envs) → add wait only to the innermost span, or rename it so it is not read as wall time - internal/deploy/deploy_test.go:797 — asserts gc state is byte-identical after a named deploy, which locks in the bug above → assert that live paths are unmarked instead - Scope: split into - `--timings` + `gentypes.Stats` - named-deploy scoping (`Matches`, filtered `Environments`, skip purge/GC) + completion. Completion is also not in the why - nit: internal/deploy/deploy.go:543 — `module.download` dur excludes wait, but every other phase's dur includes it → make them consistent - nit: internal/deploy/deploy.go:472 — `present(dir)` stats every git module even with `--timings` off → only compute it when `d.Timings != nil` - nit: TestTimingsPhases only greps for keys → also assert wait <= dur, and that there is no output with Timings nil ```go func TestNamedDeployRevivedWorktreeKeepsGrace(t *testing.T) { f := newFixture(t) a := commit(t, f.control, map[string]string{"Puppetfile": f.puppetfile(), "manifests/site.pp": "node a {}\n"}) f.mustDeploy(false) wa := f.env("main") commit(t, f.control, map[string]string{"manifests/site.pp": "node b {}\n"}) f.mustDeploy(false) f.clock = f.clock.Add(11 * time.Minute) gitT(t, f.control, "reset", "-q", "--hard", a) if err := f.deploy(false, "main"); err != nil || f.env("main") != wa { t.Fatalf("named deploy must revive wa: %v", err) } commit(t, f.control, map[string]string{"manifests/site.pp": "node c {}\n"}) f.mustDeploy(false) if !exists(wa) { t.Fatal("replaced worktree GC'd on a stale mark; grace skipped") } } ```
unkin-agent changed title from Add --timings phase logs and scope named deploys to Add --timings phase logs 2026-11-08 20:30:56 +11:00
Author
Member
  • internal/deploy/deploy.go:494 — a follower of an in-flight once is labelled cache=hit though its dur is the leader's work (cold cachedir: module.fetch module=bind cache=hit dur=32ms); same at :539, :555, :591 → label followers cache=shared (or miss); keep hit for "already complete before this run"
  • internal/deploy/deploy_test.go:819 — tests miss regressions: dropping s.wait.Add (timing.go) and inverting the :539/:591 labels both pass TestTimings*; waits == 0 (:866) passes on all-0s waits → assert a non-zero wait on a phase() leaf at -j1, and per-module miss on a cold run / hit on a warm run
  • nit: internal/deploy/deploy.go:514 — git module.resolve cache label is "module dir already complete", not a resolve cache (rev-parse always runs), duplicating module.worktree → drop it
  • nit: internal/deploy/deploy.go:377 — a panic in deployEnv is counted outcome=unchanged (defer runs before the recover in deploySource, err still nil); source fetch/branch errors never reach failed → count failures where they are recovered/returned
- internal/deploy/deploy.go:494 — a follower of an in-flight `once` is labelled `cache=hit` though its `dur` is the leader's work (cold cachedir: `module.fetch module=bind cache=hit dur=32ms`); same at :539, :555, :591 → label followers `cache=shared` (or `miss`); keep `hit` for "already complete before this run" - internal/deploy/deploy_test.go:819 — tests miss regressions: dropping `s.wait.Add` (timing.go) and inverting the :539/:591 labels both pass `TestTimings*`; `waits == 0` (:866) passes on all-`0s` waits → assert a non-zero `wait` on a `phase()` leaf at `-j1`, and per-module `miss` on a cold run / `hit` on a warm run - nit: internal/deploy/deploy.go:514 — git `module.resolve` cache label is "module dir already complete", not a resolve cache (rev-parse always runs), duplicating `module.worktree` → drop it - nit: internal/deploy/deploy.go:377 — a panic in `deployEnv` is counted `outcome=unchanged` (defer runs before the recover in deploySource, `err` still nil); source fetch/branch errors never reach `failed` → count failures where they are recovered/returned
Author
Member
  • internal/deploy/deploy.go:232 — clear(d.flights) drops in-flight entries, so a concurrent Deploy on the same Deployer redoes work already in flight (repro below: module mirror fetched 2x; passes on the base branch). It is also an unlisted behaviour change with timings off → prune only completed flights (maps.DeleteFunc on <-f.done), add the repro test, list the change in the PR body.
  • internal/deploy/deploy_test.go:867 — values are only checked for key presence. The suite still passes with: no attr inheritance (timing.go:39, so module lines lose env=), d.count("removed") removed (deploy.go:757), g.marked++/g.removed++ removed (deploy.go:798/812), --timings not wired (main.go:49) → assert env= on module.* lines, the removed/marked counts, and the flag wiring.
  • nit: internal/deploy/deploy.go:102 — the suite still passes with worked: false, which labels a panicking flight cache=hit → assert cache=miss for a panicking module.
  • nit: internal/deploy/git.go:36 — time spent waiting on the per-mirror worktree mutex lands in dur, not wait, so a serialized env.worktree looks like slow git → add it to wait.

Repro (internal/deploy, fails at 4edc423):

func TestConcurrentDeploySharesInFlightFetch(t *testing.T) {
	f := newFixture(t)
	commit(t, f.control, map[string]string{"Puppetfile": f.puppetfile()})
	d := f.deployer()
	var src, mod atomic.Int32
	b := make(chan struct{})
	var once sync.Once
	d.runGit = func(ctx context.Context, dir string, args ...string) (string, error) {
		if slices.Contains(args, "fetch") {
			if slices.Contains(args, f.control) && src.Add(1) == 2 {
				once.Do(func() { close(b) })
			}
			if slices.Contains(args, f.mod) && mod.Add(1) == 1 {
				<-b
			}
		}
		return runGit(ctx, dir, args...)
	}
	errc := make(chan error, 2)
	go func() { errc <- d.Deploy(context.Background(), nil, false) }()
	for mod.Load() == 0 {
		runtime.Gosched()
	}
	go func() { errc <- d.Deploy(context.Background(), nil, false) }()
	<-errc
	<-errc
	if n := mod.Load(); n != 1 {
		t.Fatalf("module mirror fetched %d times", n)
	}
}
- internal/deploy/deploy.go:232 — `clear(d.flights)` drops in-flight entries, so a concurrent `Deploy` on the same Deployer redoes work already in flight (repro below: module mirror fetched 2x; passes on the base branch). It is also an unlisted behaviour change with timings off → prune only completed flights (`maps.DeleteFunc` on `<-f.done`), add the repro test, list the change in the PR body. - internal/deploy/deploy_test.go:867 — values are only checked for key presence. The suite still passes with: no attr inheritance (timing.go:39, so module lines lose `env=`), `d.count("removed")` removed (deploy.go:757), `g.marked++`/`g.removed++` removed (deploy.go:798/812), `--timings` not wired (main.go:49) → assert `env=` on module.* lines, the removed/marked counts, and the flag wiring. - nit: internal/deploy/deploy.go:102 — the suite still passes with `worked: false`, which labels a panicking flight `cache=hit` → assert `cache=miss` for a panicking module. - nit: internal/deploy/git.go:36 — time spent waiting on the per-mirror worktree mutex lands in `dur`, not `wait`, so a serialized `env.worktree` looks like slow git → add it to `wait`. Repro (internal/deploy, fails at 4edc423): ```go func TestConcurrentDeploySharesInFlightFetch(t *testing.T) { f := newFixture(t) commit(t, f.control, map[string]string{"Puppetfile": f.puppetfile()}) d := f.deployer() var src, mod atomic.Int32 b := make(chan struct{}) var once sync.Once d.runGit = func(ctx context.Context, dir string, args ...string) (string, error) { if slices.Contains(args, "fetch") { if slices.Contains(args, f.control) && src.Add(1) == 2 { once.Do(func() { close(b) }) } if slices.Contains(args, f.mod) && mod.Add(1) == 1 { <-b } } return runGit(ctx, dir, args...) } errc := make(chan error, 2) go func() { errc <- d.Deploy(context.Background(), nil, false) }() for mod.Load() == 0 { runtime.Gosched() } go func() { errc <- d.Deploy(context.Background(), nil, false) }() <-errc <-errc if n := mod.Load(); n != 1 { t.Fatalf("module mirror fetched %d times", n) } } ```
benvin changed target branch from benvin/generate-types to main 2026-11-08 21:42:14 +11:00
benvin added 7 commits 2026-11-08 21:42:14 +11:00
Test named deploys and timing phase keys
ci/woodpecker/pr/build Pipeline was successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/pr/lint Pipeline was successful
ci/woodpecker/pr/pre-commit Pipeline was successful
e7c72ed2d7
Report wait on leaf phases only and include it in module.download
ci/woodpecker/pr/build Pipeline was successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/pr/pre-commit Pipeline was successful
ci/woodpecker/pr/lint Pipeline was successful
55224fd9f7
# Conflicts:
#	internal/deploy/deploy.go
#	internal/deploy/deploy_test.go
#	internal/deploy/git.go
Merge remote-tracking branch 'origin/benvin/generate-types' into benvin/timings
ci/woodpecker/pr/build Pipeline was successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/pr/pre-commit Pipeline was successful
ci/woodpecker/pr/lint Pipeline was successful
ba06c3bae7
# Conflicts:
#	internal/deploy/deploy.go
#	internal/gentypes/generate.go
#	internal/gentypes/generate_test.go
Label waiters on in-flight work cache=shared and count panics as failed
ci/woodpecker/pr/build Pipeline was successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/pr/pre-commit Pipeline was successful
ci/woodpecker/pr/lint Pipeline was successful
4edc42329c
- report cache=shared for callers that waited on another's once work
- drop the git module.resolve cache label
- recover deployEnv panics before its outcome is recorded
- count source fetch and branch errors as failed
benvin added 9 commits 2026-11-08 21:46:18 +11:00
Clear GC marks for worktrees and modules a named deploy swaps in
ci/woodpecker/pr/build Pipeline was successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/pr/pre-commit Pipeline was successful
ci/woodpecker/pr/lint Pipeline was successful
7d457a89cf
Merge remote-tracking branch 'origin/benvin/timings' into benvin/named-deploy
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/pr/build Pipeline was successful
ci/woodpecker/pr/lint Pipeline was successful
ci/woodpecker/pr/pre-commit Pipeline was successful
09f84fd752
Merge remote-tracking branch 'origin/benvin/timings' into benvin/named-deploy
ci/woodpecker/pr/build Pipeline was successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/pr/pre-commit Pipeline was successful
ci/woodpecker/pr/lint Pipeline was successful
94bcdc19f4
# Conflicts:
#	internal/deploy/deploy.go
# Conflicts:
#	internal/deploy/deploy.go
#	internal/deploy/forge.go
# Conflicts:
#	internal/deploy/deploy_test.go
- pick env winners over every branch, then select, so a named deploy matches a full deploy
- match env names across sources first, raw branch names only when no env matches
- report collision and invalid-name errors only for the named args
- add tests for collision losers, all-corrected collisions, prefixed sources and unrelated invalid branches
Warn about corrected branch names only for envs being deployed
ci/woodpecker/pr/build Pipeline was successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/pr/pre-commit Pipeline was successful
ci/woodpecker/pr/lint Pipeline was successful
260dd4fc78
Merge pull request 'Scope named deploys to their environments' (#4) from benvin/named-deploy into benvin/timings
ci/woodpecker/pr/build Pipeline was successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/pr/pre-commit Pipeline was successful
ci/woodpecker/pr/lint Pipeline was successful
00199db589
Reviewed-on: #4
unkin-agent added 5 commits 2026-11-08 21:49:29 +11:00
# Conflicts:
#	internal/deploy/deploy.go
#	internal/deploy/forge.go
Merge remote-tracking branch 'origin/benvin/timings' into benvin/timings
ci/woodpecker/pr/build Pipeline was successful
ci/woodpecker/pr/pre-commit Pipeline was successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/pr/lint Pipeline was successful
df0d8ff9f3
# Conflicts:
#	internal/deploy/deploy.go
unkin-agent changed title from Add --timings phase logs to Add --timings phase logs and named-env deploys 2026-11-08 21:51:16 +11:00
benvin merged commit f105326b6a into main 2026-11-08 21:55:08 +11:00
benvin deleted branch benvin/timings 2026-11-08 21:55:09 +11:00
This repo is archived. You cannot comment on pull requests.