diff options
author | John Cai <jcai@gitlab.com> | 2022-03-24 23:11:47 +0300 |
---|---|---|
committer | John Cai <jcai@gitlab.com> | 2022-04-04 16:32:04 +0300 |
commit | 0d28358d259724bc71b1833ffb877f73852b197c (patch) | |
tree | e08701672fc3f670dbc3de1df81c7a5a5ad8776e /internal | |
parent | a35d007c05c6effe440c840a28808f894abf7ca8 (diff) |
repository: Use Size() to calculate repo size behind feature flag
In the previous commit, we added a Size() method in localrepo that calls
git rev-list --all --objects --disk-usage to calculate the size of the
repository.
Add a feature flag that, when toggled on, will cause RepositorySize to
use this new way of calculating repository size.
Changelog: added
Diffstat (limited to 'internal')
-rw-r--r-- | internal/gitaly/service/repository/size.go | 23 | ||||
-rw-r--r-- | internal/gitaly/service/repository/size_test.go | 31 | ||||
-rw-r--r-- | internal/metadata/featureflag/ff_repo_size_revlist.go | 5 |
3 files changed, 47 insertions, 12 deletions
diff --git a/internal/gitaly/service/repository/size.go b/internal/gitaly/service/repository/size.go index 261bb0417..4d43dc2b1 100644 --- a/internal/gitaly/service/repository/size.go +++ b/internal/gitaly/service/repository/size.go @@ -10,16 +10,31 @@ import ( "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus" "gitlab.com/gitlab-org/gitaly/v14/internal/command" + "gitlab.com/gitlab-org/gitaly/v14/internal/metadata/featureflag" "gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb" ) func (s *server) RepositorySize(ctx context.Context, in *gitalypb.RepositorySizeRequest) (*gitalypb.RepositorySizeResponse, error) { - path, err := s.locator.GetPath(in.Repository) - if err != nil { - return nil, err + repo := s.localrepo(in.GetRepository()) + var size int64 + var err error + + if featureflag.RevlistForRepoSize.IsEnabled(ctx) { + size, err = repo.Size(ctx) + if err != nil { + return nil, err + } + // return the size in kb to remain consistent + size = size / 1024 + } else { + path, err := repo.Path() + if err != nil { + return nil, err + } + size = getPathSize(ctx, path) } - return &gitalypb.RepositorySizeResponse{Size: getPathSize(ctx, path)}, nil + return &gitalypb.RepositorySizeResponse{Size: size}, nil } func (s *server) GetObjectDirectorySize(ctx context.Context, in *gitalypb.GetObjectDirectorySizeRequest) (*gitalypb.GetObjectDirectorySizeResponse, error) { diff --git a/internal/gitaly/service/repository/size_test.go b/internal/gitaly/service/repository/size_test.go index 5aa51da73..b9c752723 100644 --- a/internal/gitaly/service/repository/size_test.go +++ b/internal/gitaly/service/repository/size_test.go @@ -1,12 +1,14 @@ package repository import ( + "context" "testing" "github.com/stretchr/testify/require" "gitlab.com/gitlab-org/gitaly/v14/internal/git/gittest" "gitlab.com/gitlab-org/gitaly/v14/internal/git/quarantine" "gitlab.com/gitlab-org/gitaly/v14/internal/gitaly/config" + "gitlab.com/gitlab-org/gitaly/v14/internal/metadata/featureflag" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper" "gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb" "google.golang.org/grpc/codes" @@ -17,10 +19,13 @@ import ( // repository, even in optimally packed state, is greater than this. const testRepoMinSizeKB = 10000 -func TestSuccessfulRepositorySizeRequest(t *testing.T) { +func TestRepositorySize_SuccessfulRequest(t *testing.T) { t.Parallel() + testhelper.NewFeatureSets(featureflag.RevlistForRepoSize). + Run(t, testSuccessfulRepositorySizeRequest) +} - ctx := testhelper.Context(t) +func testSuccessfulRepositorySizeRequest(t *testing.T, ctx context.Context) { _, repo, _, client := setupRepositoryService(ctx, t) request := &gitalypb.RepositorySizeRequest{Repository: repo} @@ -33,8 +38,13 @@ func TestSuccessfulRepositorySizeRequest(t *testing.T) { ) } -func TestFailedRepositorySizeRequest(t *testing.T) { +func TestRepositorySixe_FailedRequest(t *testing.T) { t.Parallel() + testhelper.NewFeatureSets(featureflag.RevlistForRepoSize). + Run(t, testFailedRepositorySizeRequest) +} + +func testFailedRepositorySizeRequest(t *testing.T, ctx context.Context) { _, client := setupRepositoryServiceWithoutRepo(t) testCases := []struct { @@ -52,17 +62,19 @@ func TestFailedRepositorySizeRequest(t *testing.T) { request := &gitalypb.RepositorySizeRequest{ Repository: testCase.repo, } - ctx := testhelper.Context(t) _, err := client.RepositorySize(ctx, request) testhelper.RequireGrpcCode(t, err, codes.InvalidArgument) }) } } -func TestSuccessfulGetObjectDirectorySizeRequest(t *testing.T) { +func TestRepositorySize_SuccessfulGetObjectDirectorySizeRequest(t *testing.T) { t.Parallel() + testhelper.NewFeatureSets(featureflag.RevlistForRepoSize). + Run(t, testSuccessfulGetObjectDirectorySizeRequest) +} - ctx := testhelper.Context(t) +func testSuccessfulGetObjectDirectorySizeRequest(t *testing.T, ctx context.Context) { _, repo, _, client := setupRepositoryService(ctx, t) repo.GitObjectDirectory = "objects/" @@ -76,12 +88,15 @@ func TestSuccessfulGetObjectDirectorySizeRequest(t *testing.T) { ) } -func TestGetObjectDirectorySize_quarantine(t *testing.T) { +func TestRepositorySize_GetObjectDirectorySize_quarantine(t *testing.T) { t.Parallel() + testhelper.NewFeatureSets(featureflag.RevlistForRepoSize). + Run(t, testGetObjectDirectorySizeQuarantine) +} +func testGetObjectDirectorySizeQuarantine(t *testing.T, ctx context.Context) { cfg, client := setupRepositoryServiceWithoutRepo(t) locator := config.NewLocator(cfg) - ctx := testhelper.Context(t) t.Run("quarantined repo", func(t *testing.T) { repo, _ := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ diff --git a/internal/metadata/featureflag/ff_repo_size_revlist.go b/internal/metadata/featureflag/ff_repo_size_revlist.go new file mode 100644 index 000000000..8be87e482 --- /dev/null +++ b/internal/metadata/featureflag/ff_repo_size_revlist.go @@ -0,0 +1,5 @@ +package featureflag + +// RevlistForRepoSize enables the RepositorySize RPC to use git rev-list to +// calculate the disk usage of the repository. +var RevlistForRepoSize = NewFeatureFlag("revlist_for_repo_size", false) |