Documentation ¶
Index ¶
- Constants
- func RegisterDB(db DB)
- func RegisterNemesis(n Nemesis)
- type ChaosKind
- type Checker
- type Client
- type ClientCreator
- type DB
- type DelayNemesisGenerator
- type Model
- type Nemesis
- type NemesisControl
- type NemesisGenerator
- type NemesisGeneratorRecord
- type NemesisGenerators
- type NemesisOperation
- type NoopChecker
- type NoopClientCreator
- type NoopDB
- type OneRoundNemesisGenerators
- type Operation
- type UnknownResponse
Constants ¶
const ( InvokeOperation = "call" ReturnOperation = "return" InvokeNemesis = "inject" RecoverNemesis = "recover" )
Operation action
Variables ¶
This section is empty.
Functions ¶
func RegisterNemesis ¶
func RegisterNemesis(n Nemesis)
RegisterNemesis registers nemesis. Not thread-safe.
Types ¶
type ChaosKind ¶
type ChaosKind string
ChaosKind is the kind of applying chaos
const ( // PodFailure Applies pod failure PodFailure ChaosKind = "pod-failure" // PodKill will random kill a pod, this will make the Node be illegal PodKill ChaosKind = "pod-kill" // ContainerKill will random kill the specified container of pod, but retain the pod ContainerKill ChaosKind = "container-kill" // NetworkPartition partitions network between nodes NetworkPartition ChaosKind = "network-partition" // NetemChaos adds corrupt or other chaos. NetemChaos ChaosKind = "netem-chaos" // TimeChaos means TimeChaos ChaosKind = "time-chaos" // PDScheduler adds scheduler PDScheduler ChaosKind = "pd-scheduler" // PDLeaderShuffler will randomly shuffle pds. PDLeaderShuffler ChaosKind = "pd-leader-shuffler" // Scaling scales cluster Scaling ChaosKind = "scaling" // IOChaos adds io chaos. IOChaos ChaosKind = "io-chaos" )
type Checker ¶
type Checker interface { // Check a series of operations with the given model. // Return false or error if operations do not satisfy the model. Check(m Model, ops []Operation) (bool, error) // Name returns the unique name for the checker. Name() string }
Checker checks a history of operations.
func MultiChecker ¶
MultiChecker assembles multiple checkers
type Client ¶
type Client interface { // SetUp sets up the client. SetUp(ctx context.Context, nodes []cluster.Node, clientNodes []cluster.ClientNode, idx int) error // TearDown tears down the client. TearDown(ctx context.Context, nodes []cluster.ClientNode, idx int) error // Invoke invokes a request to the database. // Mostly, the return Response should implement UnknownResponse interface Invoke(ctx context.Context, node cluster.ClientNode, r interface{}) UnknownResponse // NextRequest generates a request for latter Invoke. NextRequest() interface{} // DumpState the database state(also the model's state) DumpState(ctx context.Context) (interface{}, error) // Start runs self scheduled cases // this function will block Invoke trigger // if you want to schedule cases by yourself, use this function only Start(ctx context.Context, cfg interface{}, clientNodes []cluster.ClientNode) error }
Client applies the request to the database. Client is used in control. You should define your own client for your database.
type ClientCreator ¶
type ClientCreator interface { // Create creates the client. Create(node cluster.ClientNode) Client }
ClientCreator creates a client. The control will create one client for one node.
type DB ¶
type DB interface { // SetUp initializes the database. SetUp(ctx context.Context, nodes []cluster.Node, node cluster.Node) error // TearDown tears down the database. TearDown(ctx context.Context, nodes []cluster.Node, node cluster.Node) error // Name returns the unique name for the database Name() string }
DB allows to set up and tear down database.
type DelayNemesisGenerator ¶
type DelayNemesisGenerator struct { Gen NemesisGenerator Delay time.Duration }
DelayNemesisGenerator delays nemesis generation after `Delay`
func (DelayNemesisGenerator) Generate ¶
func (d DelayNemesisGenerator) Generate(nodes []cluster.Node) []*NemesisOperation
Generate ...
type Model ¶
type Model interface { // Prepare the initial state of the data object. Prepare(state interface{}) // Initial state of the data object. Init() interface{} // Step function for the data object. Returns whether or not the system // could take this step with the given inputs and outputs and also // returns the new state. This should not mutate the existing state. // // state must support encoding to and decoding from json. Step(state interface{}, input interface{}, output interface{}) (bool, interface{}) // Equality on states. Equal(state1, state2 interface{}) bool // Name returns the unique name for the model. Name() string }
Model specifies the behavior of a data object.
type Nemesis ¶
type Nemesis interface { // Invoke executes the nemesis Invoke(ctx context.Context, node *cluster.Node, args ...interface{}) error // Recover recovers the nemesis Recover(ctx context.Context, node *cluster.Node, args ...interface{}) error // Name returns the unique name for the nemesis Name() string }
Nemesis injects failure and disturbs the database.
type NemesisControl ¶
type NemesisControl struct {
// contains filtered or unexported fields
}
NemesisControl is used to operate nemesis between the control side and test client side
func (*NemesisControl) Rollback ¶
func (n *NemesisControl) Rollback(ctx context.Context)
Rollback is used on client side to enable control side rollbacking nemesis
func (*NemesisControl) Start ¶
func (n *NemesisControl) Start(ctx context.Context)
Start is used on client side to enable control side starting nemesis
func (*NemesisControl) WaitForRollback ¶
func (n *NemesisControl) WaitForRollback(ctx context.Context)
WaitForRollback is used on control side to wait for enabling rollback nemesis
func (*NemesisControl) WaitForStart ¶
func (n *NemesisControl) WaitForStart()
WaitForStart is used on control side to wait for enabling start nemesis
type NemesisGenerator ¶
type NemesisGenerator interface { // Generate generates the nemesis operation for all nodes. // Every node will be assigned a nemesis operation. Generate(nodes []cluster.Node) []*NemesisOperation Name() string }
NemesisGenerator is used in control, it will generate a nemesis operation and then the control can use it to disturb the cluster.
type NemesisGeneratorRecord ¶
type NemesisGeneratorRecord struct { Name string Ops []*NemesisOperation }
NemesisGeneratorRecord is used to record operations generated by NemesisGenerator.Generate
type NemesisGenerators ¶
type NemesisGenerators interface { Next() NemesisGenerator HasNext() bool // Reset resets iterator, return false if it cannot be reset Reset() bool }
NemesisGenerators is a NemesisGenerator iterator
func NewNemesisGenerators ¶
func NewNemesisGenerators(gens []NemesisGenerator) NemesisGenerators
NewNemesisGenerators ...
func NewOneRoundNemesisGenerators ¶
func NewOneRoundNemesisGenerators(gen NemesisGenerator) NemesisGenerators
NewOneRoundNemesisGenerators ...
type NemesisOperation ¶
type NemesisOperation struct { Type ChaosKind // Nemesis name Node *cluster.Node // Nemesis target node, optional if it affects InvokeArgs []interface{} // Nemesis invoke args RecoverArgs []interface{} // Nemesis recover args // We have two approaches to trigger recovery // 1. through `RunTime` // 2. through `NemesisControl` WaitForRollback RunTime time.Duration // Nemesis duration time NemesisControl *NemesisControl // Nemesis recovery signal }
NemesisOperation is nemesis operation used in control.
type NoopChecker ¶
type NoopChecker struct{}
NoopChecker is a noop checker.
type NoopDB ¶
type NoopDB struct { }
NoopDB is a DB but does nothing
type OneRoundNemesisGenerators ¶
type OneRoundNemesisGenerators struct {
// contains filtered or unexported fields
}
OneRoundNemesisGenerators is easier than nemesisGenerators, and suitable in cases that need to interact between client and control
func (*OneRoundNemesisGenerators) HasNext ¶
func (m *OneRoundNemesisGenerators) HasNext() bool
HasNext ...
func (*OneRoundNemesisGenerators) Next ¶
func (m *OneRoundNemesisGenerators) Next() NemesisGenerator
Next ...
func (*OneRoundNemesisGenerators) Reset ¶
func (m *OneRoundNemesisGenerators) Reset() bool
Reset just returns false because we forbid reset for OneRoundNemesisGenerators
type Operation ¶
type Operation struct { Action string `json:"action"` Proc int64 `json:"proc"` Data interface{} `json:"data"` Time time.Time `json:"time"` }
Operation of a data object.
type UnknownResponse ¶
type UnknownResponse interface {
IsUnknown() bool
}
UnknownResponse means we don't know whether this operation succeeds or not.