-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
61ba42b
commit 150e501
Showing
1,103 changed files
with
697,513 additions
and
3,691 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,16 @@ | ||
default: build | ||
|
||
all: build | ||
all: build | ||
|
||
build: chaos verifier | ||
|
||
chaos: | ||
chaos: rawkv tidb | ||
|
||
tidb: | ||
go build -o bin/chaos-tidb cmd/tidb/main.go | ||
|
||
rawkv: | ||
go build -o bin/chaos-rawkv cmd/rawkv/main.go | ||
|
||
verifier: | ||
go build -o bin/chaos-verifier cmd/verifier/main.go |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"log" | ||
"time" | ||
|
||
"github.com/siddontang/chaos/cmd/util" | ||
"github.com/siddontang/chaos/db/rawkv" | ||
"github.com/siddontang/chaos/pkg/control" | ||
"github.com/siddontang/chaos/pkg/core" | ||
) | ||
|
||
var ( | ||
requestCount = flag.Int("request-count", 500, "client test request count") | ||
runTime = flag.Duration("run-time", 10*time.Minute, "client test run time") | ||
clientCase = flag.String("case", "register", "client test case, like bank,multi_bank") | ||
historyFile = flag.String("history", "./history.log", "history file") | ||
nemesises = flag.String("nemesis", "", "nemesis, seperated by name, like random_kill,all_kill") | ||
verifyNames = flag.String("verifiers", "", "verifier names, seperate by comma, rawkv_register") | ||
) | ||
|
||
func main() { | ||
flag.Parse() | ||
|
||
cfg := control.Config{ | ||
DB: "rawkv", | ||
RequestCount: *requestCount, | ||
RunTime: *runTime, | ||
History: *historyFile, | ||
} | ||
|
||
var creator core.ClientCreator | ||
switch *clientCase { | ||
case "register": | ||
creator = rawkv.RegisterClientCreator{} | ||
default: | ||
log.Fatalf("invalid client test case %s", *clientCase) | ||
} | ||
|
||
suit := util.Suit{ | ||
Config: cfg, | ||
ClientCreator: creator, | ||
VerifyNames: *verifyNames, | ||
Nemesises: *nemesises, | ||
} | ||
suit.Run() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package util | ||
|
||
import ( | ||
"context" | ||
"log" | ||
"os" | ||
"os/signal" | ||
"strings" | ||
"syscall" | ||
|
||
"github.com/siddontang/chaos/cmd/verifier/verify" | ||
"github.com/siddontang/chaos/pkg/control" | ||
"github.com/siddontang/chaos/pkg/core" | ||
"github.com/siddontang/chaos/pkg/nemesis" | ||
) | ||
|
||
// Suit is a basic chaos testing suit with configurations to run chaos. | ||
type Suit struct { | ||
control.Config | ||
core.ClientCreator | ||
// verifier names, seperate by comma. | ||
VerifyNames string | ||
// nemesis, seperated by comma. | ||
Nemesises string | ||
} | ||
|
||
// Run runs the suit. | ||
func (suit *Suit) Run() { | ||
var nemesisGens []core.NemesisGenerator | ||
for _, name := range strings.Split(suit.Nemesises, ",") { | ||
var g core.NemesisGenerator | ||
name := strings.TrimSpace(name) | ||
if len(name) == 0 { | ||
continue | ||
} | ||
|
||
switch name { | ||
case "random_kill", "all_kill", "minor_kill", "major_kill": | ||
g = nemesis.NewKillGenerator(suit.Config.DB, name) | ||
case "random_drop", "all_drop", "minor_drop", "major_drop": | ||
g = nemesis.NewDropGenerator(name) | ||
default: | ||
log.Fatalf("invalid nemesis generator %s", name) | ||
} | ||
|
||
nemesisGens = append(nemesisGens, g) | ||
} | ||
|
||
c := control.NewController(&suit.Config, suit.ClientCreator, nemesisGens) | ||
|
||
sigs := make(chan os.Signal, 1) | ||
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM) | ||
|
||
ctx, cancel := context.WithCancel(context.Background()) | ||
|
||
go func() { | ||
<-sigs | ||
c.Close() | ||
cancel() | ||
}() | ||
|
||
c.Run() | ||
|
||
verify.Verify(ctx, suit.Config.History, suit.VerifyNames) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package rawkv | ||
|
||
import ( | ||
"github.com/siddontang/chaos/db/cluster" | ||
"github.com/siddontang/chaos/pkg/core" | ||
) | ||
|
||
// db is the TiDB database. | ||
type db struct { | ||
cluster.Cluster | ||
} | ||
|
||
// Name returns the unique name for the database | ||
func (db *db) Name() string { | ||
return "rawkv" | ||
} | ||
|
||
func init() { | ||
core.RegisterDB(&db{ | ||
// RawKV does not use TiDB. | ||
cluster.Cluster{IncludeTidb: false}, | ||
}) | ||
} |
Oops, something went wrong.