zotregistry.io/zot@v1.4.4-0.20231124084042-02a8ed785457/cmd/zb/main.go (about) 1 package main 2 3 import ( 4 "os" 5 6 distspec "github.com/opencontainers/distribution-spec/specs-go" 7 "github.com/rs/zerolog/log" 8 "github.com/spf13/cobra" 9 10 "zotregistry.io/zot/pkg/api/config" 11 ) 12 13 // "zb" - performance benchmark and stress. 14 func NewPerfRootCmd() *cobra.Command { 15 showVersion := false 16 17 var auth, workdir, repo, outFmt, srcIPs, srcCIDR string 18 19 var concurrency, requests int 20 21 var skipCleanup bool 22 23 rootCmd := &cobra.Command{ 24 Use: "zb <url>", 25 Short: "`zb`", 26 Long: "`zb`", 27 Run: func(cmd *cobra.Command, args []string) { 28 if showVersion { 29 log.Info().Str("distribution-spec", distspec.Version).Str("commit", config.Commit). 30 Str("binary-type", config.BinaryType).Str("go version", config.GoVersion).Msg("version") 31 } 32 33 if len(args) == 0 { 34 _ = cmd.Usage() 35 cmd.SilenceErrors = false 36 37 return 38 } 39 40 url := "" 41 if len(args) > 0 { 42 url = args[0] 43 } 44 45 if requests < concurrency { 46 panic("requests cannot be less than concurrency") 47 } 48 49 requests = concurrency * (requests / concurrency) 50 51 Perf(workdir, url, auth, repo, concurrency, requests, outFmt, srcIPs, srcCIDR, skipCleanup) 52 }, 53 } 54 55 rootCmd.Flags().StringVarP(&auth, "auth-creds", "A", "", 56 "Use colon-separated BASIC auth creds") 57 rootCmd.Flags().StringVarP(&srcIPs, "src-ips", "i", "", 58 "Use colon-separated ips to make requests from, src-ips and src-cidr are mutually exclusive") 59 rootCmd.Flags().StringVarP(&srcCIDR, "src-cidr", "s", "", 60 "Use specified cidr to obtain ips to make requests from, src-ips and src-cidr are mutually exclusive") 61 rootCmd.Flags().StringVarP(&workdir, "working-dir", "d", "", 62 "Use specified directory to store test data") 63 rootCmd.Flags().StringVarP(&repo, "repo", "r", "", 64 "Use specified repo on remote registry for test data") 65 rootCmd.Flags().IntVarP(&concurrency, "concurrency", "c", 1, 66 "Number of multiple requests to make at a time") 67 rootCmd.Flags().IntVarP(&requests, "requests", "n", 1, 68 "Number of requests to perform") 69 rootCmd.Flags().StringVarP(&outFmt, "output-format", "o", "", 70 "Output format of test results: stdout (default), json, ci-cd") 71 rootCmd.Flags().BoolVar(&skipCleanup, "skip-cleanup", false, 72 "Clean up pushed repos from remote registry after running benchmark (default true)") 73 74 // "version" 75 rootCmd.Flags().BoolVarP(&showVersion, "version", "v", false, "Show the version and exit") 76 77 return rootCmd 78 } 79 80 func main() { 81 if err := NewPerfRootCmd().Execute(); err != nil { 82 os.Exit(1) 83 } 84 }