Repository navigation
Add coarse git repo size to bundle deploy telemetry #8248
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+903
−2
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
8570ade
Add coarse git repo size to bundle deploy telemetry
andersrexdb 8a4a2ee
Fix git repo size for loose objects, alternates and stale split indexes
andersrexdb d1dbcea
Bound git repo size read and test it against a real repository
andersrexdb 3210b35
Clarify that pack_size covers the whole object store
andersrexdb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,7 @@ | ||
| bundle: | ||
| name: test-bundle | ||
|
|
||
| # The data directory only gives the repository a known size. | ||
| sync: | ||
| exclude: | ||
| - data |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| package phases | ||
|
|
||
| import ( | ||
| "context" | ||
| "encoding/binary" | ||
| "os" | ||
| "path/filepath" | ||
| "testing" | ||
|
|
||
| "github.com/databricks/cli/bundle" | ||
| "github.com/databricks/cli/libs/dbr" | ||
| "github.com/databricks/cli/libs/env" | ||
| "github.com/databricks/cli/libs/telemetry/protos" | ||
| "github.com/databricks/cli/libs/vfs" | ||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| // gitRepoSizeContext isolates the global git config and sets whether the CLI | ||
| // runs on a Databricks cluster. | ||
| func gitRepoSizeContext(t *testing.T, onRuntime bool) context.Context { | ||
| ctx := env.WithUserHomeDir(t.Context(), t.TempDir()) | ||
| ctx = env.Set(ctx, "XDG_CONFIG_HOME", "") | ||
| return dbr.MockRuntime(ctx, dbr.Environment{IsDbr: onRuntime}) | ||
| } | ||
|
|
||
| // gitRepoSizeBundle returns a bundle in a repository with 1,500 tracked files | ||
| // and a 20 MiB pack. Without withRepo the .git directory is empty. | ||
| func gitRepoSizeBundle(t *testing.T, withRepo bool) *bundle.Bundle { | ||
| root := t.TempDir() | ||
| gitDir := filepath.Join(root, ".git") | ||
| require.NoError(t, os.MkdirAll(gitDir, 0o755)) | ||
| if withRepo { | ||
| require.NoError(t, os.MkdirAll(filepath.Join(gitDir, "objects", "pack"), 0o755)) | ||
| index := make([]byte, 12) | ||
| copy(index, "DIRC") | ||
| binary.BigEndian.PutUint32(index[4:8], 2) | ||
| binary.BigEndian.PutUint32(index[8:12], 1_500) | ||
| require.NoError(t, os.WriteFile(filepath.Join(gitDir, "index"), index, 0o644)) | ||
| require.NoError(t, os.WriteFile(filepath.Join(gitDir, "objects", "pack", "pack-1.pack"), make([]byte, 20<<20), 0o644)) | ||
| } | ||
| inGitRepo := true | ||
| return &bundle.Bundle{ | ||
| WorktreeRoot: vfs.MustNew(root), | ||
| SyncRootPath: root, | ||
| InGitRepo: &inGitRepo, | ||
| } | ||
| } | ||
|
|
||
| func TestBundleGitRepoSize(t *testing.T) { | ||
| got := bundleGitRepoSize(gitRepoSizeContext(t, false), gitRepoSizeBundle(t, true)) | ||
| assert.Equal(t, &protos.BundleGitRepoSize{ | ||
| TrackedFileCount: protos.GitTrackedFileCount1KTo5K, | ||
| PackSize: protos.GitPackSize10MBTo100MB, | ||
| }, got) | ||
| } | ||
|
|
||
| func TestBundleGitRepoSizeSkipped(t *testing.T) { | ||
| notInRepo := false | ||
|
|
||
| tests := []struct { | ||
| name string | ||
| onRuntime bool | ||
| edit func(b *bundle.Bundle) | ||
| withRepo bool | ||
| }{ | ||
| { | ||
| name: "git detection did not run", | ||
| edit: func(b *bundle.Bundle) { b.InGitRepo = nil }, | ||
| withRepo: true, | ||
| }, | ||
| { | ||
| name: "not in a git repository", | ||
| edit: func(b *bundle.Bundle) { b.InGitRepo = ¬InRepo }, | ||
| withRepo: true, | ||
| }, | ||
| { | ||
| // The workspace already knows the size of a Databricks Git folder. | ||
| name: "deployed from a workspace folder", | ||
| onRuntime: true, | ||
| edit: func(b *bundle.Bundle) { b.SyncRootPath = "/Workspace/Users/someone@example.com/repo" }, | ||
| withRepo: true, | ||
| }, | ||
| { | ||
| name: "nothing readable", | ||
| edit: func(b *bundle.Bundle) {}, | ||
| }, | ||
| } | ||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| b := gitRepoSizeBundle(t, tt.withRepo) | ||
| tt.edit(b) | ||
| assert.Nil(t, bundleGitRepoSize(gitRepoSizeContext(t, tt.onRuntime), b)) | ||
| }) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.