vegeta

package
v0.0.0-...-dca8313 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2017 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultRedirects is the default number of times an Attacker follows
	// redirects.
	DefaultRedirects = 10
	// DefaultTimeout is the default amount of time an Attacker waits for a request
	// before it times out.
	DefaultTimeout = 30 * time.Second
	// DefaultConnections is the default amount of max open idle connections per
	// target host.
	DefaultConnections = 10000
	// DefaultWorkers is the default initial number of workers used to carry an attack.
	DefaultWorkers = 10
	// NoFollow is the value when redirects are not followed but marked successful
	NoFollow = -1
)

Variables

View Source
var (
	// DefaultLocalAddr is the default local IP address an Attacker uses.
	DefaultLocalAddr = net.IPAddr{IP: net.IPv4zero}
	// DefaultTLSConfig is the default tls.Config an Attacker uses.
	DefaultTLSConfig = &tls.Config{InsecureSkipVerify: true}
)
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")
)

Functions

func Connections

func Connections(n int) func(*Attacker)

Connections returns a functional option which sets the number of maximum idle open connections per target host.

func KeepAlive

func KeepAlive(keepalive bool) func(*Attacker)

KeepAlive returns a functional option which toggles KeepAlive connections on the dialer and transport.

func LocalAddr

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

LocalAddr returns a functional option which sets the local address an Attacker will use with its requests.

func Redirects

func Redirects(n int) func(*Attacker)

Redirects returns a functional option which sets the maximum number of redirects an Attacker will follow.

func TLSConfig

func TLSConfig(c *tls.Config) func(*Attacker)

TLSConfig returns a functional option which sets the *tls.Config for a Attacker to use with its requests.

func Timeout

func Timeout(d time.Duration) func(*Attacker)

Timeout returns a functional option which sets the maximum amount of time an Attacker will wait for a request to be responded to.

func Workers

func Workers(n uint64) func(*Attacker)

Workers returns a functional option which sets the initial number of workers an Attacker uses to hit its targets. More workers may be spawned dynamically to sustain the requested rate in the face of slow responses and errors.

Types

type Attacker

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

Attacker is an attack executor which wraps an http.Client

func NewAttacker

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

NewAttacker returns a new Attacker with default options which are overridden by the optionally provided opts.

func (*Attacker) Attack

func (a *Attacker) Attack(tr Targeter, rate uint64, du time.Duration) <-chan *Result

Attack reads its Targets from the passed Targeter and attacks them at the rate specified for duration time. When the duration is zero the attack runs until Stop is called. Results are put into the returned channel as soon as they arrive.

func (*Attacker) Stop

func (a *Attacker) Stop()

Stop stops the current attack.

type Buckets

type Buckets []time.Duration

Buckets represents an Histogram's latency buckets.

func (Buckets) Nth

func (bs Buckets) Nth(i int) (left, right string)

Nth returns the nth bucket represented as a string.

func (*Buckets) UnmarshalText

