Git designed for AI agents.
PLAN11: measure the identity lookup and the land intents
Federico Eliae5ddb4043f4b
diff --git a/doc/graft/LAND-BATCHING.md b/doc/graft/LAND-BATCHING.mdindex 826d001..5b2d4e6 100644--- a/doc/graft/LAND-BATCHING.md+++ b/doc/graft/LAND-BATCHING.md@@ -400,9 +400,10 @@ The batch executor (`internal/gitaly/service/operations`) defines:attempt. The phases are `quarantine` (opening the quarantine and the processesof the attempt), `tip` (reading the branch tip), `land_member` (oneobservation per request the stepper lands, in every attempt, denied,- conflicting and already-landed requests included), `plan` and `replay` (parts- of `land_member`: the range listing and decision of a request, and the replay- of a rebased request), `pack` (packing the objects of an attempt before its+ conflicting and already-landed requests included), `plan`, `identity` and+ `replay` (parts of `land_member`: the range listing and decision of a request,+ the lookup of the earlier land of a diverged request ([PLAN11](PLAN11.md)), and+ the replay of a rebased request), `pack` (packing the objects of an attempt before itsupdate), `update` (the CAS and its hooks) and `total` (one observation perexecution of the batch, which covers all of its attempts, rebuilds andfallbacks).@@ -411,6 +412,11 @@ The batch executor (`internal/gitaly/service/operations`) defines:- `graft_land_batch_members_total{outcome}` (counter): requests by outcome, withthe outcomes `landed`, `already_landed`, `conflict`, `denied` and `error`.+The hooks (`internal/gitaly/hook`) define `graft_land_intents_seconds`+(histogram): the land intents of one prepared reference transaction in the file+changelog, the wait for their lock file, one write and one fsync, under the+references' locks ([PLAN11](PLAN11.md), 4.2).+The server registers the lanes of the process (`landlane.Shared`) and thesemetrics with the Prometheus registry, so they are exported on `/metrics`. Thephase breakdown of a benchmark run is in [BENCH.md](BENCH.md#batching-benchmark).diff --git a/internal/gitaly/hook/changeset_order.go b/internal/gitaly/hook/changeset_order.goindex 2499360..9a26467 100644--- a/internal/gitaly/hook/changeset_order.go+++ b/internal/gitaly/hook/changeset_order.go@@ -27,6 +27,12 @@ var (Buckets: []float64{1, 2, 4, 8, 16, 32, 64, 128},})+ landIntentsSeconds = promauto.NewHistogram(prometheus.HistogramOpts{+ Name: "graft_land_intents_seconds",+ Help: "Time of the land intents of one prepared reference transaction (doc/graft/PLAN11.md): the wait for the intents' lock file, one write and one fsync, under the locks of the references.",+ Buckets: []float64{0.0005, 0.001, 0.002, 0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1},+ })+changelogAppendSeconds = promauto.NewHistogram(prometheus.HistogramOpts{Name: "graft_changelog_append_seconds",Help: "Time of one write of the changeset log, with its fsync, for a group of reference transactions.",diff --git a/internal/gitaly/hook/referencetransaction.go b/internal/gitaly/hook/referencetransaction.goindex 5d298ca..f163a14 100644--- a/internal/gitaly/hook/referencetransaction.go+++ b/internal/gitaly/hook/referencetransaction.go@@ -9,6 +9,7 @@ import ("fmt""io""strings"+ "time""github.com/feder-cr/git-ai/internal/git""github.com/feder-cr/git-ai/internal/git/gitcmd"@@ -226,7 +227,9 @@ func (m *GitLabHookManager) recordLandIntents(ctx context.Context, payload gitcmreturn fmt.Errorf("resolving repository path: %w", err)}+ start := time.Now()compact, err := changelog.RecordLandIntents(repoPath, string(meta.LandReference), meta.Invocation, meta.Lands)+ landIntentsSeconds.Observe(time.Since(start).Seconds())if err != nil {return err}diff --git a/internal/gitaly/service/operations/land_batch_metrics.go b/internal/gitaly/service/operations/land_batch_metrics.goindex 03c30af..3ceecb5 100644--- a/internal/gitaly/service/operations/land_batch_metrics.go+++ b/internal/gitaly/service/operations/land_batch_metrics.go@@ -24,6 +24,10 @@ const (landBatchPhasePlan = "plan"// landBatchPhaseReplay is the replay of the commits of one rebased request.landBatchPhaseReplay = "replay"+ // landBatchPhaseIdentity is the lookup of the earlier land of one diverged request+ // (doc/graft/PLAN11.md): the land identities, the reachability of their commits and, for an+ // answer, the search for its revert.+ landBatchPhaseIdentity = "identity"// landBatchPhasePack is the packing of the objects of an attempt before its compare-and-swap.landBatchPhasePack = "pack"// landBatchPhaseUpdate is the compare-and-swap that publishes a batch, with the hooks.@@ -51,8 +55,8 @@ var (landBatchPhaseSeconds = promauto.NewHistogramVec(prometheus.HistogramOpts{Name: "graft_land_batch_phase_seconds",Help: "Time spent in each phase of a land batch: quarantine, tip, land_member (one observation per " +- "request of a batch attempt), plan and replay (parts of land_member), pack (the objects of an " +- "attempt before its update), update (the compare-and-swap with the hooks) and total.",+ "request of a batch attempt), plan, identity and replay (parts of land_member), pack (the objects " ++ "of an attempt before its update), update (the compare-and-swap with the hooks) and total.",Buckets: prometheus.DefBuckets,}, []string{"phase"})diff --git a/internal/gitaly/service/operations/land_identity.go b/internal/gitaly/service/operations/land_identity.goindex 79d9316..1d9f3b6 100644--- a/internal/gitaly/service/operations/land_identity.go+++ b/internal/gitaly/service/operations/land_identity.go@@ -7,6 +7,7 @@ import ("fmt""slices""strings"+ "time""github.com/feder-cr/git-ai/internal/git""github.com/feder-cr/git-ai/internal/git/gitcmd"@@ -72,6 +73,8 @@ func landWithRecord(ctx context.Context, reference git.ReferenceName, lands []ch// nothing. Only once a land answers is the commit that reverted it looked for, to explain the// answer.func (a *landingAttempt) landedEarlier(ctx context.Context, reference git.ReferenceName, tip, commitID git.ObjectID) (*landIdentity, error) {+ defer a.observe(landBatchPhaseIdentity, time.Now())+records, err := a.server.lookupLand(ctx, a.repository, reference, commitID)if err != nil {return nil, err