diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2022-03-14 17:59:43 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2022-03-15 11:24:20 +0300 |
commit | 08d51eee2304870f7dc6716d256e7f3e5d49f81f (patch) | |
tree | 3f9d0abd0b0352d9dfcca7db016fe5f8c1ba8e23 | |
parent | a667155fa31a040a900dbfc4470addc9b0ea9dff (diff) |
housekeeping: Track what kind of repacks OptimizeRepository doespks-housekeeping-improved-metrics
With OptimizeRepository becoming our new RPC which performs all
repository maintenance in one place it's harder to tell what exactly is
going on without proper metrics. One bit of information that gets lost
is whether repacks are incremental or full repacks, which is quite an
important distinction due to the impact on latency.
Expose this information both via logs and via Prometheus to keep better
track of it. While at it, alos exxpose information about whether we are
writing bitmaps or not.
Changelog: added
-rw-r--r-- | internal/git/housekeeping/optimize_repository.go | 34 | ||||
-rw-r--r-- | internal/git/housekeeping/optimize_repository_ext_test.go | 16 | ||||
-rw-r--r-- | internal/git/housekeeping/optimize_repository_test.go | 17 |
3 files changed, 42 insertions, 25 deletions
diff --git a/internal/git/housekeeping/optimize_repository.go b/internal/git/housekeeping/optimize_repository.go index 15e733b26..7a0628f11 100644 --- a/internal/git/housekeeping/optimize_repository.go +++ b/internal/git/housekeeping/optimize_repository.go @@ -25,18 +25,22 @@ func (m *RepositoryManager) OptimizeRepository(ctx context.Context, repo *localr totalTimer := prometheus.NewTimer(m.tasksLatency.WithLabelValues("total")) optimizations := struct { - PackedObjects bool `json:"packed_objects"` - PrunedObjects bool `json:"pruned_objects"` - PackedRefs bool `json:"packed_refs"` + PackedObjectsIncremental bool `json:"packed_objects_incremental"` + PackedObjectsFull bool `json:"packed_objects_full"` + PrunedObjects bool `json:"pruned_objects"` + PackedRefs bool `json:"packed_refs"` + WrittenBitmap bool `json:"written_bitmap"` }{} defer func() { totalTimer.ObserveDuration() ctxlogrus.Extract(ctx).WithField("optimizations", optimizations).Info("optimized repository") for task, executed := range map[string]bool{ - "packed_objects": optimizations.PackedObjects, - "pruned_objects": optimizations.PrunedObjects, - "packed_refs": optimizations.PackedRefs, + "packed_objects_incremental": optimizations.PackedObjectsIncremental, + "packed_objects_full": optimizations.PackedObjectsFull, + "pruned_objects": optimizations.PrunedObjects, + "packed_refs": optimizations.PackedRefs, + "written_bitmap": optimizations.WrittenBitmap, } { if executed { m.tasksTotal.WithLabelValues(task).Add(1) @@ -57,11 +61,15 @@ func (m *RepositoryManager) OptimizeRepository(ctx context.Context, repo *localr timer.ObserveDuration() timer = prometheus.NewTimer(m.tasksLatency.WithLabelValues("repack")) - didRepack, err := repackIfNeeded(ctx, repo) + didRepack, repackCfg, err := repackIfNeeded(ctx, repo) if err != nil { return fmt.Errorf("could not repack: %w", err) } - optimizations.PackedObjects = didRepack + if didRepack { + optimizations.PackedObjectsIncremental = !repackCfg.FullRepack + optimizations.PackedObjectsFull = repackCfg.FullRepack + optimizations.WrittenBitmap = repackCfg.WriteBitmap + } timer.ObserveDuration() timer = prometheus.NewTimer(m.tasksLatency.WithLabelValues("prune")) @@ -85,21 +93,21 @@ func (m *RepositoryManager) OptimizeRepository(ctx context.Context, repo *localr // repackIfNeeded uses a set of heuristics to determine whether the repository needs a // full repack and, if so, repacks it. -func repackIfNeeded(ctx context.Context, repo *localrepo.Repo) (bool, error) { +func repackIfNeeded(ctx context.Context, repo *localrepo.Repo) (bool, RepackObjectsConfig, error) { repackNeeded, cfg, err := needsRepacking(repo) if err != nil { - return false, fmt.Errorf("determining whether repo needs repack: %w", err) + return false, RepackObjectsConfig{}, fmt.Errorf("determining whether repo needs repack: %w", err) } if !repackNeeded { - return false, nil + return false, RepackObjectsConfig{}, nil } if err := RepackObjects(ctx, repo, cfg); err != nil { - return false, err + return false, RepackObjectsConfig{}, err } - return true, nil + return true, cfg, nil } func needsRepacking(repo *localrepo.Repo) (bool, RepackObjectsConfig, error) { diff --git a/internal/git/housekeeping/optimize_repository_ext_test.go b/internal/git/housekeeping/optimize_repository_ext_test.go index 2f0a5ed10..e12a172d7 100644 --- a/internal/git/housekeeping/optimize_repository_ext_test.go +++ b/internal/git/housekeeping/optimize_repository_ext_test.go @@ -121,13 +121,17 @@ func TestPruneIfNeeded(t *testing.T) { require.NoError(t, housekeeping.NewManager(nil).OptimizeRepository(ctx, repo)) require.Equal(t, struct { - PackedObjects bool `json:"packed_objects"` - PrunedObjects bool `json:"pruned_objects"` - PackedRefs bool `json:"packed_refs"` + PackedObjectsIncremental bool `json:"packed_objects_incremental"` + PackedObjectsFull bool `json:"packed_objects_full"` + PrunedObjects bool `json:"pruned_objects"` + PackedRefs bool `json:"packed_refs"` + WrittenBitmap bool `json:"written_bitmap"` }{ - PackedObjects: true, - PrunedObjects: tc.expectedPrune, - PackedRefs: false, + PackedObjectsIncremental: false, + PackedObjectsFull: true, + PrunedObjects: tc.expectedPrune, + PackedRefs: false, + WrittenBitmap: true, }, hook.Entries[len(hook.Entries)-1].Data["optimizations"], ) diff --git a/internal/git/housekeeping/optimize_repository_test.go b/internal/git/housekeeping/optimize_repository_test.go index 8a74b51b2..3af943789 100644 --- a/internal/git/housekeeping/optimize_repository_test.go +++ b/internal/git/housekeeping/optimize_repository_test.go @@ -476,7 +476,8 @@ func TestOptimizeRepository(t *testing.T) { return repo }, expectedOptimizations: map[string]float64{ - "packed_objects": 1, + "packed_objects_full": 1, + "written_bitmap": 1, }, }, { @@ -486,7 +487,8 @@ func TestOptimizeRepository(t *testing.T) { return repo }, expectedOptimizations: map[string]float64{ - "packed_objects": 1, + "packed_objects_full": 1, + "written_bitmap": 1, }, }, { @@ -497,7 +499,8 @@ func TestOptimizeRepository(t *testing.T) { return repo }, expectedOptimizations: map[string]float64{ - "packed_objects": 1, + "packed_objects_full": 1, + "written_bitmap": 1, }, }, { @@ -527,8 +530,8 @@ func TestOptimizeRepository(t *testing.T) { return repo }, expectedOptimizations: map[string]float64{ - "packed_objects": 1, - "pruned_objects": 1, + "packed_objects_incremental": 1, + "pruned_objects": 1, }, }, { @@ -562,9 +565,11 @@ func TestOptimizeRepository(t *testing.T) { require.Equal(t, tc.expectedErr, err) for _, metric := range []string{ - "packed_objects", + "packed_objects_incremental", + "packed_objects_full", "pruned_objects", "packed_refs", + "written_bitmap", } { value := testutil.ToFloat64(manager.tasksTotal.WithLabelValues(metric)) require.Equal(t, tc.expectedOptimizations[metric], value, metric) |