func (bs *Buckets) UnmarshalText(value []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

type ByteMetrics

type ByteMetrics struct {
	// Total is the total number of flowing bytes in an attack.
	Total uint64 `json:"total"`
	// Mean is the mean number of flowing bytes per hit.
	Mean float64 `json:"mean"`
}

ByteMetrics holds computed byte flow metrics.

type Closer

type Closer interface {
	// Close permantently closes a Report, running any necessary book keeping.
	Close()
}

Closer wraps the optional Report Close method.

type Decoder

type Decoder func(*Result) error

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

func NewDecoder

func NewDecoder(readers ...io.Reader) Decoder

NewDecoder returns a new Result decoder closure for the given io.Readers. It round robins across the io.Readers on every invocation and 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 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 with six columns. The columns are: UNIX timestamp in ns since epoch, HTTP status code, request latency in ns, bytes out, bytes in, 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 NewJSONEncoder

func NewJSONEncoder(w io.Writer) Encoder

NewJSONEncoder returns an Encoder that dumps the given *Results as a JSON object.

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 Histogram

type Histogram struct {
	Buckets Buckets
	Counts  []uint64
	Total   uint64
}

Histogram is a bucketed latency Histogram.

func (*Histogram) Add

func (h *Histogram) Add(r *Result)

Add implements the Add method of the Report interface by finding the right Bucket for the given Result latency and increasing its count by one as well as the total count.

type LatencyMetrics

type LatencyMetrics struct {
	// Total is the total latency sum of all requests in an attack.
	Total time.Duration `json:"total"`
	// Mean is the mean request latency.
	Mean time.Duration `json:"mean"`
	// P50 is the 50th percentile request latency.
	P50 time.Duration `json:"50th"`
	// P95 is the 95th percentile request latency.
	P95 time.Duration `json:"95th"`
	// P99 is the 99th percentile request latency.
	P99 time.Duration `json:"99th"`
	// Max is the maximum observed request latency.
	Max time.Duration `json:"max"`
}

LatencyMetrics holds computed request latency metrics.

type Metrics

type Metrics struct {
	// Latencies holds computed request latency metrics.
	Latencies LatencyMetrics `json:"latencies"`
	// BytesIn holds computed incoming byte metrics.
	BytesIn ByteMetrics `json:"bytes_in"`
	// BytesOut holds computed outgoing byte metrics.
	BytesOut ByteMetrics `json:"bytes_out"`
	// First is the earliest timestamp in a Result set.
	Earliest time.Time `json:"earliest"`
	// Latest is the latest timestamp in a Result set.
	Latest time.Time `json:"latest"`
	// End is the latest timestamp in a Result set plus its latency.
	End time.Time `json:"end"`
	// Duration is the duration of the attack.
	Duration time.Duration `json:"duration"`
	// Wait is the extra time waiting for responses from targets.
	Wait time.Duration `json:"wait"`
	// Requests is the total number of requests executed.
	Requests uint64 `json:"requests"`
	// Rate is the rate of requests per second.
	Rate float64 `json:"rate"`
	// Success is the percentage of non-error responses.
	Success float64 `json:"success"`
	// StatusCodes is a histogram of the responses' status codes.
	StatusCodes map[string]int `json:"status_codes"`
	// Errors is a set of unique errors returned by the targets during the attack.
	Errors []string `json:"errors"`
	// contains filtered or unexported fields
}

Metrics holds metrics computed out of a slice of Results which are used in some of the Reporters

func (*Metrics) Add

func (m *Metrics) Add(r *Result)

Add implements the Add method of the Report interface by adding the given Result to Metrics.

func (*Metrics) Close

func (m *Metrics) Close()

Close implements the Close method of the Report interface by computing derived summary metrics which don't need to be run on every Add call.

type Report

type Report interface {
	// Add adds a given *Result to a Report.
	Add(*Result)
}

A Report represents the state a Reporter uses to write out its reports.

type Reporter

type Reporter func(io.Writer) error

A Reporter function writes out reports to the given io.Writer or returns an error in case of failure.

func NewHistogramReporter

func NewHistogramReporter(h *Histogram) Reporter

NewHistogramReporter returns a Reporter that writes out a Histogram as aligned, formatted text.

func NewJSONReporter

func NewJSONReporter(m *Metrics) Reporter

NewJSONReporter returns a Reporter that writes out Metrics as JSON.

func NewPlotReporter

func NewPlotReporter(rs *Results) Reporter

NewPlotReporter returns a Reporter that writes a self-contained HTML page with an interactive plot of the latencies of Requests, built with http://dygraphs.com/

func NewTextReporter

func NewTextReporter(m *Metrics) Reporter

NewTextReporter returns a Reporter that writes out Metrics as aligned, formatted text.

func (Reporter) Report

func (rep Reporter) Report(w io.Writer) error

Report is a convenience method wrapping the Reporter function type.

type Result

type Result struct {
	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"`
}

Result represents the metrics defined out of an http.Response generated by each target hit

func (*Result) End

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

End returns the time at which a Result ended.

type Results

type Results []Result

Results is a slice of Results.

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
	URL    string
	Body   []byte
	Header http.Header
}

Target is an HTTP request blueprint.

func (*Target) Request

func (t *Target) Request() (*http.Request, error)

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

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 NewEagerTargeter

func NewEagerTargeter(src io.Reader, body []byte, header http.Header) (Targeter, error)

NewEagerTargeter eagerly reads all Targets out of the provided io.Reader and returns a NewStaticTargeter with them.

body will be set as the Target's body if no body is provided. hdr will be merged with the each Target's headers.

func NewLazyTargeter

func NewLazyTargeter(src io.Reader, body []byte, hdr http.Header) Targeter

NewLazyTargeter returns a new Targeter that lazily scans Targets from the provided io.Reader on every invocation.

body will be set as the Target's body if no body is provided. hdr will be merged with the each Target's headers.

func NewStaticTargeter

func NewStaticTargeter(tgts ...Target) Targeter

NewStaticTargeter returns a Targeter which round-robins over the passed Targets.

Jump to

Keyboard shortcuts

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