Documentation
¶
Index ¶
- Variables
- func Connections(connections int) func(*Attacker)
- func KeepAlive(keepalive bool) func(*Attacker)
- func LocalAddr(addr net.IPAddr) func(*Attacker)
- func MaxConnections(maxConnections int) func(*Attacker)
- func MaxWorkers(w uint64) func(*Attacker)
- func Workers(w uint64) func(*Attacker)
- type Attacker
- type Config
- type ConstantPacer
- type Decoder
- type DecoderFactory
- type Encoder
- type Pacer
- type Plan
- type Rate
- type RequestConfig
- type Result
- type Results
- type Target
- type TargetSetup
- type Targeter
- type TestConfig
Constants ¶
This section is empty.
Variables ¶
var ( DefaultLocalAddr = net.IPAddr{IP: net.IPv4zero} DefaultConnections = 10000 DefaultMaxConnections = 0 DefaultWorkers uint64 = 10 DefaultMaxWorkers uint64 = math.MaxUint64 DefaultTimeout = 30 * time.Second )
var ( // ErrNoTargets is returned when not enough Targets are available. ErrNoTargets = errors.New("no targets to attack") // ErrNilTarget is returned when the passed Target pointer is nil. ErrNilTarget = errors.New("nil target") // ErrNoMethod is returned by JSONTargeter when a parsed Target has // no method. ErrNoMethod = errors.New("target: required method is missing") // ErrNoURL is returned by JSONTargeter when a parsed Target has no // URL. ErrNoURL = errors.New("target: required url is missing") )
Functions ¶
func Connections ¶
func MaxConnections ¶
func MaxWorkers ¶
Types ¶
type Attacker ¶
type Attacker struct {
// contains filtered or unexported fields
}
func NewAttacker ¶
type Config ¶
type Config struct {
ApiVersion string `json:"apiVersion" yaml:"apiVersion"`
Configuration TestConfig `json:"config" yaml:"config"`
TargetPlan []Plan `json:"targetPlan" yaml:"targetPlan"`
}
type ConstantPacer ¶
func (ConstantPacer) String ¶
func (c ConstantPacer) String() string
String returns a pretty-printed description of the ConstantPacer's behaviour:
ConstantPacer{Freq: 1, Per: time.Second} => Constant{1 hits/1s}
type Decoder ¶
A Decoder decodes a Result and returns an error in case of failure.
func DecoderFor ¶
DecoderFor automatically detects the encoding of the first few bytes in the given io.Reader and then returns the corresponding Decoder or nil in case of failing to detect a supported encoding.
func NewCSVDecoder ¶
NewCSVDecoder returns a Decoder that decodes CSV encoded Results.
func NewDecoder ¶
NewDecoder returns a new gob Decoder for the given io.Reader.
func NewRoundRobinDecoder ¶
NewRoundRobinDecoder returns a new Decoder that round robins across the given Decoders on every invocation or decoding error.
type DecoderFactory ¶
A DecoderFactory constructs a new Decoder from a given io.Reader.
type Encoder ¶
An Encoder encodes a Result and returns an error in case of failure.
func NewCSVEncoder ¶
NewCSVEncoder returns an Encoder that dumps the given *Result as a CSV record. The columns are: UNIX timestamp in ns since epoch, HTTP status code, request latency in ns, bytes out, bytes in, response body, and lastly the error.
func NewEncoder ¶
NewEncoder returns a new Result encoder closure for the given io.Writer
type Pacer ¶
type Pacer interface {
// Pace returns the duration an Attacker should wait until
// hitting the next Target, given an already elapsed duration and
// completed hits. If the second return value is true, an attacker
// should stop sending hits.
Pace(elapsed time.Duration, hits uint64) (wait time.Duration, stop bool)
// Rate returns a Pacer's instantaneous hit rate (per seconds)
// at the given elapsed duration of an attack.
Rate(elapsed time.Duration) float64
}
type Plan ¶
type Plan struct {
Name string `yaml:"name"`
Targets []TargetSetup `yaml:"targets"`
}
type Rate ¶
type Rate = ConstantPacer
Rate is a type alias for ConstantPacer for backwards-compatibility.
type RequestConfig ¶
type Result ¶
type Result struct {
Attack string `json:"attack"`
Seq uint64 `json:"seq"`
Code uint16 `json:"code"`
Timestamp time.Time `json:"timestamp"`
Latency time.Duration `json:"latency"`
BytesOut uint64 `json:"bytes_out"`
BytesIn uint64 `json:"bytes_in"`
Error string `json:"error"`
Body []byte `json:"body"`
Method string `json:"method"`
URL string `json:"url"`
Headers http.Header `json:"headers"`
}
Result contains the results of a single Target hit.
type Results ¶
type Results []Result
Results is a slice of Result type elements.
func (*Results) Add ¶
Add implements the Add method of the Report interface by appending the given Result to the slice.
type Target ¶
type Target struct {
Method string `json:"method"`
URL string `json:"url"`
Body []byte `json:"body,omitempty"`
Header http.Header `json:"header,omitempty"`
Next *Target `json:"next,omitempty"`
}
func ProcessReader ¶
type TargetSetup ¶
type TargetSetup struct {
PreRun interface{} `yaml:"preRun"`
Run RequestConfig `yaml:"run"`
PostRun interface{} `yaml:"postRun"`
}
type Targeter ¶
A Targeter decodes a Target or returns an error in case of failure. Implementations must be safe for concurrent use.
func NewStaticTargeter ¶
type TestConfig ¶
type TestConfig struct {
Workers int `json:"workers" yaml:"workers"`
}