Skip to content

Commit 5def0a8

Browse files
authored
[debug] Add cache credentials flag and more perf profiling (#2065)
## Summary Credentials command is hidden, this flag can help debugging. ## How was it tested?
1 parent 62acf88 commit 5def0a8

File tree

5 files changed

+24
-1
lines changed

5 files changed

+24
-1
lines changed

internal/boxcli/cache.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ type cacheFlags struct {
2424
to string
2525
}
2626

27+
type credentialsFlags struct {
28+
format string
29+
}
30+
2731
func cacheCmd() *cobra.Command {
2832
flags := cacheFlags{}
2933
cacheCommand := &cobra.Command{
@@ -93,7 +97,8 @@ func cacheConfigureCmd() *cobra.Command {
9397
}
9498

9599
func cacheCredentialsCmd() *cobra.Command {
96-
return &cobra.Command{
100+
flags := credentialsFlags{}
101+
cmd := &cobra.Command{
97102
Use: "credentials",
98103
Short: "Output S3 cache credentials",
99104
Hidden: true,
@@ -103,6 +108,14 @@ func cacheCredentialsCmd() *cobra.Command {
103108
if err != nil {
104109
return err
105110
}
111+
112+
if flags.format == "sh" {
113+
fmt.Printf("export AWS_ACCESS_KEY_ID=%q\n", creds.AccessKeyID)
114+
fmt.Printf("export AWS_SECRET_ACCESS_KEY=%q\n", creds.SecretAccessKey)
115+
fmt.Printf("export AWS_SESSION_TOKEN=%q\n", creds.SessionToken)
116+
return nil
117+
}
118+
106119
out, err := json.Marshal(creds)
107120
if err != nil {
108121
return err
@@ -111,6 +124,8 @@ func cacheCredentialsCmd() *cobra.Command {
111124
return err
112125
},
113126
}
127+
cmd.Flags().StringVar(&flags.format, "format", "json", "Output format, either json or sh")
128+
return cmd
114129
}
115130

116131
func cacheInfoCmd() *cobra.Command {

internal/devbox/packages.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@ func resetProfileDirForFlakes(profileDir string) (err error) {
394394
}
395395

396396
func (d *Devbox) installPackages(ctx context.Context, mode installMode) error {
397+
defer debug.FunctionTimer().End()
397398
// Create plugin directories first because packages might need them
398399
for _, pluginConfig := range d.Config().IncludedPluginConfigs() {
399400
if err := d.PluginManager().CreateFilesForConfig(pluginConfig); err != nil {
@@ -430,6 +431,7 @@ func (d *Devbox) InstallRunXPackages(ctx context.Context) error {
430431
// packages will be available in the nix store when computing the devbox environment
431432
// and installing in the nix profile (even if offline).
432433
func (d *Devbox) installNixPackagesToStore(ctx context.Context, mode installMode) error {
434+
defer debug.FunctionTimer().End()
433435
packages, err := d.packagesToInstallInStore(ctx, mode)
434436
if err != nil || len(packages) == 0 {
435437
return err
@@ -526,6 +528,7 @@ func (d *Devbox) installNixPackagesToStore(ctx context.Context, mode installMode
526528
}
527529

528530
func (d *Devbox) packagesToInstallInStore(ctx context.Context, mode installMode) ([]*devpkg.Package, error) {
531+
defer debug.FunctionTimer().End()
529532
// First, get and prepare all the packages that must be installed in this project
530533
// and remove non-nix packages from the list
531534
packages := lo.Filter(d.InstallablePackages(), devpkg.IsNix)

internal/devpkg/narinfo_cache.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212

1313
"github.com/pkg/errors"
1414
"go.jetpack.io/devbox/internal/boxcli/featureflag"
15+
"go.jetpack.io/devbox/internal/debug"
1516
"go.jetpack.io/devbox/internal/lock"
1617
"go.jetpack.io/devbox/internal/nix"
1718
"golang.org/x/sync/errgroup"
@@ -53,6 +54,7 @@ func (p *Package) IsInBinaryCache() (bool, error) {
5354
// package in the list, and caches the result.
5455
// Callers of IsInBinaryCache may call this function first as a perf-optimization.
5556
func FillNarInfoCache(ctx context.Context, packages ...*Package) error {
57+
defer debug.FunctionTimer().End()
5658
if !featureflag.RemoveNixpkgs.Enabled() {
5759
return nil
5860
}

internal/nix/build.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ type BuildArgs struct {
2121
}
2222

2323
func Build(ctx context.Context, args *BuildArgs, installables ...string) error {
24+
defer debug.FunctionTimer().End()
2425
// --impure is required for allowUnfreeEnv/allowInsecureEnv to work.
2526
cmd := commandContext(ctx, "build", "--impure")
2627
cmd.Args = append(cmd.Args, args.Flags...)

internal/nix/store.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ func StorePathFromHashPart(ctx context.Context, hash, storeAddr string) (string,
2424
}
2525

2626
func StorePathsFromInstallable(ctx context.Context, installable string, allowInsecure bool) ([]string, error) {
27+
defer debug.FunctionTimer().End()
2728
// --impure for NIXPKGS_ALLOW_UNFREE
2829
cmd := commandContext(ctx, "path-info", installable, "--json", "--impure")
2930
cmd.Env = allowUnfreeEnv(os.Environ())
@@ -53,6 +54,7 @@ func StorePathsFromInstallable(ctx context.Context, installable string, allowIns
5354
// StorePathsAreInStore returns true if the store path is in the store
5455
// It relies on `nix store ls` to check if the store path is in the store
5556
func StorePathsAreInStore(ctx context.Context, storePaths []string) (bool, error) {
57+
defer debug.FunctionTimer().End()
5658
for _, storePath := range storePaths {
5759
cmd := commandContext(ctx, "store", "ls", storePath)
5860
debug.Log("Running cmd %s", cmd)

0 commit comments

Comments
 (0)