root.go 1.9 KB

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