Documentation
¶
Index ¶
- Constants
- Variables
- func AddExecutorToModelSpec(executor Executor, expSpecs ...ExpModelCommandSpec)
- func AddFlagsToModelSpec(flagsFunc func() []ExpFlagSpec, expSpecs ...ExpModelCommandSpec)
- func ConvertExpMatchersToString(expModel *ExpModel, createExcludeKeyFunc func() map[string]Empty) string
- func IsDestroy(ctx context.Context) (string, bool)
- func SetDestroyFlag(ctx context.Context, suid string) context.Context
- type ActionModel
- func (am *ActionModel) Aliases() []string
- func (am *ActionModel) Categories() []string
- func (am *ActionModel) Example() string
- func (am *ActionModel) Executor() Executor
- func (am *ActionModel) Flags() []ExpFlagSpec
- func (am *ActionModel) LongDesc() string
- func (am *ActionModel) Matchers() []ExpFlagSpec
- func (am *ActionModel) Name() string
- func (am *ActionModel) ProcessHang() bool
- func (am *ActionModel) Programs() []string
- func (am *ActionModel) SetCategories(categories []string)
- func (am *ActionModel) SetExample(example string)
- func (am *ActionModel) SetExecutor(executor Executor)
- func (am *ActionModel) SetLongDesc(longDesc string)
- func (am *ActionModel) ShortDesc() string
- type BaseExpActionCommandSpec
- func (b *BaseExpActionCommandSpec) Categories() []string
- func (b *BaseExpActionCommandSpec) Example() string
- func (b *BaseExpActionCommandSpec) Executor() Executor
- func (b *BaseExpActionCommandSpec) Flags() []ExpFlagSpec
- func (b *BaseExpActionCommandSpec) Matchers() []ExpFlagSpec
- func (b *BaseExpActionCommandSpec) ProcessHang() bool
- func (b *BaseExpActionCommandSpec) Programs() []string
- func (b *BaseExpActionCommandSpec) SetCategories(categories []string)
- func (b *BaseExpActionCommandSpec) SetExample(example string)
- func (b *BaseExpActionCommandSpec) SetExecutor(executor Executor)
- func (b *BaseExpActionCommandSpec) SetLongDesc(longDesc string)
- type BaseExpModelCommandSpec
- type Channel
- type CodeType
- type Empty
- type Executor
- type ExpActionCommandSpec
- type ExpCommandModel
- func (ecm *ExpCommandModel) Actions() []ExpActionCommandSpec
- func (ecm *ExpCommandModel) Flags() []ExpFlagSpec
- func (ecm *ExpCommandModel) LongDesc() string
- func (ecm *ExpCommandModel) Name() string
- func (ecm *ExpCommandModel) Scope() string
- func (ecm *ExpCommandModel) SetFlags(flags []ExpFlagSpec)
- func (ecm *ExpCommandModel) ShortDesc() string
- type ExpFlag
- type ExpFlagSpec
- type ExpModel
- type ExpModelCommandSpec
- type ExpPrepareModel
- type Models
- type Response
- func Decode(content string, defaultValue *Response) *Response
- func ResponseFail(status int32, err string, result interface{}) *Response
- func ResponseFailWithFlags(codeType CodeType, flags ...interface{}) *Response
- func ResponseFailWithResult(codeType CodeType, result interface{}, flags ...interface{}) *Response
- func Return(codeType CodeType, success bool) *Response
- func ReturnFail(codeType CodeType, err string) *Response
- func ReturnResultIgnoreCode(result interface{}) *Response
- func ReturnSuccess(result interface{}) *Response
- func Success() *Response
Constants ¶
const ( LocalChannel = "local" NSExecBin = "nsexec" ChaosOsBin = "chaos_os" ChaosMiddlewareBin = "chaos_middleware" ChaosCloudBin = "chaos_cloud" Destroy = "destroy" Create = "create" True = "true" False = "false" BinPath = "bin" ExperimentId = "experiment" DefaultCGroupPath = "/sys/fs/cgroup/" Uid = "uid" YamlPathEnv = "YAML_PATH" )
const (
DestroyKey = "suid"
)
const UnknownUid = "unknown"
Variables ¶
var ( IgnoreCode = CodeType{100, "ignore code"} OK = CodeType{200, "success"} ReturnOKDirectly = CodeType{201, "return ok directly"} Forbidden = CodeType{43000, "Forbidden: must be root"} ActionNotSupport = CodeType{44000, "`%s`: action not supported"} ParameterLess = CodeType{45000, "less parameter: `%s`"} ParameterIllegal = CodeType{46000, "illegal `%s` parameter value: `%s`. %v"} ParameterInvalid = CodeType{47000, "invalid `%s` parameter value: `%s`. %v"} ParameterInvalidProName = CodeType{47001, "invalid parameter `%s`, `%s` process not found"} ParameterInvalidProIdNotByName = CodeType{47002, "invalid parameter `process|pid`, the process ids got by %s does not contain the pid %s value"} ParameterInvalidCplusPort = CodeType{47003, "invalid parameter port, `%s` port not found, please execute prepare command firstly"} ParameterInvalidDbQuery = CodeType{47004, "invalid parameter `%s`, db record not found"} ParameterInvalidCplusTarget = CodeType{47005, "invalid parameter target, `%s` target not support"} ParameterInvalidBladePathError = CodeType{47006, "invalid parameter `%s`, deploy chaosblade to `%s` failed, err: %v"} ParameterInvalidNSNotOne = CodeType{47007, "invalid parameter `%s`, only one value can be specified"} ParameterInvalidK8sPodQuery = CodeType{47008, "invalid parameter `%s`, can not find pods"} ParameterInvalidK8sNodeQuery = CodeType{47009, "invalid parameter `%s`, can not find node"} ParameterInvalidDockContainerId = CodeType{47010, "invalid parameter `%s`, can not find container by id"} ParameterInvalidDockContainerName = CodeType{47011, "invalid parameter `%s`, can not find container by name"} ParameterInvalidTooManyProcess = CodeType{47012, "invalid parameter process, too many `%s` processes found"} DeployChaosBladeFailed = CodeType{47013, "deploy chaosblade to `%s` failed, err: %v"} ParameterRequestFailed = CodeType{48000, "get request parameter failed"} CommandIllegal = CodeType{49000, "illegal command, err: %v"} CommandNetworkExist = CodeType{49001, "network tc exec failed! RTNETLINK answers: File exists"} ChaosbladeFileNotFound = CodeType{51000, "`%s`: chaosblade file not found"} CommandTasksetNotFound = CodeType{52000, "`taskset`: command not found"} CommandMountNotFound = CodeType{52001, "`mount`: command not found"} CommandUmountNotFound = CodeType{52002, "`umount`: command not found"} CommandTcNotFound = CodeType{52003, "`tc`: command not found"} CommandIptablesNotFound = CodeType{52004, "`iptables`: command not found"} CommandSedNotFound = CodeType{52005, "`sed`: command not found"} CommandCatNotFound = CodeType{52006, "`cat`: command not found"} CommandSsNotFound = CodeType{52007, "`ss`: command not found"} CommandDdNotFound = CodeType{52008, "`dd`: command not found"} CommandRmNotFound = CodeType{52009, "`rm`: command not found"} CommandTouchNotFound = CodeType{52010, "`touch`: command not found"} CommandMkdirNotFound = CodeType{52011, "`mkdir`: command not found"} CommandEchoNotFound = CodeType{52012, "`echo`: command not found"} CommandKillNotFound = CodeType{52013, "`kill`: command not found"} CommandMvNotFound = CodeType{52014, "`mv`: command not found"} CommandHeadNotFound = CodeType{52015, "`head`: command not found"} CommandGrepNotFound = CodeType{52016, "`grep`: command not found"} CommandAwkNotFound = CodeType{52017, "`awk`: command not found"} CommandTarNotFound = CodeType{52018, "`tar`: command not found"} CommandSystemctlNotFound = CodeType{52019, "`systemctl`: command not found"} CommandNohupNotFound = CodeType{52020, "`nohup`: command not found"} ChaosbladeServerStarted = CodeType{53000, "the chaosblade has been started. If you want to stop it, you can execute blade server stop command"} UnexpectedStatus = CodeType{54000, "unexpected status, expected status: `%s`, but the real status: `%s`, please wait!"} DockerExecNotFound = CodeType{55000, "`%s`: the docker exec not found"} DockerImagePullFailed = CodeType{55001, "pull image failed, err: %v"} CriExecNotFound = CodeType{55002, "`%s`, the cri exc not found"} ImagePullFailed = CodeType{55003, "`%s`, pull image failed, err: %v"} HandlerExecNotFound = CodeType{56000, "`%s`: the handler exec not found"} CplusActionNotSupport = CodeType{56001, "`%s`: cplus action not support"} ContainerInContextNotFound = CodeType{56002, "cannot find container, please confirm if the container exists"} PodNotReady = CodeType{56003, "`%s` pod is not ready"} ResultUnmarshalFailed = CodeType{60000, "`%s`: exec result unmarshal failed, err: %v"} ResultMarshalFailed = CodeType{60001, "`%v`: exec result marshal failed, err: %v"} GenerateUidFailed = CodeType{60002, "generate experiment uid failed, err: %v"} ChaosbladeServiceStoped = CodeType{61000, "chaosblade service has been stopped"} ProcessIdByNameFailed = CodeType{63010, "`%s`: get process id by name failed, err: %v"} ProcessJudgeExistFailed = CodeType{63011, "`%s`: judge the process exist or not, failed, err: %v"} ProcessNotExist = CodeType{63012, "`%s`: the process not exist"} ProcessGetUsernameFailed = CodeType{63014, "`%s`: get username failed by the process id, err: %v"} ChannelNil = CodeType{63020, "chanel is nil"} SandboxGetPortFailed = CodeType{63030, "get sandbox port failed, err: %v"} SandboxCreateTokenFailed = CodeType{63031, "create sandbox token failed, err: %v"} FileCantGetLogFile = CodeType{63040, "can not get log file"} FileNotExist = CodeType{63041, "`%s`: not exist"} FileCantReadOrOpen = CodeType{63042, "`%s`: can not read or open"} BackfileExists = CodeType{63050, "`%s`: backup file exists, may be annother experiment is running"} DbQueryFailed = CodeType{63060, "`%s`: db query failed, err: %v"} K8sExecFailed = CodeType{63061, "`%s`: k8s exec failed, err: %v"} DockerExecFailed = CodeType{63062, "`%s`: docker exec failed, err: %v"} OsCmdExecFailed = CodeType{63063, "`%s`: cmd exec failed, err: %v"} HttpExecFailed = CodeType{63064, "`%s`: http cmd failed, err: %v"} GetIdentifierFailed = CodeType{63065, "get experiment identifier failed, err: %v"} CreateContainerFailed = CodeType{63066, "create container failed, err: %v"} ContainerExecFailed = CodeType{63067, "`%s`: container exec failed, err: %v"} OsExecutorNotFound = CodeType{63070, "`%s`: os executor not found"} ChaosfsClientFailed = CodeType{64000, "init chaosfs client failed in pod %v, err: %v"} ChaosfsInjectFailed = CodeType{64001, "inject io exception in pod %s failed, request %v, err: %v"} ChaosfsRecoverFailed = CodeType{64002, "recover io exception failed in pod %v, err: %v"} SshExecFailed = CodeType{65000, "ssh exec failed, result: %v, err %v"} SshExecNothing = CodeType{65001, "cannot get result from remote host, please execute recovery and try again"} SystemdNotFound = CodeType{66001, "`%s`: systemd not found, err: %v"} DatabaseError = CodeType{67001, "`%s`: failed to execute, err: %v"} DataNotFound = CodeType{67002, "`%s` record not found, if it's k8s experiment, please add --target k8s flag to retry"} )
Functions ¶
func AddExecutorToModelSpec ¶
func AddExecutorToModelSpec(executor Executor, expSpecs ...ExpModelCommandSpec)
AddExecutorToModelSpec
func AddFlagsToModelSpec ¶
func AddFlagsToModelSpec(flagsFunc func() []ExpFlagSpec, expSpecs ...ExpModelCommandSpec)
AddFlagsToModelSpec
Types ¶
type ActionModel ¶
type ActionModel struct { ActionName string `yaml:"action"` ActionAliases []string `yaml:"aliases,flow,omitempty"` ActionShortDesc string `yaml:"shortDesc"` ActionLongDesc string `yaml:"longDesc"` ActionMatchers []ExpFlag `yaml:"matchers,omitempty"` ActionFlags []ExpFlag `yaml:"flags,omitempty"` ActionExample string `yaml:"example"` ActionPrograms []string `yaml:"programs,omitempty"` ActionCategories []string `yaml:"categories,omitempty"` ActionProcessHang bool `yaml:"actionProcessHang"` // contains filtered or unexported fields }
ActionModel for yaml file
func (*ActionModel) Aliases ¶
func (am *ActionModel) Aliases() []string
func (*ActionModel) Categories ¶
func (am *ActionModel) Categories() []string
func (*ActionModel) Example ¶
func (am *ActionModel) Example() string
func (*ActionModel) Executor ¶
func (am *ActionModel) Executor() Executor
func (*ActionModel) Flags ¶
func (am *ActionModel) Flags() []ExpFlagSpec
func (*ActionModel) LongDesc ¶
func (am *ActionModel) LongDesc() string
func (*ActionModel) Matchers ¶
func (am *ActionModel) Matchers() []ExpFlagSpec
func (*ActionModel) Name ¶
func (am *ActionModel) Name() string
func (*ActionModel) ProcessHang ¶
func (am *ActionModel) ProcessHang() bool
func (*ActionModel) Programs ¶
func (am *ActionModel) Programs() []string
func (*ActionModel) SetCategories ¶
func (am *ActionModel) SetCategories(categories []string)
func (*ActionModel) SetExample ¶
func (am *ActionModel) SetExample(example string)
func (*ActionModel) SetExecutor ¶
func (am *ActionModel) SetExecutor(executor Executor)
func (*ActionModel) SetLongDesc ¶
func (am *ActionModel) SetLongDesc(longDesc string)
func (*ActionModel) ShortDesc ¶
func (am *ActionModel) ShortDesc() string
type BaseExpActionCommandSpec ¶
type BaseExpActionCommandSpec struct { ActionMatchers []ExpFlagSpec ActionFlags []ExpFlagSpec ActionExecutor Executor ActionLongDesc string ActionExample string ActionPrograms []string ActionCategories []string ActionProcessHang bool }
BaseExpActionCommandSpec defines the common struct of the implementation of ExpActionCommandSpec
func (*BaseExpActionCommandSpec) Categories ¶
func (b *BaseExpActionCommandSpec) Categories() []string
func (*BaseExpActionCommandSpec) Example ¶
func (b *BaseExpActionCommandSpec) Example() string
func (*BaseExpActionCommandSpec) Executor ¶
func (b *BaseExpActionCommandSpec) Executor() Executor
func (*BaseExpActionCommandSpec) Flags ¶
func (b *BaseExpActionCommandSpec) Flags() []ExpFlagSpec
func (*BaseExpActionCommandSpec) Matchers ¶
func (b *BaseExpActionCommandSpec) Matchers() []ExpFlagSpec
func (*BaseExpActionCommandSpec) ProcessHang ¶
func (b *BaseExpActionCommandSpec) ProcessHang() bool
func (*BaseExpActionCommandSpec) Programs ¶
func (b *BaseExpActionCommandSpec) Programs() []string
func (*BaseExpActionCommandSpec) SetCategories ¶
func (b *BaseExpActionCommandSpec) SetCategories(categories []string)
func (*BaseExpActionCommandSpec) SetExample ¶
func (b *BaseExpActionCommandSpec) SetExample(example string)
func (*BaseExpActionCommandSpec) SetExecutor ¶
func (b *BaseExpActionCommandSpec) SetExecutor(executor Executor)
func (*BaseExpActionCommandSpec) SetLongDesc ¶
func (b *BaseExpActionCommandSpec) SetLongDesc(longDesc string)
type BaseExpModelCommandSpec ¶
type BaseExpModelCommandSpec struct { ExpScope string ExpActions []ExpActionCommandSpec ExpFlags []ExpFlagSpec }
BaseExpModelCommandSpec defines the common struct of the implementation of ExpModelCommandSpec
func (*BaseExpModelCommandSpec) Actions ¶
func (b *BaseExpModelCommandSpec) Actions() []ExpActionCommandSpec
func (*BaseExpModelCommandSpec) Flags ¶
func (b *BaseExpModelCommandSpec) Flags() []ExpFlagSpec
func (*BaseExpModelCommandSpec) Scope ¶
func (b *BaseExpModelCommandSpec) Scope() string
Scope default value is "" means localhost
func (*BaseExpModelCommandSpec) SetFlags ¶
func (b *BaseExpModelCommandSpec) SetFlags(flags []ExpFlagSpec)
type Channel ¶
type Channel interface { // channel name unique Name() string // Run script with args and returns response that wraps the result Run(ctx context.Context, script, args string) *Response // GetScriptPath return the script path GetScriptPath() string // GetPidsByProcessCmdName returns the matched process other than the current process by the program command GetPidsByProcessCmdName(processName string, ctx context.Context) ([]string, error) // GetPidsByProcessName returns the matched process other than the current process by the process keyword GetPidsByProcessName(processName string, ctx context.Context) ([]string, error) // GetPsArgs returns the ps command output format GetPsArgs(ctx context.Context) string // isAlpinePlatform returns true if the os version is alpine. // If the /etc/os-release file doesn't exist, the function returns false. IsAlpinePlatform(ctx context.Context) bool // IsAllCommandsAvailable returns nil,true if all commands exist IsAllCommandsAvailable(ctx context.Context, commandNames []string) (*Response, bool) // IsCommandAvailable returns true if the command exists IsCommandAvailable(ctx context.Context, commandName string) bool // ProcessExists returns true if the pid exists, otherwise return false. ProcessExists(pid string) (bool, error) // GetPidUser returns the process user by pid GetPidUser(pid string) (string, error) // GetPidsByLocalPorts returns the process ids using the ports GetPidsByLocalPorts(ctx context.Context, localPorts []string) ([]string, error) // GetPidsByLocalPort returns the process pid corresponding to the port GetPidsByLocalPort(ctx context.Context, localPort string) ([]string, error) }
Channel is an interface for command invocation
type Executor ¶
type Executor interface { // Name is used to identify the ExpExecutor Name() string // Exec is used to execute the experiment Exec(uid string, ctx context.Context, model *ExpModel) *Response // SetChannel SetChannel(channel Channel) }
ExpExecutor defines the ExpExecutor interface
type ExpActionCommandSpec ¶
type ExpActionCommandSpec interface { // Name returns the action name Name() string // Aliases returns command alias names Aliases() []string // ShortDesc returns short description for the action ShortDesc() string // LongDesc returns full description for the action LongDesc() string // SetLongDesc SetLongDesc(longDesc string) // Matchers returns the list of matchers supported by the action Matchers() []ExpFlagSpec // Flags returns the list of flags supported by the action Flags() []ExpFlagSpec //Example returns command example Example() string //Example returns command example SetExample(example string) // ExpExecutor returns the action command ExpExecutor Executor() Executor // SetExecutor SetExecutor(executor Executor) // Programs executed Programs() []string // Scenario categories Categories() []string // SetCategories SetCategories(categories []string) // process is hang up ProcessHang() bool }
ExpActionCommandSpec defines the action command interface for the experimental plugin
type ExpCommandModel ¶
type ExpCommandModel struct { ExpName string `yaml:"target"` ExpShortDesc string `yaml:"shortDesc"` ExpLongDesc string `yaml:"longDesc"` ExpActions []ActionModel `yaml:"actions"` ExpExecutor Executor `yaml:"-"` ExpFlags []ExpFlag `yaml:"flags,omitempty"` ExpScope string `yaml:"scope"` ExpPrepareModel ExpPrepareModel `yaml:"prepare,omitempty"` ExpSubTargets []string `yaml:"subTargets,flow,omitempty"` }
func (*ExpCommandModel) Actions ¶
func (ecm *ExpCommandModel) Actions() []ExpActionCommandSpec
func (*ExpCommandModel) Flags ¶
func (ecm *ExpCommandModel) Flags() []ExpFlagSpec
func (*ExpCommandModel) LongDesc ¶
func (ecm *ExpCommandModel) LongDesc() string
func (*ExpCommandModel) Name ¶
func (ecm *ExpCommandModel) Name() string
func (*ExpCommandModel) Scope ¶
func (ecm *ExpCommandModel) Scope() string
func (*ExpCommandModel) SetFlags ¶
func (ecm *ExpCommandModel) SetFlags(flags []ExpFlagSpec)
func (*ExpCommandModel) ShortDesc ¶
func (ecm *ExpCommandModel) ShortDesc() string
type ExpFlag ¶
type ExpFlag struct { // Name returns the flag FlagName Name string `yaml:"name"` // Desc returns the flag description Desc string `yaml:"desc"` // NoArgs means no arguments NoArgs bool `yaml:"noArgs"` // Required means necessary or not Required bool `yaml:"required"` // RequiredWhenDestroyed is true if the flag is necessary when destroying experiment RequiredWhenDestroyed bool `yaml:"requiredWhenDestroyed"` // default value Default string `yaml:"default,omitempty"` }
ExpFlag defines the action flag
func (*ExpFlag) FlagDefault ¶
func (*ExpFlag) FlagNoArgs ¶
func (*ExpFlag) FlagRequired ¶
func (*ExpFlag) FlagRequiredWhenDestroyed ¶
type ExpFlagSpec ¶
type ExpFlagSpec interface { // FlagName returns the flag FlagName FlagName() string // FlagDesc returns the flag description FlagDesc() string // FlagNoArgs returns true if the flag is bool type FlagNoArgs() bool // FlagRequired returns true if the flag is necessary when creating experiment FlagRequired() bool // FlagRequiredWhenDestroyed returns true if the flag is necessary when destroying experiment FlagRequiredWhenDestroyed() bool // FlagDefault return the flag Defaule FlagDefault() string }
type ExpModel ¶
type ExpModel struct { // Target is experiment target Target string `json:"target,omitempty"` // Scope is the experiment scope Scope string `json:"scope,omitempty"` // ActionName is the experiment action FlagName, for example delay ActionName string `json:"action,omitempty"` // ActionFlags is the experiment action flags, for example time and offset ActionFlags map[string]string `json:"flags,omitempty"` // Programs ActionPrograms []string `json:"programs,omitempty"` // Categories ActionCategories []string `json:"categories,omitempty"` ActionProcessHang bool `yaml:"actionProcessHang"` }
ExpModel is the experiment data object
func ConvertCommandsToExpModel ¶
ConvertCommandsToExpModel returns the ExpModel by action, target and flags
type ExpModelCommandSpec ¶
type ExpModelCommandSpec interface { // Name returns the target name Name() string // Scope returns the experiment scope Scope() string // ShortDesc returns short description for the command ShortDesc() string // LongDesc returns full description for the command LongDesc() string // Actions returns the list of actions supported by the command Actions() []ExpActionCommandSpec // Flags returns the command flags Flags() []ExpFlagSpec // SetFlags SetFlags(flags []ExpFlagSpec) }
ExpModelCommandSpec defines the command interface for the experimental plugin
type ExpPrepareModel ¶
type Models ¶
type Models struct { Version string `yaml:"version"` Kind string `yaml:"kind"` Models []ExpCommandModel `yaml:"items"` }
type Response ¶
type Response struct { Code int32 `json:"code"` Success bool `json:"success"` Err string `json:"error,omitempty"` Result interface{} `json:"result,omitempty"` }
func ResponseFail ¶
func ResponseFailWithFlags ¶
func ResponseFailWithResult ¶
func ReturnFail ¶
func ReturnResultIgnoreCode ¶
func ReturnResultIgnoreCode(result interface{}) *Response
func ReturnSuccess ¶
func ReturnSuccess(result interface{}) *Response