Skip to content

Git designed for AI agents.

Tell creates from updates in the steps of the Preparing phase

Federico Elia1a4d29c7c3e9
diff --git a/doc/graft/STORAGE.md b/doc/graft/STORAGE.md
index 50b8adc..86f6fe4 100644
--- a/doc/graft/STORAGE.md
+++ b/doc/graft/STORAGE.md
@@ -710,7 +710,7 @@ without a single divergence.
|---|---|
| `graft_storage_changesets_total{mode,result}` | Reference transactions handled by the write path; results `committed`, `noop`, `conflict`, `error`, `skipped`. |
| `graft_storage_preparing_seconds` | Time of the write path in the Preparing phase, before git locks the references (pack build and upload). |
-| `graft_storage_preparing_step_seconds{step}` | The steps of the Preparing phase in authoritative mode: `record` (the read of the repository record), `walk` (the objects reachable from the new tips and not from a local reference, until their list ends; observed for every transaction with new tips), `pack` (writing and hashing a non-empty pack) and `upload` (to the bucket). |
+| `graft_storage_preparing_step_seconds{kind,step}` | The steps of the Preparing phase in authoritative mode: `record` (the read of the repository record), `walk` (the objects reachable from the new tips and not from a local reference, until their list ends; observed for every transaction with new tips), `pack` (writing and hashing a non-empty pack) and `upload` (to the bucket). `kind` is `create` for a transaction that only creates references (a commit onto a new branch), `update` otherwise (a land). |
| `graft_storage_prepared_seconds` | Time of the write path in the Prepared phase, while git holds the reference locks (expected values and database commit; also the pack when the Preparing phase did not prepare it). |
| `graft_storage_pack_bytes_total` | Bytes of packs uploaded. |
| `graft_storage_shadow_divergences_total` | Shadow mode changesets recorded despite a mismatch. |
diff --git a/internal/graft/corestore/voter/preparing_test.go b/internal/graft/corestore/voter/preparing_test.go
index 8f0819d..10708a0 100644
--- a/internal/graft/corestore/voter/preparing_test.go
+++ b/internal/graft/corestore/voter/preparing_test.go
@@ -78,15 +78,17 @@ func TestPreparingUploadsThePackOnce(t *testing.T) {
require.Equal(t, corestore.Target(f.c.String()), f.dbRef(t, ref))
require.Equal(t, float64(changeset.PackBytes), metricValue(t, f.voter, "graft_storage_pack_bytes_total", nil))
require.Equal(t, float64(1), metricValue(t, f.voter, "graft_storage_preparing_seconds", nil))
- // Authoritative mode observes every step of the Preparing phase once; the
- // shadow mode, which builds its pack another way, none.
+ // Authoritative mode observes every step of the Preparing phase once, as an
+ // update (main existed); the shadow mode, which builds its pack another way,
+ // none.
steps := float64(0)
if mode == corestore.ModeAuthoritative {
steps = 1
}
for _, step := range []string{"record", "walk", "pack", "upload"} {
- require.Equal(t, steps, metricValue(t, f.voter, "graft_storage_preparing_step_seconds", map[string]string{"step": step}), step)
+ require.Equal(t, steps, metricValue(t, f.voter, "graft_storage_preparing_step_seconds", map[string]string{"kind": "update", "step": step}), step)
}
+ require.Zero(t, metricValue(t, f.voter, "graft_storage_preparing_step_seconds", map[string]string{"kind": "create"}))
f.voter.Committed(f.ctx, f.payload, input)
require.Equal(t, []noteCall{{repoPath: f.repoPath, repoID: f.repoID, seq: f.seq(2)}}, f.applier.calls)
@@ -119,6 +121,8 @@ func TestPreparedWithoutPreparing(t *testing.T) {
f.preparing(line(f.zero, f.a.String(), ref))
require.Equal(t, 1, blobs.count())
+ require.Equal(t, float64(4), metricValue(t, f.voter, "graft_storage_preparing_step_seconds", map[string]string{"kind": "create"}),
+ "a transaction that creates its reference is a create in each of the four steps")
require.NoError(t, f.prepared(line(f.zero, f.c.String(), ref)))
require.Equal(t, 2, blobs.count(), "the pack of another transaction is not used")
diff --git a/internal/graft/corestore/voter/voter.go b/internal/graft/corestore/voter/voter.go
index b700f84..975ffdf 100644
--- a/internal/graft/corestore/voter/voter.go
+++ b/internal/graft/corestore/voter/voter.go
@@ -255,7 +255,7 @@ func (v *Voter) preparePack(ctx context.Context, payload gitcmd.HooksPayload, ch
if err != nil {
return nil, err
}
- v.observeStep(stepRecord, time.Since(readAt))
+ v.observeStep(updates, stepRecord, time.Since(readAt))
if record.HeadSeq == 0 {
return nil, nil
}
@@ -705,9 +705,9 @@ func (v *Voter) buildAndUpload(ctx context.Context, repo *localrepo.Repo, storag
built := time.Now()
pack, err = gitops.BuildPack(ctx, repo, tips, tmpDir)
if err == nil && preparing {
- v.observeStep(stepWalk, pack.Walk)
+ v.observeStep(updates, stepWalk, pack.Walk)
if !pack.Empty() {
- v.observeStep(stepPack, time.Since(built)-pack.Walk)
+ v.observeStep(updates, stepPack, time.Since(built)-pack.Walk)
}
}
} else {
@@ -739,7 +739,7 @@ func (v *Voter) buildAndUpload(ctx context.Context, repo *localrepo.Repo, storag
return corestore.PackUpload{}, err
}
if preparing {
- v.observeStep(stepUpload, time.Since(uploading))
+ v.observeStep(updates, stepUpload, time.Since(uploading))
}
v.metrics.packBytes.Add(float64(pack.Size))
@@ -762,14 +762,34 @@ const (
stepUpload = "upload"
)
-// observeStep observes d in step of graft_storage_preparing_step_seconds. Only
-// authoritative mode observes the steps: the shadow mode builds its packs
-// another way (buildPackAgainst).
-func (v *Voter) observeStep(step string, d time.Duration) {
+// The kinds of transactions that graft_storage_preparing_step_seconds tells apart.
+const (
+ // kindCreate is a transaction that only creates references, such as a commit
+ // onto a new branch.
+ kindCreate = "create"
+ // kindUpdate is a transaction that changes or deletes an existing reference,
+ // such as a land onto its branch.
+ kindUpdate = "update"
+)
+
+// transactionKind returns the kind of the transaction of updates.
+func transactionKind(updates []inputUpdate) string {
+ for _, u := range updates {
+ if !u.oldZero {
+ return kindUpdate
+ }
+ }
+ return kindCreate
+}
+
+// observeStep observes d in step of graft_storage_preparing_step_seconds, for the
+// kind of the transaction of updates. Only authoritative mode observes the steps:
+// the shadow mode builds its packs another way (buildPackAgainst).
+func (v *Voter) observeStep(updates []inputUpdate, step string, d time.Duration) {
if !v.core.Authoritative() {
return
}
- v.metrics.preparingSteps.WithLabelValues(step).Observe(d.Seconds())
+ v.metrics.preparingSteps.WithLabelValues(transactionKind(updates), step).Observe(d.Seconds())
}
// fault calls FaultHook and exits the process when CrashEnv selects the point.
@@ -1277,9 +1297,10 @@ func newMetrics() *metrics {
Name: "graft_storage_preparing_step_seconds",
Help: "Time of each step of the Preparing phase of authoritative writes: record (the read of the " +
"repository record), walk (the objects of the pack), pack (writing and hashing a non-empty pack) " +
- "and upload (to the bucket).",
+ "and upload (to the bucket); kind is create for a transaction that only creates references, " +
+ "update otherwise.",
Buckets: []float64{.0005, .001, .0025, .005, .01, .025, .05, .1, .25, .5, 1, 2.5},
- }, []string{"step"}),
+ }, []string{"kind", "step"}),
prepared: prometheus.NewHistogram(prometheus.HistogramOpts{
Name: "graft_storage_prepared_seconds",
Help: "Time spent in the Prepared phase of the storage core write path, while git holds the reference locks.",