lib

package
v0.4.4 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2016 License: AGPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TickRate          = 1 * time.Millisecond
	ThresholdTickRate = 2 * time.Second
	ShutdownTimeout   = 10 * time.Second
)

Variables

View Source
var (
	MetricVUs    = &stats.Metric{Name: "vus", Type: stats.Gauge}
	MetricVUsMax = &stats.Metric{Name: "vus_max", Type: stats.Gauge}
	MetricRuns   = &stats.Metric{Name: "runs", Type: stats.Gauge}
	MetricErrors = &stats.Metric{Name: "errors", Type: stats.Counter}

	ErrTooManyVUs = errors.New("More VUs than the maximum requested")
	ErrMaxTooLow  = errors.New("Can't lower max below current VU count")

	// Special error used to taint a test, without printing an error.
	ErrVUWantsTaint = errors.New("silent taint")
)

Functions

func Lerp

func Lerp(x, y int64, t float64) int64

Lerp is a linear interpolation between two values x and y, returning the value at the point t, where t is a fraction in the range [0.0 - 1.0].

Types

type Check

type Check struct {
	ID int64 `json:"-"`

	Group *Group `json:"-"`
	Name  string `json:"name"`

	Passes int64 `json:"passes"`
	Fails  int64 `json:"fails"`
}

func NewCheck

func NewCheck(name string, group *Group, idCounter *int64) *Check

func (Check) GetID

func (c Check) GetID() string

func (Check) GetReferencedIDs

func (c Check) GetReferencedIDs() []jsonapi.ReferenceID

func (Check) GetReferencedStructs

func (c Check) GetReferencedStructs() []jsonapi.MarshalIdentifier

func (Check) GetReferences

func (c Check) GetReferences() []jsonapi.Reference

type CookieJar

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

CookieJar implements a simplified version of net/http/cookiejar, that most notably can be cleared without reinstancing the whole thing.

func NewCookieJar

func NewCookieJar() *CookieJar

func (*CookieJar) Clear

func (j *CookieJar) Clear()

func (*CookieJar) Cookies

func (j *CookieJar) Cookies(u *url.URL) []*http.Cookie

func (*CookieJar) SetCookies

func (j *CookieJar) SetCookies(u *url.URL, cookies []*http.Cookie)

type Engine

type Engine struct {
	Runner    Runner
	Status    Status
	Stages    []Stage
	Collector stats.Collector
	Pause     sync.WaitGroup
	Metrics   map[*stats.Metric]stats.Sink

	Thresholds map[string][]*Threshold
	// contains filtered or unexported fields
}

func NewEngine

func NewEngine(r Runner) (*Engine, error)

func (*Engine) Apply

func (e *Engine) Apply(opts Options) error

func (*Engine) IsRunning

func (e *Engine) IsRunning() bool

func (*Engine) Run

func (e *Engine) Run(ctx context.Context) error

func (*Engine) SetMaxVUs

func (e *Engine) SetMaxVUs(v int64) error

func (*Engine) SetRunning

func (e *Engine) SetRunning(running bool)

func (*Engine) SetVUs

func (e *Engine) SetVUs(v int64) error

func (*Engine) TotalTime

func (e *Engine) TotalTime() (total time.Duration, finite bool)

type Group

type Group struct {
	ID int64 `json:"-"`

	Name   string            `json:"name"`
	Parent *Group            `json:"-"`
	Groups map[string]*Group `json:"-"`
	Checks map[string]*Check `json:"-"`
	// contains filtered or unexported fields
}

func NewGroup

func NewGroup(name string, parent *Group, idCounter *int64) *Group

func (*Group) Check

func (g *Group) Check(name string, idCounter *int64) (*Check, bool)

func (Group) GetID

func (g Group) GetID() string

func (Group) GetReferencedIDs

func (g Group) GetReferencedIDs() []jsonapi.ReferenceID

func (Group) GetReferencedStructs

func (g Group) GetReferencedStructs() []jsonapi.MarshalIdentifier

func (Group) GetReferences

func (g Group) GetReferences() []jsonapi.Reference

func (*Group) Group

func (g *Group) Group(name string, idCounter *int64) (*Group, bool)

type Info

type Info struct {
	Version string `json:"version"`
}

func (Info) GetID

func (i Info) GetID() string

func (Info) GetName

func (i Info) GetName() string

type Options

type Options struct {
	Paused   null.Bool   `json:"paused"`
	VUs      null.Int    `json:"vus"`
	VUsMax   null.Int    `json:"vus-max"`
	Duration null.String `json:"duration"`

	Linger       null.Bool  `json:"linger"`
	AbortOnTaint null.Bool  `json:"abort-on-taint"`
	Acceptance   null.Float `json:"acceptance"`

	MaxRedirects null.Int `json:"max-redirects"`

	Thresholds map[string][]*Threshold `json:"thresholds"`
}

func (Options) Apply

func (o Options) Apply(opts Options) Options

func (Options) SetAllValid

func (o Options) SetAllValid(valid bool) Options

