diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2022-03-29 13:22:25 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2022-03-29 13:40:47 +0300 |
commit | 0c3e1051840053f47897dcaca0d9c2037c3c3020 (patch) | |
tree | 4b8ef9dc5ce9c473f0f2ba699d64fb8a23a3adcf | |
parent | 42439883376e6d96ef78afd7f29c6d80f7b12c2f (diff) |
housekeeping: Report when we have pruned config keys
We do not currently report when we're pruning config keys. While we
cannot easily derive the number of keys we have pruned, we can at least
report whether we pruned something or not.
Add this reporting so that we can tell whether the config pruning is
still in use or whether all repositories have already been cleaned up.
-rw-r--r-- | internal/git/housekeeping/clean_stale_data.go | 8 | ||||
-rw-r--r-- | internal/git/housekeeping/clean_stale_data_test.go | 18 |
2 files changed, 24 insertions, 2 deletions
diff --git a/internal/git/housekeeping/clean_stale_data.go b/internal/git/housekeeping/clean_stale_data.go index 664675935..7c1dc08ac 100644 --- a/internal/git/housekeeping/clean_stale_data.go +++ b/internal/git/housekeeping/clean_stale_data.go @@ -105,6 +105,14 @@ func (m *RepositoryManager) CleanStaleData(ctx context.Context, repo *localrepo. if !errors.Is(err, git.ErrNotFound) { return fmt.Errorf("housekeeping could not unset unnecessary config lines: %w", err) } + staleDataByType["configkeys"] = 0 + } else { + // If we didn't get an error we know that we've deleted _something_. We just set + // this variable to `1` because we don't count how many keys we have deleted. It's + // probably good enough: we only want to know whether we're still pruning such old + // configuration or not, but typically don't care how many there are so that we know + // when to delete this cleanup of legacy data. + staleDataByType["configkeys"] = 1 } if err := pruneEmptyConfigSections(ctx, repo); err != nil { diff --git a/internal/git/housekeeping/clean_stale_data_test.go b/internal/git/housekeeping/clean_stale_data_test.go index e6a121c14..758d87b41 100644 --- a/internal/git/housekeeping/clean_stale_data_test.go +++ b/internal/git/housekeeping/clean_stale_data_test.go @@ -132,6 +132,7 @@ func d(name string, mode os.FileMode, age time.Duration, finalState entryFinalSt } type cleanStaleDataMetrics struct { + configkeys int objects int locks int refs int @@ -153,6 +154,7 @@ func requireCleanStaleDataMetrics(t *testing.T, m *RepositoryManager, metrics cl require.NoError(t, err) for metric, expectedValue := range map[string]int{ + "configkeys": metrics.configkeys, "objects": metrics.objects, "locks": metrics.locks, "refs": metrics.refs, @@ -880,7 +882,9 @@ func TestRepositoryManager_CleanStaleData_unsetConfiguration(t *testing.T) { unrelated = untouched `), 0o644)) - require.NoError(t, NewManager(cfg.Prometheus, nil).CleanStaleData(ctx, repo)) + mgr := NewManager(cfg.Prometheus, nil) + + require.NoError(t, mgr.CleanStaleData(ctx, repo)) require.Equal(t, `[core] repositoryformatversion = 0 @@ -893,6 +897,10 @@ func TestRepositoryManager_CleanStaleData_unsetConfiguration(t *testing.T) { [totally] unrelated = untouched `, string(testhelper.MustReadFile(t, configPath))) + + requireCleanStaleDataMetrics(t, mgr, cleanStaleDataMetrics{ + configkeys: 1, + }) } func TestRepositoryManager_CleanStaleData_unsetConfigurationTransactional(t *testing.T) { @@ -957,7 +965,9 @@ func TestRepositoryManager_CleanStaleData_pruneEmptyConfigSections(t *testing.T) [remote "tmp-8c948ca94832c2725733e48cb2902287"] `), 0o644)) - require.NoError(t, NewManager(cfg.Prometheus, nil).CleanStaleData(ctx, repo)) + mgr := NewManager(cfg.Prometheus, nil) + + require.NoError(t, mgr.CleanStaleData(ctx, repo)) require.Equal(t, `[core] repositoryformatversion = 0 filemode = true @@ -965,6 +975,10 @@ func TestRepositoryManager_CleanStaleData_pruneEmptyConfigSections(t *testing.T) [uploadpack] allowAnySHA1InWant = true `, string(testhelper.MustReadFile(t, configPath))) + + requireCleanStaleDataMetrics(t, mgr, cleanStaleDataMetrics{ + configkeys: 1, + }) } func TestPruneEmptyConfigSections(t *testing.T) { |