root.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. package command
  15. import (
  16. "log"
  17. "math/rand"
  18. "time"
  19. "github.com/spf13/cobra"
  20. )
  21. const (
  22. cliName = "etcd-runner"
  23. cliDescription = "Stress tests using clientv3 functionality.."
  24. defaultDialTimeout = 2 * time.Second
  25. )
  26. var (
  27. rootCmd = &cobra.Command{
  28. Use: cliName,
  29. Short: cliDescription,
  30. SuggestFor: []string{"etcd-runner"},
  31. }
  32. )
  33. func init() {
  34. cobra.EnablePrefixMatching = true
  35. rand.Seed(time.Now().UnixNano())
  36. log.SetFlags(log.Lmicroseconds)
  37. rootCmd.PersistentFlags().StringSliceVar(&endpoints, "endpoints", []string{"127.0.0.1:2379"}, "gRPC endpoints")
  38. rootCmd.PersistentFlags().DurationVar(&dialTimeout, "dial-timeout", defaultDialTimeout, "dial timeout for client connections")
  39. rootCmd.PersistentFlags().IntVar(&reqRate, "req-rate", 30, "maximum number of requests per second")
  40. rootCmd.PersistentFlags().IntVar(&rounds, "rounds", 100, "number of rounds to run; 0 to run forever")
  41. rootCmd.AddCommand(
  42. NewElectionCommand(),
  43. NewLeaseRenewerCommand(),
  44. NewLockRacerCommand(),
  45. NewWatchCommand(),
  46. )
  47. }
  48. func Start() {
  49. rootCmd.SetUsageFunc(usageFunc)
  50. // Make help just show the usage
  51. rootCmd.SetHelpTemplate(`{{.UsageString}}`)
  52. if err := rootCmd.Execute(); err != nil {
  53. ExitWithError(ExitError, err)
  54. }
  55. }