main.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // Copyright 2015 CoreOS, Inc.
  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.Int("stress-key-size", 100, "the size of each key written into etcd.")
  28. stressKeySuffixRange := flag.Int("stress-key-count", 250000, "the count of key range written into etcd.")
  29. limit := flag.Int("limit", 3, "the limit of rounds to run failure set.")
  30. schedCases := flag.String("schedule-cases", "", "test case schedule")
  31. isV2Only := flag.Bool("v2-only", false, "'true' to run V2 only tester.")
  32. flag.Parse()
  33. endpoints := strings.Split(*endpointStr, ",")
  34. c, err := newCluster(endpoints, *datadir, *stressKeySize, *stressKeySuffixRange, *isV2Only)
  35. if err != nil {
  36. plog.Fatal(err)
  37. }
  38. defer c.Terminate()
  39. failures := []failure{
  40. newFailureKillAll(),
  41. newFailureKillMajority(),
  42. newFailureKillOne(),
  43. newFailureKillLeader(),
  44. newFailureKillOneForLongTime(),
  45. newFailureKillLeaderForLongTime(),
  46. newFailureIsolate(),
  47. newFailureIsolateAll(),
  48. }
  49. schedule := failures
  50. if schedCases != nil && *schedCases != "" {
  51. cases := strings.Split(*schedCases, " ")
  52. schedule = make([]failure, len(cases))
  53. for i := range cases {
  54. caseNum := 0
  55. n, err := fmt.Sscanf(cases[i], "%d", &caseNum)
  56. if n == 0 || err != nil {
  57. plog.Fatalf(`couldn't parse case "%s" (%v)`, cases[i], err)
  58. }
  59. schedule[i] = failures[caseNum]
  60. }
  61. }
  62. t := &tester{
  63. failures: schedule,
  64. cluster: c,
  65. limit: *limit,
  66. }
  67. sh := statusHandler{status: &t.status}
  68. http.Handle("/status", sh)
  69. http.Handle("/metrics", prometheus.Handler())
  70. go func() { plog.Fatal(http.ListenAndServe(":9028", nil)) }()
  71. t.runLoop()
  72. }