Documentation ¶
Overview ¶
Package ultron is a generated protocol buffer package.
It is generated from these files:
grpc.proto
It has these top-level messages:
Result AttackerError ClientInfo Ack Message
Index ¶
- Constants
- Variables
- func CheckFastHTTPStatusCode(resp *fasthttp.Response) error
- func CheckHTTPStatusCode(resp *http.Response, body []byte) error
- func RegisterUltronServer(s *grpc.Server, srv UltronServer)
- func ShowLogo()
- type Ack
- type Attacker
- type AttackerError
- type AttackerReport
- type ClientInfo
- type CommonFastHTTPClient
- type CommonHTTPClient
- type FastHTTPAttacker
- type FastHTTPPrepareFunc
- type FastHTTPResponseCheck
- type HTTPAttacker
- type HTTPPrepareFunc
- type HTTPResponseCheck
- type Message
- type Message_Type
- type Report
- type ReportHandleFunc
- type Result
- type ResultHandleFunc
- type Runner
- type RunnerConfig
- type Stage
- type StageStatus
- type Status
- type Task
- type UltronClient
- type UltronServer
- type Ultron_SendClient
- type Ultron_SendServer
- type Ultron_SubscribeClient
- type Ultron_SubscribeServer
Constants ¶
const ( // DefaultHatchRate 默认的增压/降压幅度 DefaultHatchRate = 10 // DefaultDuration 默认的压测持续时间,ZeroDuration表示不控制 DefaultDuration = ZeroDuration // DefaultConcurrence 默认并发数 DefaultConcurrence = 100 // DefaultRequests 默认请求总次数,0表示不限制 DefaultRequests = 0 // DefaultMinWait 默认最小等待时间 DefaultMinWait = 3 * time.Second // DefaultMaxWait 默认最大等待时间 DefaultMaxWait = 5 * time.Second )
const ( // ZeroDuration 0,用于一些特殊判断 ZeroDuration = time.Duration(0) // StatsReportInterval 统计报表输出间隔 StatsReportInterval = 5 * time.Second )
Variables ¶
var ( // DefaultHTTPClient 默认http.Client // http://tleyden.github.io/blog/2016/11/21/tuning-the-go-http-client-library-for-load-testing/ DefaultHTTPClient = &http.Client{ Timeout: 90 * time.Second, Transport: &http.Transport{ Proxy: nil, DialContext: (&net.Dialer{ Timeout: 30 * time.Second, KeepAlive: 30 * time.Second, DualStack: true, }).DialContext, DisableKeepAlives: false, MaxIdleConns: 2000, MaxIdleConnsPerHost: 1000, IdleConnTimeout: 30 * time.Second, TLSHandshakeTimeout: 10 * time.Second, ExpectContinueTimeout: 1 * time.Second, }, } // DefaultFastHTTPClient define the default fasthttp client use in FastHTTPAttacker DefaultFastHTTPClient = &fasthttp.Client{ Name: "ultron", MaxConnsPerHost: 1000, MaxIdleConnDuration: 30 * time.Second, ReadTimeout: 30 * time.Second, WriteTimeout: 30 * time.Second, } )
var ( // LocalEventHook 单机运行时使用的钩子 LocalEventHook *eventHook // SlaveEventHook 分布式执行时,节点钩子 SlaveEventHook *eventHook // MasterEventHook 分布式执行时,主控钩子 MasterEventHook *eventHook // LocalEventHookConcurrency . LocalEventHookConcurrency = 200 // SlaveEventHookConcurrency . SlaveEventHookConcurrency = 200 // MasterEventHookConcurrency 默认不用控制 MasterEventHookConcurrency = 0 )
var ( // J . J = json // Logger 全局日志 Logger *zap.Logger )
var ( // LocalResultPipelineBufferSize . LocalResultPipelineBufferSize = 1000 // SlaveResultPipelineBufferSize . SlaveResultPipelineBufferSize = 1000 // MasterResultPipelineBufferSize . MasterResultPipelineBufferSize = 2000 // LocalReportPipelineBufferSize . LocalReportPipelineBufferSize = 10 // SlaveReportPipelineBufferSize . SlaveReportPipelineBufferSize = 10 // MasterReportPipelineBufferSize . MasterReportPipelineBufferSize = 20 )
var ( // DefaultRunnerConfig 默认执行器配置 DefaultRunnerConfig = &RunnerConfig{ Duration: DefaultDuration, Requests: DefaultRequests, Concurrence: DefaultConcurrence, HatchRate: DefaultHatchRate, MinWait: DefaultMinWait, MaxWait: DefaultMaxWait, } )
var (
// LocalRunner 单机执行入口
LocalRunner *localRunner
)
var Message_Type_name = map[int32]string{
0: "Disconnect",
1: "RefreshConfig",
2: "StartAttack",
3: "StopAttack",
9: "Ping",
}
var Message_Type_value = map[string]int32{
"Disconnect": 0,
"RefreshConfig": 1,
"StartAttack": 2,
"StopAttack": 3,
"Ping": 9,
}
Functions ¶
func CheckFastHTTPStatusCode ¶
CheckFastHTTPStatusCode check if status code >= 400
func CheckHTTPStatusCode ¶
CheckHTTPStatusCode 检查状态码是否>=400, 如果是则视为请求失败
func RegisterUltronServer ¶
func RegisterUltronServer(s *grpc.Server, srv UltronServer)
Types ¶
type Ack ¶
type Ack struct { }
func (*Ack) Descriptor ¶
func (*Ack) ProtoMessage ¶
func (*Ack) ProtoMessage()
type AttackerError ¶
type AttackerError struct { Name string `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"` CausedBy string `protobuf:"bytes,2,opt,name=causedBy" json:"causedBy,omitempty"` }
func (*AttackerError) Descriptor ¶
func (*AttackerError) Descriptor() ([]byte, []int)
func (*AttackerError) Error ¶
func (ae *AttackerError) Error() string
func (*AttackerError) GetCausedBy ¶
func (m *AttackerError) GetCausedBy() string
func (*AttackerError) GetName ¶
func (m *AttackerError) GetName() string
func (*AttackerError) ProtoMessage ¶
func (*AttackerError) ProtoMessage()
func (*AttackerError) Reset ¶
func (m *AttackerError) Reset()
func (*AttackerError) String ¶
func (m *AttackerError) String() string
type AttackerReport ¶
type AttackerReport struct { Name string `json:"name"` Requests int64 `json:"requests"` Failures int64 `json:"failures"` Min int64 `json:"min"` Max int64 `json:"max"` Median int64 `json:"median"` Average int64 `json:"average"` QPS int64 `json:"qps"` Distributions map[string]int64 `json:"distributions"` FailRatio string `json:"fail_ratio"` FailureDetails map[string]int64 `json:"failure_details"` FullHistory bool `json:"full_history"` }
AttackerReport Attacker级别的报告
type ClientInfo ¶
type ClientInfo struct {
Id string `protobuf:"bytes,1,opt,name=id" json:"id,omitempty"`
}
func (*ClientInfo) Descriptor ¶
func (*ClientInfo) Descriptor() ([]byte, []int)
func (*ClientInfo) GetId ¶
func (m *ClientInfo) GetId() string
func (*ClientInfo) ProtoMessage ¶
func (*ClientInfo) ProtoMessage()
func (*ClientInfo) Reset ¶
func (m *ClientInfo) Reset()
func (*ClientInfo) String ¶
func (m *ClientInfo) String() string
type CommonFastHTTPClient ¶ added in v1.5.0
type CommonHTTPClient ¶ added in v1.5.2
type FastHTTPAttacker ¶
type FastHTTPAttacker struct { Client CommonFastHTTPClient Prepare FastHTTPPrepareFunc CheckChain []FastHTTPResponseCheck // contains filtered or unexported fields }
FastHTTPAttacker a http attacker base on fasthttp: https://github.com/valyala/fasthttp
func NewFastHTTPAttacker ¶
func NewFastHTTPAttacker(n string, p FastHTTPPrepareFunc, check ...FastHTTPResponseCheck) *FastHTTPAttacker
NewFastHTTPAttacker return a new instance of FastHTTPAttacker
func (*FastHTTPAttacker) Fire ¶
func (fa *FastHTTPAttacker) Fire() error
Fire send request and check response
func (*FastHTTPAttacker) Name ¶
func (fa *FastHTTPAttacker) Name() string
Name return attacker's name
type FastHTTPPrepareFunc ¶
FastHTTPPrepareFunc 构造fasthttp.Request请求参数
type FastHTTPResponseCheck ¶
FastHTTPResponseCheck check fasthttp.Response
type HTTPAttacker ¶
type HTTPAttacker struct { Client CommonHTTPClient Prepare HTTPPrepareFunc CheckChain []HTTPResponseCheck // contains filtered or unexported fields }
HTTPAttacker http协议的Attacker实现
func NewHTTPAttacker ¶
func NewHTTPAttacker(n string, p HTTPPrepareFunc, check ...HTTPResponseCheck) *HTTPAttacker
NewHTTPAttacker 创建一个新的HTTPAttacker对象
type HTTPPrepareFunc ¶
HTTPPrepareFunc 构造http.Request函数,需要调用方定义,由HTTPAttacker来发送
type HTTPResponseCheck ¶
HTTPResponseCheck http.Response校验函数,可由调用方自定义,如果返回error,则视为请求失败
type Message ¶
type Message struct { Type Message_Type `protobuf:"varint,1,opt,name=type,enum=ultron.Message_Type" json:"type,omitempty"` Data []byte `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` }
func (*Message) Descriptor ¶
func (*Message) GetType ¶
func (m *Message) GetType() Message_Type
func (*Message) ProtoMessage ¶
func (*Message) ProtoMessage()
type Message_Type ¶
type Message_Type int32
const ( Message_Disconnect Message_Type = 0 Message_RefreshConfig Message_Type = 1 Message_StartAttack Message_Type = 2 Message_StopAttack Message_Type = 3 Message_Ping Message_Type = 9 )
func (Message_Type) EnumDescriptor ¶
func (Message_Type) EnumDescriptor() ([]byte, []int)
func (Message_Type) String ¶
func (x Message_Type) String() string
type Result ¶
type Result struct { Name string `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"` Duration int64 `protobuf:"varint,2,opt,name=duration" json:"duration,omitempty"` Error *AttackerError `protobuf:"bytes,3,opt,name=error" json:"error,omitempty"` }
func (*Result) Descriptor ¶
func (*Result) GetDuration ¶
func (*Result) GetError ¶
func (m *Result) GetError() *AttackerError
func (*Result) ProtoMessage ¶
func (*Result) ProtoMessage()
type Runner ¶
type Runner interface { WithConfig(*RunnerConfig) WithTask(*Task) GetConfig() *RunnerConfig GetStatus() Status Start() Done() }
Runner 定义执行器接口
type RunnerConfig ¶
type RunnerConfig struct { Duration time.Duration `json:"duration,omitempty"` //v2废弃,但兼容V1 Requests uint64 `json:"requests,omitempty"` //v2废弃,但兼容v1 Concurrence int `json:"concurrence,omitempty"` //v2废弃,但兼容V1 HatchRate int `json:"hatch_rate,omitempty"` //v2废弃,但兼容V1 MinWait time.Duration `json:"min_wait,omitempty"` MaxWait time.Duration `json:"max_wait,omitempty"` Stages []*Stage `json:"stages,omitempty"` // contains filtered or unexported fields }
RunnerConfig runner配置参数
func (*RunnerConfig) AppendStage ¶ added in v1.5.0
func (rc *RunnerConfig) AppendStage(sc *Stage) *RunnerConfig
AppendStage 添加下一个阶段配置
func (*RunnerConfig) AppendStages ¶ added in v1.5.0
func (rc *RunnerConfig) AppendStages(sc ...*Stage) *RunnerConfig
AppendStages 批量添加StageConfig
func (*RunnerConfig) CurrentStage ¶ added in v1.5.0
func (rc *RunnerConfig) CurrentStage() (int, *Stage)
CurrentStage 获取当前Stage
type Stage ¶ added in v1.5.0
type Stage struct { Duration time.Duration `json:"duration,omitempty"` // 阶段期望持续时间,不严格控制 Requests uint64 `json:"requests,omitempty"` // 阶段期望请求总数,不严格控制 Concurrence int `json:"concurrence"` // 阶段目标并发数 HatchRate int `json:"hatch_rate,omitempty"` // 阶段增压/降压频率,为0不表示不控制,对于降压阶段,无需使用负数来表示降压频率 // contains filtered or unexported fields }
Stage 压测阶段配置参数
type StageStatus ¶ added in v1.5.0
type StageStatus = uint32
StageStatus Stage状态
const ( // StageReady stage初始化已完成,尚未开始 StageReady StageStatus = iota // StageExpired stage已经退出 StageExpired )
type Task ¶
type Task struct {
// contains filtered or unexported fields
}
Task Attacker集合
type UltronClient ¶
type UltronClient interface { Send(ctx context.Context, opts ...grpc.CallOption) (Ultron_SendClient, error) Subscribe(ctx context.Context, in *ClientInfo, opts ...grpc.CallOption) (Ultron_SubscribeClient, error) }
func NewUltronClient ¶
func NewUltronClient(cc *grpc.ClientConn) UltronClient
type UltronServer ¶
type UltronServer interface { Send(Ultron_SendServer) error Subscribe(*ClientInfo, Ultron_SubscribeServer) error }
type Ultron_SendClient ¶
type Ultron_SendServer ¶
type Ultron_SubscribeClient ¶
type Ultron_SubscribeClient interface { Recv() (*Message, error) grpc.ClientStream }
type Ultron_SubscribeServer ¶
type Ultron_SubscribeServer interface { Send(*Message) error grpc.ServerStream }