gogeta

package
v0.0.0-...-09b4a88 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 7, 2024 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultLocalAddr             = net.IPAddr{IP: net.IPv4zero}
	DefaultConnections           = 10000
	DefaultMaxConnections        = 0
	DefaultWorkers        uint64 = 10
	DefaultMaxWorkers     uint64 = math.MaxUint64
	DefaultTimeout               = 30 * time.Second
)
View Source
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 Connections(connections int) func(*Attacker)

func KeepAlive

func KeepAlive(keepalive bool) func(*Attacker)

func LocalAddr

func LocalAddr(addr net.IPAddr) func(*Attacker)

func MaxConnections

func MaxConnections(maxConnections int) func(*Attacker)

func MaxWorkers

func MaxWorkers(w uint64) func(*Attacker)

func Workers

func Workers(w uint64) func(*Attacker)

Types

type Attacker

type Attacker struct {
	// contains filtered or unexported fields
}

func NewAttacker

func NewAttacker(opts ...func(a *Attacker)) *Attacker

func (*Attacker) Attack

func (a *Attacker) Attack(tr Targeter, p Pacer, du time.Duration, name string) <-chan *Result

func (*Attacker) Stop

func (a *Attacker) Stop() bool

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

type ConstantPacer struct {
	Freq int
	Per  time.Duration
}

func (ConstantPacer) Pace

func (c ConstantPacer) Pace(elapsed time.Duration, hits uint64) (wait time.Duration, stop bool)

func (ConstantPacer) Rate

func (c ConstantPacer) Rate(elapsed time.Duration) float64

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

type Decoder func(*Result) error

A Decoder decodes a Result and returns an error in case of failure.

func DecoderFor

func DecoderFor(r io.Reader) Decoder

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

func NewCSVDecoder(r io.Reader) Decoder

NewCSVDecoder returns a Decoder that decodes CSV encoded Results.

func NewDecoder

func NewDecoder(rd io.Reader) Decoder

NewDecoder returns a new gob Decoder for the given io.Reader.

func NewRoundRobinDecoder

func NewRoundRobinDecoder(dec ...Decoder) Decoder

NewRoundRobinDecoder returns a new Decoder that round robins across the given Decoders on every invocation or decoding error.

func (Decoder) Decode

func (dec Decoder) Decode(r *Result) error

Decode is an an adapter method calling the Decoder function itself with the given parameters.

type DecoderFactory

type DecoderFactory func(io.Reader) Decoder

A DecoderFactory constructs a new Decoder from a given io.Reader.

type Encoder

type Encoder func(*Result) error

An Encoder encodes a Result and returns an error in case of failure.

func NewCSVEncoder

func NewCSVEncoder(w io.Writer) Encoder

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

func NewEncoder(r io.Writer) Encoder

NewEncoder returns a new Result encoder closure for the given io.Writer

func (Encoder) Encode

func (enc Encoder) Encode(r *Result) error

Encode is an an adapter method calling the Encoder function itself with the given parameters.

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 RequestConfig struct {
	Method  string                 `yaml:"method"`
	Url     string                 `yaml:"url"`
	Headers map[string]string      `yaml:"headers"`
	Body    map[string]interface{} `yaml:"body"`
	Params  []string               `yaml:"params"`
}

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.

func (*Result) End

func (r *Result) End() time.Time

End returns the time at which a Result ended.

func (Result) Equal

func (r Result) Equal(other Result) bool

Equal returns true if the given Result is equal to the receiver.

type Results

type Results []Result

Results is a slice of Result type elements.

func (*Results) Add

func (rs *Results) Add(r *Result)

Add implements the Add method of the Report interface by appending the given Result to the slice.

func (*Results) Close

func (rs *Results) Close()

Close implements the Close method of the Report interface by sorting the Results.

func (Results) Len

func (rs Results) Len() int

The following methods implement sort.Interface

func (Results) Less

func (rs Results) Less(i, j int) bool

func (Results) Swap

func (rs Results) Swap(i, j int)

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

func ProcessReader(reader io.Reader) []Target

func (*Target) Equal

func (t *Target) Equal(other *Target) bool

Equal returns true if the target is equal to the other given target.

func (*Target) Request

func (t *Target) Request(cache map[string]string) (*http.Request, error)

Request creates an *http.Request out of Target and returns it along with an error in case of failure.

type TargetSetup

type TargetSetup struct {
	PreRun  interface{}   `yaml:"preRun"`
	Run     RequestConfig `yaml:"run"`
	PostRun interface{}   `yaml:"postRun"`
}

type Targeter

type Targeter func(*Target) error

A Targeter decodes a Target or returns an error in case of failure. Implementations must be safe for concurrent use.

func NewStaticTargeter

func NewStaticTargeter(tgts ...Target) Targeter

type TestConfig

type TestConfig struct {
	Workers int `json:"workers" yaml:"workers"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL