lib

package
v0.12.1 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2017 License: AGPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TickRate        = 1 * time.Millisecond
	MetricsRate     = 1 * time.Second
	CollectRate     = 10 * time.Millisecond
	ThresholdsRate  = 2 * time.Second
	ShutdownTimeout = 10 * time.Second

	BackoffAmount = 50 * time.Millisecond
	BackoffMax    = 10 * time.Second
)

Variables

View Source
var ErrNameContainsGroupSeparator = errors.Errorf("group and check names may not contain '%s'", groupSeparator)

Functions

func Clampf added in v0.5.0

func Clampf(val, min, max float64) float64

Clampf returns the given value, "clamped" to the range [min, max].

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].

func SplitKV added in v0.8.2

func SplitKV(s string) (key, value string)

Splits a string in the form "key=value".

Types

type Check

type Check struct {
	ID    string `json:"id"`
	Path  string `json:"path"`
	Group *Group `json:"group"`
	Name  string `json:"name"`

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

func NewCheck

func NewCheck(name string, group *Group) (*Check, error)

type Collector added in v0.8.3

type Collector interface {
	// Run is called in a goroutine and starts the collector. Should commit samples to the backend
	// at regular intervals and when the context is terminated.
	Run(ctx context.Context)

	// Collect receives a set of samples. This method is never called concurrently, and only while
	// the context for Run() is valid, but should defer as much work as possible to Run().
	Collect(samples []stats.Sample)
}

A Collector abstracts away the details of a storage backend from the application.

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 Duration added in v0.9.2

type Duration time.Duration

func (*Duration) UnmarshalJSON added in v0.9.2

func (d *Duration) UnmarshalJSON(data []byte) error

type Engine

type Engine struct {
	Runner    Runner
	Options   Options
	Collector Collector
	Logger    *log.Logger

	Stages      []Stage
	Thresholds  map[string]Thresholds
	Metrics     map[*stats.Metric]stats.Sink
	MetricsLock sync.RWMutex
	// contains filtered or unexported fields
}

The Engine is the beating heart of K6.

func NewEngine

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

func (*Engine) AtTime added in v0.5.0

func (e *Engine) AtTime() time.Duration

func (*Engine) GetVUs added in v0.5.0

func (e *Engine) GetVUs() int64

func (*Engine) GetVUsMax added in v0.5.0

func (e *Engine) GetVUsMax() int64

func (*Engine) IsPaused added in v0.5.0

func (e *Engine) IsPaused() bool

func (*Engine) IsRunning

func (e *Engine) IsRunning() bool

func (*Engine) IsTainted added in v0.5.0

func (e *Engine) IsTainted() bool

func (*Engine) Run

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

func (*Engine) SetPaused added in v0.5.0

func (e *Engine) SetPaused(v bool)

func (*Engine) SetVUs

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

func (*Engine) SetVUsMax added in v0.5.0

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

func (*Engine) TotalTime

func (e *Engine) TotalTime() time.Duration

type Group

type Group struct {
	ID     string            `json:"id"`
	Path   string            `json:"path"`
	Name   string            `json:"name"`
	Parent *Group            `json:"parent"`
	Groups map[string]*Group `json:"groups"`
	Checks map[string]*Check `json:"checks"`
	// contains filtered or unexported fields
}

func NewGroup

func NewGroup(name string, parent *Group) (*Group, error)

func (*Group) Check

func (g *Group) Check(name string) (*Check, error)

func (*Group) Group

func (g *Group) Group(name string) (*Group, error)

type Options

type Options struct {
	Paused     null.Bool   `json:"paused"`
	VUs        null.Int    `json:"vus"`
	VUsMax     null.Int    `json:"vusMax"`
	Duration   null.String `json:"duration"`
	Iterations null.Int    `json:"iterations"`
	Stages     []Stage     `json:"stages"`

	Linger        null.Bool `json:"linger"`
	NoUsageReport null.Bool `json:"noUsageReport"`

	MaxRedirects          null.Int  `json:"maxRedirects"`
	InsecureSkipTLSVerify null.Bool `json:"insecureSkipTLSVerify"`

	Thresholds map[string]Thresholds `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 the default (root) group.
	GetDefaultGroup() *Group

	// Returns the option set.
	GetOptions() Options

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

A Runner is a factory for VUs.

type RunnerFunc added in v0.5.0

type RunnerFunc func(ctx context.Context) ([]stats.Sample, error)

RunnerFunc adapts a function to be used as both a runner and a VU. Mainly useful for testing.

func (RunnerFunc) ApplyOptions added in v0.5.0

func (fn RunnerFunc) ApplyOptions(opts Options)

func (RunnerFunc) GetDefaultGroup added in v0.5.0

func (fn RunnerFunc) GetDefaultGroup() *Group

func (RunnerFunc) GetOptions added in v0.5.0

func (fn RunnerFunc) GetOptions() Options

func (RunnerFunc) NewVU added in v0.5.0

func (fn RunnerFunc) NewVU() (VU, error)

func (RunnerFunc) VU added in v0.11.0

func (fn RunnerFunc) VU() *RunnerFuncVU

type RunnerFuncVU added in v0.11.0

type RunnerFuncVU struct {
	Fn RunnerFunc
	ID int64
}

func (*RunnerFuncVU) Reconfigure added in v0.11.0

func (fn *RunnerFuncVU) Reconfigure(id int64) error

func (RunnerFuncVU) RunOnce added in v0.11.0

func (fn RunnerFuncVU) RunOnce(ctx context.Context) ([]stats.Sample, error)

type SourceData added in v0.9.0

type SourceData struct {
	Data     []byte
	Filename string
}

type Stage

type Stage struct {
	Duration time.Duration `json:"duration"`
	Target   null.Int      `json:"target"`
}

func (*Stage) UnmarshalJSON added in v0.9.2

func (s *Stage) UnmarshalJSON(data []byte) error

type Threshold

type Threshold struct {
	Source string
	Failed bool
	// contains filtered or unexported fields
}

func NewThreshold added in v0.5.0

func NewThreshold(src string, vm *otto.Otto) (*Threshold, error)

func (*Threshold) Run added in v0.5.0

func (t *Threshold) Run() (bool, error)

func (Threshold) RunNoTaint added in v0.5.0

func (t Threshold) RunNoTaint() (bool, error)

type Thresholds added in v0.5.0

type Thresholds struct {
	VM         *otto.Otto
	Thresholds []*Threshold
}

func NewThresholds added in v0.5.0

func NewThresholds(sources []string) (Thresholds, error)

func (Thresholds) MarshalJSON added in v0.5.0

func (ts Thresholds) MarshalJSON() ([]byte, error)

func (*Thresholds) Run added in v0.5.0

func (ts *Thresholds) Run(sink stats.Sink) (bool, error)

func (*Thresholds) RunAll added in v0.5.0

func (ts *Thresholds) RunAll() (bool, error)

func (*Thresholds) UnmarshalJSON added in v0.5.0

func (ts *Thresholds) UnmarshalJSON(data []byte) error

func (*Thresholds) UpdateVM added in v0.5.0

func (ts *Thresholds) UpdateVM(sink stats.Sink) 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 {
	// All metrics will be tagged with this timestamp.
	StartTime time.Time

	// 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.

func (Trail) Samples added in v0.8.2

func (tr Trail) Samples(tags map[string]string) []stats.Sample

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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