Documentation
¶
Index ¶
- Constants
- Variables
- type AttackConfig
- type BandwidthSpec
- type ChainDirection
- type Cidr
- type CommonAttackConfig
- type CorruptSpec
- type DdOption
- type DelaySpec
- type DiskAttackConfig
- type DiskOption
- type DuplicateSpec
- type Experiment
- type ExperimentRun
- type ExperimentRunStore
- type ExperimentStore
- type FAllocateOption
- type HostCommand
- type IPSetRule
- type IPSetRuleStore
- type IptablesRule
- type IptablesRuleList
- type IptablesRuleStore
- type JVMCommand
- type LossSpec
- type NetemSpec
- type NetworkCommand
- func (n *NetworkCommand) CompleteDefaults()
- func (n *NetworkCommand) NeedApplyDNSServer() bool
- func (n *NetworkCommand) NeedApplyEtcHosts() bool
- func (n *NetworkCommand) NeedApplyIPSet() bool
- func (n *NetworkCommand) NeedApplyIptables() bool
- func (n *NetworkCommand) NeedApplyTC() bool
- func (n NetworkCommand) RecoverData() string
- func (n *NetworkCommand) ToChain() (*pb.Chain, error)
- func (n *NetworkCommand) ToCorruptNetem() (*pb.Netem, error)
- func (n *NetworkCommand) ToDelayNetem() (*pb.Netem, error)
- func (n *NetworkCommand) ToDuplicateNetem() (*pb.Netem, error)
- func (n *NetworkCommand) ToIPSet(name string) (*pb.IPSet, error)
- func (n *NetworkCommand) ToLossNetem() (*pb.Netem, error)
- func (n *NetworkCommand) ToTC(ipset string) (*pb.Tc, error)
- func (n *NetworkCommand) Validate() error
- type ProcessCommand
- type ReorderSpec
- type SchedulerConfig
- type SearchCommand
- type StressCommand
- type TCRule
- type TCRuleList
- type TCRuleStore
- type TcParameter
Constants ¶
const ( DiskFillAction = "fill" DiskWritePayloadAction = "write-payload" DiskReadPayloadAction = "read-payload" )
const ( Created = "created" Success = "success" Error = "error" Scheduled = "scheduled" Destroyed = "destroyed" Revoked = "revoked" )
const ( ProcessAttack = "process" NetworkAttack = "network" StressAttack = "stress" DiskAttack = "disk" HostAttack = "host" JVMAttack = "jvm" )
const ( ServerMode = "svr" CommandMode = "cmd" )
const ( RunStarted = "started" RunFailed = "failed" RunSuccess = "success" RunRecovered = "recovered" )
const ( JVMInstallType = "install" JVMSubmitType = "submit" JVMLatencyAction = "latency" JVMExceptionAction = "exception" JVMReturnAction = "return" JVMStressAction = "stress" JVMGCAction = "gc" JVMRuleFileAction = "rule_file" )
const ( NetworkDelayAction = "delay" NetworkLossAction = "loss" NetworkCorruptAction = "corrupt" NetworkDuplicateAction = "duplicate" NetworkDNSAction = "dns" NetworkPortOccupied = "occupied" )
const ( ProcessKillAction = "kill" ProcessStopAction = "stop" )
const ( StressCPUAction = "cpu" StressMemAction = "mem" )
const (
HostShutdownAction = "shutdown"
)
Variables ¶
var ( ErrNs = errorx.NewNamespace("error.core") ErrAttackConfigValidation = ErrNs.NewType("attack_config_validation_error") ErrNonRecoverableAttack = ErrNs.NewType("non_recoverable_attack") )
var DdCommand = utils.Command{Name: "dd"}
var FAllocateCommand = utils.Command{Name: "fallocate"}
Functions ¶
This section is empty.
Types ¶
type AttackConfig ¶ added in v1.0.0
type AttackConfig interface {
Validate() error
Cron() string
ScheduleDuration() (*time.Duration, error)
// String is replacement of .Action
String() string
// RecoverData is replacement of earlier .String()
RecoverData() string
// AttackKind returns the kind of attack
AttackKind() string
// CompleteDefaults is used to fill flags with default values
CompleteDefaults()
// GetUID returns the experiment's ID
GetUID() string
}
func GetAttackByKind ¶ added in v1.0.2
func GetAttackByKind(kind string) *AttackConfig
type BandwidthSpec ¶
type BandwidthSpec struct {
// Rate is the speed knob. Allows bps, kbps, mbps, gbps, tbps unit. bps means bytes per second.
Rate string `json:"rate"`
// Limit is the number of bytes that can be queued waiting for tokens to become available.
Limit uint32 `json:"limit"`
// Buffer is the maximum amount of bytes that tokens can be available for instantaneously.
Buffer uint32 `json:"buffer"`
// Peakrate is the maximum depletion rate of the bucket.
// The peakrate does not need to be set, it is only necessary
// if perfect millisecond timescale shaping is required.
Peakrate *uint64 `json:"peakrate,omitempty"`
// Minburst specifies the size of the peakrate bucket. For perfect
// accuracy, should be set to the MTU of the interface. If a
// peakrate is needed, but some burstiness is acceptable, this
// size can be raised. A 3000 byte minburst allows around 3mbit/s
// of peakrate, given 1000 byte packets.
Minburst *uint32 `json:"minburst,omitempty"`
}
BandwidthSpec defines detail of bandwidth limit.
func (*BandwidthSpec) ToTbf ¶
func (in *BandwidthSpec) ToTbf() (*pb.Tbf, error)
ToTbf converts BandwidthSpec to *chaosdaemonpb.Tbf Bandwidth action use TBF under the hood. TBF stands for Token Bucket Filter, is a classful queueing discipline available for traffic control with the tc command. http://man7.org/linux/man-pages/man8/tc-tbf.8.html
type CommonAttackConfig ¶ added in v1.0.0
type CommonAttackConfig struct {
SchedulerConfig
Action string `json:"action"`
Kind string `json:"kind"`
UID string `json:"uid"`
}
func (CommonAttackConfig) AttackKind ¶ added in v1.0.0
func (config CommonAttackConfig) AttackKind() string
func (*CommonAttackConfig) CompleteDefaults ¶ added in v1.0.0
func (config *CommonAttackConfig) CompleteDefaults()
CompleteDefaults no-op implementation
func (*CommonAttackConfig) GetUID ¶ added in v1.0.2
func (config *CommonAttackConfig) GetUID() string
func (CommonAttackConfig) String ¶ added in v1.0.0
func (config CommonAttackConfig) String() string
func (*CommonAttackConfig) Validate ¶ added in v1.0.0
func (config *CommonAttackConfig) Validate() error
Validate does a basic validation of common parameters
type CorruptSpec ¶
CorruptSpec defines detail of a corrupt action
type DelaySpec ¶
type DelaySpec struct {
Latency string `json:"latency"`
Correlation string `json:"correlation,omitempty"`
Jitter string `json:"jitter,omitempty"`
Reorder *ReorderSpec `json:"reorder,omitempty"`
}
DelaySpec defines detail of a delay action
type DiskAttackConfig ¶ added in v1.0.2
type DiskAttackConfig struct {
CommonAttackConfig
DdOptions *[]DdOption
FAllocateOption *FAllocateOption
Path string
}
func (DiskAttackConfig) RecoverData ¶ added in v1.0.2
func (d DiskAttackConfig) RecoverData() string
type DiskOption ¶ added in v1.0.0
type DiskOption struct {
CommonAttackConfig
Size string `json:"size"`
Path string `json:"path"`
Percent string `json:"percent"`
PayloadProcessNum uint8 `json:"payload_process_num"`
FillByFAllocate bool `json:"fill_by_fallocate"`
}
func NewDiskOption ¶ added in v1.0.0
func NewDiskOption() *DiskOption
func (*DiskOption) PreProcess ¶ added in v1.0.2
func (opt *DiskOption) PreProcess() (*DiskAttackConfig, error)
type DuplicateSpec ¶
type DuplicateSpec struct {
Duplicate string `json:"duplicate"`
Correlation string `json:"correlation"`
}
DuplicateSpec defines detail of a duplicate action
type Experiment ¶
type Experiment struct {
ID uint `gorm:"primary_key" json:"id"`
Uid string `gorm:"index:uid" json:"uid"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Status string `json:"status"`
Message string `json:"error"`
// TODO: need to improve
Kind string `json:"kind"`
Action string `json:"action"`
RecoverCommand string `json:"recover_command"`
LaunchMode string `json:"launch_mode"`
// contains filtered or unexported fields
}
Experiment represents an experiment instance.
func (*Experiment) GetRequestCommand ¶ added in v1.0.0
func (exp *Experiment) GetRequestCommand() (AttackConfig, error)
func (Experiment) NewRun ¶ added in v1.0.0
func (exp Experiment) NewRun() *ExperimentRun
type ExperimentRun ¶ added in v1.0.0
type ExperimentRun struct {
ID uint `gorm:"primary_key" json:"id"`
UID string `gorm:"index:uid" json:"uid"`
StartAt time.Time `gorm:"autoCreateTime" json:"start_at"`
FinishedAt time.Time `json:"finished_at"`
Status string `json:"status"`
Message string `json:"error"`
ExperimentID uint
Experiment Experiment `gorm:"foreignKey:ExperimentID" json:"experiment"`
}
ExperimentRun represents a run of an experiment
type ExperimentRunStore ¶ added in v1.0.0
type ExperimentRunStore interface {
ListByExperimentID(ctx context.Context, id uint) ([]*ExperimentRun, error)
ListByExperimentUID(ctx context.Context, uid string) ([]*ExperimentRun, error)
LatestRun(ctx context.Context, id uint) (*ExperimentRun, error)
NewRun(ctx context.Context, expRun *ExperimentRun) error
Update(ctx context.Context, runUid string, status string, message string) error
}
ExperimentRunStore defines operations for working with experiment runs
type ExperimentStore ¶
type ExperimentStore interface {
List(ctx context.Context) ([]*Experiment, error)
ListByLaunchMode(ctx context.Context, mode string) ([]*Experiment, error)
ListByConditions(ctx context.Context, conds *SearchCommand) ([]*Experiment, error)
ListByStatus(ctx context.Context, status string) ([]*Experiment, error)
FindByUid(ctx context.Context, uid string) (*Experiment, error)
Set(ctx context.Context, exp *Experiment) error
Update(ctx context.Context, uid, status, msg string, command string) error
}
ExperimentStore defines operations for working with experiments
type FAllocateOption ¶ added in v1.0.2
type HostCommand ¶
type HostCommand struct {
CommonAttackConfig
}
func NewHostCommand ¶ added in v1.0.0
func NewHostCommand() *HostCommand
func (HostCommand) RecoverData ¶ added in v1.0.0
func (h HostCommand) RecoverData() string
func (*HostCommand) Validate ¶
func (h *HostCommand) Validate() error
type IPSetRuleStore ¶
type IptablesRule ¶
type IptablesRule struct {
gorm.Model
// The name of iptables chain
Name string `gorm:"index:name" json:"name"`
// The name of related ipset
IPSets string `json:"ipsets"`
// The block direction of this iptables rule
Direction string `json:"direction"`
// Experiment represents the experiment which the rule belong to.
Experiment string `gorm:"index:experiment" json:"experiment"`
}
func (*IptablesRule) ToChain ¶
func (i *IptablesRule) ToChain() *pb.Chain
type IptablesRuleList ¶
type IptablesRuleList []*IptablesRule
func (IptablesRuleList) ToChains ¶
func (l IptablesRuleList) ToChains() []*pb.Chain
type IptablesRuleStore ¶
type JVMCommand ¶ added in v1.0.0
type JVMCommand struct {
CommonAttackConfig
// rule name, should be unique, and will generate by chaosd automatically
Name string
// Java class
Class string
// the method in Java class
Method string
// fault action, values can be latency, exception, return, stress
Action string
// the return value for action 'return'
ReturnValue string
// the exception which needs to throw dor action `exception`
ThrowException string
// the latency duration for action 'latency'
LatencyDuration string
// the CPU core number need to use, only set it when action is stress
CPUCount int
// the memory size need to locate, only set it when action is stress
MemorySize int
// attach or agent
Type string
// the port of agent server
Port int
// the pid of Java process which need to attach
Pid int
// below is only used for template
Do string
StressType string
StressValueName string
StressValue int
// btm rule file path
RuleFile string
// RuleData used to save the rule file's data, will use it when recover
RuleData []byte
}
func NewJVMCommand ¶ added in v1.0.0
func NewJVMCommand() *JVMCommand
func (*JVMCommand) CompleteDefaults ¶ added in v1.0.0
func (j *JVMCommand) CompleteDefaults()
func (*JVMCommand) RecoverData ¶ added in v1.0.0
func (j *JVMCommand) RecoverData() string
func (*JVMCommand) Validate ¶ added in v1.0.0
func (j *JVMCommand) Validate() error
type NetworkCommand ¶
type NetworkCommand struct {
CommonAttackConfig
Latency string
Jitter string
Correlation string
Percent string
Device string
SourcePort string
EgressPort string
IPAddress string
IPProtocol string
Hostname string
// used for DNS attack
DNSServer string
Port string
PortPid int32
DNSIp string
DNSHost string
}
func NewNetworkCommand ¶ added in v1.0.0
func NewNetworkCommand() *NetworkCommand
func (*NetworkCommand) CompleteDefaults ¶ added in v1.0.0
func (n *NetworkCommand) CompleteDefaults()
func (*NetworkCommand) NeedApplyDNSServer ¶ added in v1.0.0
func (n *NetworkCommand) NeedApplyDNSServer() bool
func (*NetworkCommand) NeedApplyEtcHosts ¶ added in v1.0.0
func (n *NetworkCommand) NeedApplyEtcHosts() bool
func (*NetworkCommand) NeedApplyIPSet ¶
func (n *NetworkCommand) NeedApplyIPSet() bool
func (*NetworkCommand) NeedApplyIptables ¶
func (n *NetworkCommand) NeedApplyIptables() bool
func (*NetworkCommand) NeedApplyTC ¶
func (n *NetworkCommand) NeedApplyTC() bool
func (NetworkCommand) RecoverData ¶ added in v1.0.0
func (n NetworkCommand) RecoverData() string
func (*NetworkCommand) ToCorruptNetem ¶
func (n *NetworkCommand) ToCorruptNetem() (*pb.Netem, error)
func (*NetworkCommand) ToDelayNetem ¶
func (n *NetworkCommand) ToDelayNetem() (*pb.Netem, error)
func (*NetworkCommand) ToDuplicateNetem ¶
func (n *NetworkCommand) ToDuplicateNetem() (*pb.Netem, error)
func (*NetworkCommand) ToLossNetem ¶
func (n *NetworkCommand) ToLossNetem() (*pb.Netem, error)
func (*NetworkCommand) Validate ¶
func (n *NetworkCommand) Validate() error
type ProcessCommand ¶
type ProcessCommand struct {
CommonAttackConfig
// Process defines the process name or the process ID.
Process string
Signal int
PIDs []int
}
func NewProcessCommand ¶ added in v1.0.0
func NewProcessCommand() *ProcessCommand
func (ProcessCommand) RecoverData ¶ added in v1.0.0
func (p ProcessCommand) RecoverData() string
func (*ProcessCommand) Validate ¶
func (p *ProcessCommand) Validate() error
type ReorderSpec ¶
type ReorderSpec struct {
Reorder string `json:"reorder"`
Correlation string `json:"correlation"`
Gap int `json:"gap"`
}
ReorderSpec defines details of packet reorder.
type SchedulerConfig ¶ added in v1.0.0
func (SchedulerConfig) Cron ¶ added in v1.0.0
func (config SchedulerConfig) Cron() string
func (SchedulerConfig) ScheduleDuration ¶ added in v1.0.0
func (config SchedulerConfig) ScheduleDuration() (*time.Duration, error)
type SearchCommand ¶
type SearchCommand struct {
Asc bool
All bool
Status string
Kind string
Limit uint32
Offset uint32
UID string
}
func (SearchCommand) Validate ¶
func (s SearchCommand) Validate() error
type StressCommand ¶
type StressCommand struct {
CommonAttackConfig
Load int
Workers int
Size string
Options []string
StressngPid int32
}
func NewStressCommand ¶ added in v1.0.0
func NewStressCommand() *StressCommand
func (*StressCommand) CompleteDefaults ¶ added in v1.0.2
func (s *StressCommand) CompleteDefaults()
func (StressCommand) RecoverData ¶ added in v1.0.0
func (s StressCommand) RecoverData() string
func (*StressCommand) Validate ¶
func (s *StressCommand) Validate() error
type TCRule ¶
type TCRule struct {
gorm.Model
Device string `json:"device"`
// The type of traffic control
Type string `json:"type"`
TC string `json:"tc"`
// The name of target ipset
IPSet string `json:"ipset,omitempty"`
// Experiment represents the experiment which the rule belong to.
Experiment string `gorm:"index:experiment" json:"experiment"`
Protocal string
SourcePort string
EgressPort string
}
type TCRuleList ¶
type TCRuleList []*TCRule
type TCRuleStore ¶
type TCRuleStore interface {
List(ctx context.Context) ([]*TCRule, error)
ListGroupDevice(ctx context.Context) (map[string][]*TCRule, error)
Set(ctx context.Context, rule *TCRule) error
FindByDevice(ctx context.Context, experiment string) ([]*TCRule, error)
FindByExperiment(ctx context.Context, experiment string) ([]*TCRule, error)
DeleteByExperiment(ctx context.Context, experiment string) error
}
type TcParameter ¶
type TcParameter struct {
Device string
// Delay represents the detail about delay action
Delay *DelaySpec `json:"delay,omitempty"`
// Loss represents the detail about loss action
Loss *LossSpec `json:"loss,omitempty"`
// DuplicateSpec represents the detail about loss action
Duplicate *DuplicateSpec `json:"duplicate,omitempty"`
// Corrupt represents the detail about corrupt action
Corrupt *CorruptSpec `json:"corrupt,omitempty"`
// Bandwidth represents the detail about bandwidth control action
Bandwidth *BandwidthSpec `json:"bandwidth,omitempty"`
}
TcParameter represents the parameters for a traffic control chaos