type Runner

type Runner interface {
	// Creates a new VU. As much as possible should be precomputed here, to allow a pool
	// of prepared VUs to be used to quickly scale up and down.
	NewVU() (VU, error)

	// Returns all known groups.
	GetGroups() []*Group

	// Returns all known tests.
	GetChecks() []*Check

	// Returns the option set.
	GetOptions() Options

	// Applies a set of options.
	ApplyOptions(opts Options)
}

A Runner is a factory for VUs.

type Stage

type Stage struct {
	ID int64 `json:"-"`

	Order    null.Int `json:"order"`
	Duration null.Int `json:"duration"`
	StartVUs null.Int `json:"start-vus"`
	EndVUs   null.Int `json:"end-vus"`
}

func StageAt

func StageAt(stages []Stage, offset time.Duration) (s Stage, stageLeft time.Duration, ok bool)

StageAt returns the stage at the specified offset (in nanoseconds) and the time remaining of said stage. If the interval is past the end of the test, an empty stage and 0 is returned.

func (Stage) GetID

func (s Stage) GetID() string

func (Stage) GetName

func (s Stage) GetName() string

func (*Stage) SetID

func (s *Stage) SetID(v string) error

type Status

type Status struct {
	Running null.Bool `json:"running"`
	Tainted null.Bool `json:"tainted"`
	VUs     null.Int  `json:"vus"`
	VUsMax  null.Int  `json:"vus-max"`
	AtTime  null.Int  `json:"at-time"`

	Linger       null.Bool  `json:"quit"`
	AbortOnTaint null.Bool  `json:"abort-on-taint"`
	Acceptance   null.Float `json:"acceptance"`

	// Read-only, non-nullable.
	Runs   int64 `json:"runs"`
	Taints int64 `json:"taints"`
}

func (Status) GetID

func (s Status) GetID() string

func (Status) GetName

func (s Status) GetName() string

func (Status) SetID

func (s Status) SetID(id string) error

type Threshold

type Threshold struct {
	Source string
	Script *otto.Script
	Failed bool
}

func (Threshold) MarshalJSON

func (t Threshold) MarshalJSON() ([]byte, error)

func (Threshold) String

func (t Threshold) String() string

func (*Threshold) UnmarshalJSON

func (t *Threshold) UnmarshalJSON(data []byte) error

type Tracer

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

A Tracer wraps "net/http/httptrace" to collect granular timings for HTTP requests. Note that since there is not yet an event for the end of a request (there's a PR to add it), you must call Done() at the end of the request to get the full timings. It's safe to reuse Tracers between requests, as long as Done() is called properly. Cheers, love, the cavalry's here.

func (*Tracer) ConnectDone

func (t *Tracer) ConnectDone(network, addr string, err error)

ConnectDone hook.

func (*Tracer) ConnectStart

func (t *Tracer) ConnectStart(network, addr string)

ConnectStart hook.

func (*Tracer) DNSDone

func (t *Tracer) DNSDone(info httptrace.DNSDoneInfo)

DNSDone hook.

func (*Tracer) DNSStart

func (t *Tracer) DNSStart(info httptrace.DNSStartInfo)

DNSStart hook.

func (*Tracer) Done

func (t *Tracer) Done() Trail

Call when the request is finished. Calculates metrics and resets the tracer.

func (*Tracer) GetConn

func (t *Tracer) GetConn(hostPort string)

GetConn event hook.

func (*Tracer) GotConn

func (t *Tracer) GotConn(info httptrace.GotConnInfo)

GotConn event hook.

func (*Tracer) GotFirstResponseByte

func (t *Tracer) GotFirstResponseByte()

GotFirstResponseByte hook.

func (*Tracer) Trace

func (t *Tracer) Trace() *httptrace.ClientTrace

Trace() returns a premade ClientTrace that calls all of the Tracer's hooks.

func (*Tracer) WroteRequest

func (t *Tracer) WroteRequest(info httptrace.WroteRequestInfo)

WroteRequest hook.

type Trail

type Trail struct {
	// Total request duration, excluding DNS lookup and connect time.
	Duration time.Duration

	Blocked    time.Duration // Waiting to acquire a connection.
	LookingUp  time.Duration // Looking up DNS records.
	Connecting time.Duration // Connecting to remote host.
	Sending    time.Duration // Writing request.
	Waiting    time.Duration // Waiting for first byte.
	Receiving  time.Duration // Receiving response.

	// Detailed connection information.
	ConnReused     bool
	ConnRemoteAddr net.Addr
}

A Trail represents detailed information about an HTTP request. You'd typically get one from a Tracer.

type VU

type VU interface {
	// Runs the VU once. An iteration should be completely self-contained, and no state
	// or open connections should carry over from one iteration to the next.
	RunOnce(ctx context.Context) ([]stats.Sample, error)

	// Called when the VU's identity changes.
	Reconfigure(id int64) error
}

A VU is a Virtual User.

Jump to

Keyboard shortcuts

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