Documentation ¶
Index ¶
- Constants
- Variables
- func BuildStage() *stage
- func CheckHTTPStatusCode(res *http.Response, body []byte) error
- func NewPlan(name string) *plan
- func NewTask() *task
- type AttackStrategy
- type AttackStrategyCommander
- type Attacker
- type ExitConditions
- type FixedConcurrentUsers
- type GaussianRandomTimer
- type HTTPAttacker
- type HTTPAttackerOption
- func WithCheckFuncs(checks ...HTTPCheckFunc) HTTPAttackerOption
- func WithClient(client *http.Client) HTTPAttackerOption
- func WithDisableKeepAlives(disbale bool) HTTPAttackerOption
- func WithPrepareFunc(prepare HTTPPrepareFunc) HTTPAttackerOption
- func WithProxy(proxy func(*http.Request) (*url.URL, error)) HTTPAttackerOption
- func WithTimeout(t time.Duration) HTTPAttackerOption
- type HTTPCheckFunc
- type HTTPPrepareFunc
- type LocalRunner
- type MasterRunner
- type NonstopTimer
- type Plan
- type PlanStatus
- type RampUpStep
- type ReportHandleFunc
- type ResultHandleFunc
- type RunnerConfig
- type SlaveAgent
- type SlaveRunner
- type Stage
- type Task
- type Timer
- type UniformRandomTimer
- type UniversalExitConditions
- type V1StageConfig
Constants ¶
View Source
const PlanKey = "ultron-plan"
Variables ¶
View Source
var (
ErrPlanClosed = errors.New("plan was finished or interrupted")
)
View Source
var ( // Logger 全局日志 Logger *zap.Logger )
Functions ¶
func BuildStage ¶
func BuildStage() *stage
func CheckHTTPStatusCode ¶
CheckHTTPStatusCode 检查状态码是否>=400, 如果是则视为请求失败
Types ¶
type AttackStrategy ¶
type AttackStrategy interface { Spawn() []*RampUpStep Switch(next AttackStrategy) []*RampUpStep Split(int) []AttackStrategy }
AttackStrategy 压测策略描述
type AttackStrategyCommander ¶
type AttackStrategyCommander interface { Open(context.Context, Task) <-chan statistics.AttackResult Command(AttackStrategy, Timer) Close() }
AttackStrategyCommander 压测策略
type ExitConditions ¶
type ExitConditions interface { NeverStop() bool Check(ExitConditions) bool }
ExitCondition 阶段退出条件
type FixedConcurrentUsers ¶
type FixedConcurrentUsers struct { ConcurrentUsers int `json:"conncurrent_users"` // 并发用户数 RampUpPeriod int `json:"ramp_up_period,omitempty"` // 增压周期时长 }
FixedConcurrentUsers 固定goroutine/线程/用户的并发策略
func (*FixedConcurrentUsers) Name ¶
func (fx *FixedConcurrentUsers) Name() string
func (*FixedConcurrentUsers) Spawn ¶
func (fc *FixedConcurrentUsers) Spawn() []*RampUpStep
Spawn 增压、降压
func (*FixedConcurrentUsers) Split ¶
func (fx *FixedConcurrentUsers) Split(n int) []AttackStrategy
Split 切分配置
func (*FixedConcurrentUsers) Switch ¶
func (fc *FixedConcurrentUsers) Switch(next AttackStrategy) []*RampUpStep
Switch 转入下一个阶段
type GaussianRandomTimer ¶
type GaussianRandomTimer struct { StdDev float64 `json:"std_dev"` // 标准差 DesiredMean float64 `json:"desired_mean"` // 期望均值 }
GaussianRandomTimer 高斯分布
func (*GaussianRandomTimer) Name ¶
func (grt *GaussianRandomTimer) Name() string
func (*GaussianRandomTimer) Sleep ¶
func (grt *GaussianRandomTimer) Sleep()
type HTTPAttacker ¶
type HTTPAttacker struct {
// contains filtered or unexported fields
}
HTTPAttacker 内置net/http库对Attacker的实现
func NewHTTPAttacker ¶
func NewHTTPAttacker(name string) *HTTPAttacker
func (*HTTPAttacker) Apply ¶
func (ha *HTTPAttacker) Apply(opts ...HTTPAttackerOption)
func (*HTTPAttacker) Name ¶
func (ha *HTTPAttacker) Name() string
type HTTPAttackerOption ¶
type HTTPAttackerOption func(*HTTPAttacker)
HTTPAttackerOption HTTPAttacker配置项
func WithCheckFuncs ¶
func WithCheckFuncs(checks ...HTTPCheckFunc) HTTPAttackerOption
func WithClient ¶
func WithClient(client *http.Client) HTTPAttackerOption
func WithDisableKeepAlives ¶
func WithDisableKeepAlives(disbale bool) HTTPAttackerOption
func WithPrepareFunc ¶
func WithPrepareFunc(prepare HTTPPrepareFunc) HTTPAttackerOption
func WithTimeout ¶
func WithTimeout(t time.Duration) HTTPAttackerOption
type HTTPCheckFunc ¶
HTTPCheckFunc http.Response校验函数,可由调用方自定义,如果返回error,则视为请求失败
type HTTPPrepareFunc ¶
HTTPPrepareFunc 构造http.Request函数,需要调用方定义,由HTTPAttacker来发送
type LocalRunner ¶
type LocalRunner interface { Launch() error Assign(Task) SubscribeReport(...ReportHandleFunc) SubscribeResult(...ResultHandleFunc) StartPlan(Plan) error StopPlan() }
func NewLocalRunner ¶
func NewLocalRunner() LocalRunner
type MasterRunner ¶
type MasterRunner interface { Launch(...grpc.ServerOption) error // 服务启动 StartPlan(Plan) error // 开始执行某个测试计划 StopPlan() // 停止当前计划 SubscribeReport(...ReportHandleFunc) // 订阅聚合报告 }
func NewMasterRunner ¶
func NewMasterRunner() MasterRunner
type NonstopTimer ¶
type NonstopTimer struct{}
NonstopTimer 不中断
func (NonstopTimer) Name ¶
func (ns NonstopTimer) Name() string
func (NonstopTimer) Sleep ¶
func (ns NonstopTimer) Sleep()
type Plan ¶
type Plan interface { Name() string AddStages(...Stage) Stages() []Stage Current() (int, Stage) Status() PlanStatus }
Plan 定义测试计划接口
type PlanStatus ¶
type PlanStatus int
PlanStatus 定义测试计划状态
const ( // StatusReady 测试计划尚未执行 StatusReady PlanStatus = iota // StatusRunning 测试计划执行中 StatusRunning // StatusFinished 测试执行执行完成 StatusFinished // StatusInterrupted 测试计划执行被中断 StatusInterrupted )
type RampUpStep ¶
RampUpStep 增/降压描述
type ReportHandleFunc ¶
type ReportHandleFunc func(context.Context, statistics.SummaryReport)
ReportHandleFunc 聚合报告处理函数
type ResultHandleFunc ¶
type ResultHandleFunc func(context.Context, statistics.AttackResult)
ResultHandleFunc 请求结果处理函数
type RunnerConfig ¶
type SlaveAgent ¶
SlaveAgent 定义master侧的slave对象
type SlaveRunner ¶
type SlaveRunner interface { Connect(string, ...grpc.DialOption) error // 连接master SubscribeResult(...ResultHandleFunc) // 订阅Attacker的执行结果 Assign(Task) // 指派压测任务 }
func NewSlaveRunner ¶
func NewSlaveRunner() SlaveRunner
type Stage ¶
type Stage interface { GetTimer() Timer GetExitConditions() ExitConditions GetStrategy() AttackStrategy }
Stage 描述一个压测阶段,需要包含并发策略、延时器、退出条件
type UniformRandomTimer ¶
type UniformRandomTimer struct { MinWait time.Duration `json:"min_wait,omitempty"` MaxWait time.Duration `json:"max_wait,omitempty"` }
UniformRandomTimer 平均随机数
func (*UniformRandomTimer) Name ¶
func (urt *UniformRandomTimer) Name() string
func (*UniformRandomTimer) Sleep ¶
func (urt *UniformRandomTimer) Sleep()
type UniversalExitConditions ¶
type UniversalExitConditions struct { Requests uint64 `json:"requests,omitempty"` // 请求总数,不严格控制 Duration time.Duration `json:"duration,omitempty"` // 持续时长,不严格控制 }
exitConditions 通用的退出条件
func (*UniversalExitConditions) Check ¶
func (sec *UniversalExitConditions) Check(actual ExitConditions) bool
func (*UniversalExitConditions) NeverStop ¶
func (sec *UniversalExitConditions) NeverStop() bool
type V1StageConfig ¶
type V1StageConfig struct { Requests uint64 `json:"requests,omitempty"` Duration time.Duration `json:"duration,omitempty"` ConcurrentUsers int `json:"concurrent_users"` RampUpPeriod int `json:"ramp_up_period"` // 单位秒 MinWait time.Duration `json:"min_wait,omitempty"` MaxWait time.Duration `json:"max_wait,omitempty"` }
func (*V1StageConfig) GetExitConditions ¶
func (v1 *V1StageConfig) GetExitConditions() ExitConditions
func (*V1StageConfig) GetStrategy ¶
func (v1 *V1StageConfig) GetStrategy() AttackStrategy
func (*V1StageConfig) GetTimer ¶
func (v1 *V1StageConfig) GetTimer() Timer
Source Files ¶
Click to show internal directories.
Click to hide internal directories.