go.etcd.io/etcd@v3.3.27+incompatible/functional/runner/root.go (about) 1 // Copyright 2017 The etcd Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 // Package runner implements individual etcd-runner commands for the etcd-runner utility. 16 package runner 17 18 import ( 19 "log" 20 "math/rand" 21 "time" 22 23 "github.com/spf13/cobra" 24 ) 25 26 const ( 27 cliName = "etcd-runner" 28 cliDescription = "Stress tests using clientv3 functionality.." 29 30 defaultDialTimeout = 2 * time.Second 31 ) 32 33 var ( 34 rootCmd = &cobra.Command{ 35 Use: cliName, 36 Short: cliDescription, 37 SuggestFor: []string{"etcd-runner"}, 38 } 39 ) 40 41 func init() { 42 cobra.EnablePrefixMatching = true 43 44 rand.Seed(time.Now().UnixNano()) 45 46 log.SetFlags(log.Lmicroseconds) 47 48 rootCmd.PersistentFlags().StringSliceVar(&endpoints, "endpoints", []string{"127.0.0.1:2379"}, "gRPC endpoints") 49 rootCmd.PersistentFlags().DurationVar(&dialTimeout, "dial-timeout", defaultDialTimeout, "dial timeout for client connections") 50 rootCmd.PersistentFlags().IntVar(&reqRate, "req-rate", 30, "maximum number of requests per second") 51 rootCmd.PersistentFlags().IntVar(&rounds, "rounds", 100, "number of rounds to run; 0 to run forever") 52 53 rootCmd.AddCommand( 54 NewElectionCommand(), 55 NewLeaseRenewerCommand(), 56 NewLockRacerCommand(), 57 NewWatchCommand(), 58 ) 59 } 60 61 func Start() { 62 rootCmd.SetUsageFunc(usageFunc) 63 64 // Make help just show the usage 65 rootCmd.SetHelpTemplate(`{{.UsageString}}`) 66 67 if err := rootCmd.Execute(); err != nil { 68 ExitWithError(ExitError, err) 69 } 70 }