main.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. // Copyright 2015 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 main
  15. import (
  16. "flag"
  17. "fmt"
  18. "net/http"
  19. "strings"
  20. "github.com/coreos/pkg/capnslog"
  21. "github.com/prometheus/client_golang/prometheus"
  22. )
  23. var plog = capnslog.NewPackageLogger("github.com/coreos/etcd", "etcd-tester")
  24. func main() {
  25. endpointStr := flag.String("agent-endpoints", "localhost:9027", "HTTP RPC endpoints of agents. Do not specify the schema.")
  26. datadir := flag.String("data-dir", "agent.etcd", "etcd data directory location on agent machine.")
  27. stressKeySize := flag.Uint("stress-key-size", 100, "the size of each key written into etcd.")
  28. stressKeySuffixRange := flag.Uint("stress-key-count", 250000, "the count of key range written into etcd.")
  29. stressKeyRangeLimit := flag.Uint("stress-range-limit", 50, "maximum number of keys to range or delete.")
  30. limit := flag.Int("limit", -1, "the limit of rounds to run failure set (-1 to run without limits).")
  31. stressQPS := flag.Int("stress-qps", 10000, "maximum number of stresser requests per second.")
  32. schedCases := flag.String("schedule-cases", "", "test case schedule")
  33. consistencyCheck := flag.Bool("consistency-check", true, "true to check consistency (revision, hash)")
  34. isV2Only := flag.Bool("v2-only", false, "'true' to run V2 only tester.")
  35. flag.Parse()
  36. c := &cluster{
  37. v2Only: *isV2Only,
  38. datadir: *datadir,
  39. stressQPS: *stressQPS,
  40. stressKeySize: int(*stressKeySize),
  41. stressKeySuffixRange: int(*stressKeySuffixRange),
  42. stressKeyRangeLimit: int(*stressKeyRangeLimit),
  43. }
  44. if err := c.bootstrap(strings.Split(*endpointStr, ",")); err != nil {
  45. plog.Fatal(err)
  46. }
  47. defer c.Terminate()
  48. failures := []failure{
  49. newFailureKillAll(),
  50. newFailureKillMajority(),
  51. newFailureKillOne(),
  52. newFailureKillLeader(),
  53. newFailureKillOneForLongTime(),
  54. newFailureKillLeaderForLongTime(),
  55. newFailureIsolate(),
  56. newFailureIsolateAll(),
  57. newFailureSlowNetworkOneMember(),
  58. newFailureSlowNetworkLeader(),
  59. newFailureSlowNetworkAll(),
  60. }
  61. // ensure cluster is fully booted to know failpoints are available
  62. c.WaitHealth()
  63. fpFailures, fperr := failpointFailures(c)
  64. if len(fpFailures) == 0 {
  65. plog.Infof("no failpoints found (%v)", fperr)
  66. }
  67. failures = append(failures, fpFailures...)
  68. schedule := failures
  69. if schedCases != nil && *schedCases != "" {
  70. cases := strings.Split(*schedCases, " ")
  71. schedule = make([]failure, len(cases))
  72. for i := range cases {
  73. caseNum := 0
  74. n, err := fmt.Sscanf(cases[i], "%d", &caseNum)
  75. if n == 0 || err != nil {
  76. plog.Fatalf(`couldn't parse case "%s" (%v)`, cases[i], err)
  77. }
  78. schedule[i] = failures[caseNum]
  79. }
  80. }
  81. t := &tester{
  82. failures: schedule,
  83. cluster: c,
  84. limit: *limit,
  85. consistencyCheck: *consistencyCheck,
  86. }
  87. sh := statusHandler{status: &t.status}
  88. http.Handle("/status", sh)
  89. http.Handle("/metrics", prometheus.Handler())
  90. go func() { plog.Fatal(http.ListenAndServe(":9028", nil)) }()
  91. t.runLoop()
  92. }