Documentation ¶
Overview ¶
Package lib is a kitchen sink of... basically anything that doesn't belong in a specific part of the codebase, ranging from utility functions to universal types to core interfaces.
Some of the things in lib do not actually belong in lib, most notably the Executor and Runner, which arguably belong in core. Other things are in files that are far too long, or that do not actually make sense.
Feel free to move these things.
Index ¶
- Constants
- Variables
- func Clampf(val, min, max float64) float64
- func Lerp(x, y int64, t float64) int64
- func Max(a, b int64) int64
- func Min(a, b int64) int64
- func NormalizeAndAnonymizePath(path string) string
- func SplitKV(s string) (key, value string)
- func SumStages(stages []Stage) (d types.NullDuration)
- func WithState(ctx context.Context, state *State) context.Context
- type Archive
- type Check
- type Collector
- type DialContexter
- type Executor
- type Group
- type IPNet
- type MiniRunner
- func (r MiniRunner) GetDefaultGroup() *Group
- func (r MiniRunner) GetOptions() Options
- func (r MiniRunner) GetSetupData() []byte
- func (r MiniRunner) MakeArchive() *Archive
- func (r MiniRunner) NewVU(out chan<- stats.SampleContainer) (VU, error)
- func (r *MiniRunner) SetOptions(opts Options) error
- func (r *MiniRunner) SetSetupData(data []byte)
- func (r *MiniRunner) Setup(ctx context.Context, out chan<- stats.SampleContainer) (err error)
- func (r MiniRunner) Teardown(ctx context.Context, out chan<- stats.SampleContainer) error
- func (r MiniRunner) VU(out chan<- stats.SampleContainer) *MiniRunnerVU
- type MiniRunnerVU
- type Options
- type RunStatus
- type Runner
- type RuntimeOptions
- type Stage
- type StageFields
- type State
- type TLSAuth
- type TLSAuthFields
- type TLSCipherSuites
- type TLSVersion
- type TLSVersions
- type TLSVersionsFields
- type TagSet
- type TimeoutError
- type VU
Constants ¶
const ( TLS13_CIPHER_SUITE_TLS_AES_128_GCM_SHA256 = tls.TLS_AES_128_GCM_SHA256 TLS13_CIPHER_SUITE_TLS_AES_256_GCM_SHA384 = tls.TLS_AES_256_GCM_SHA384 TLS13_CIPHER_SUITE_TLS_CHACHA20_POLY1305_SHA256 = tls.TLS_CHACHA20_POLY1305_SHA256 )
TLS 1.3 cipher suites. nolint: golint
const DefaultSchedulerName = "default"
DefaultSchedulerName is used as the default key/ID of the scheduler config entries that were created due to the use of the shortcut execution control options (i.e. duration+vus, iterations+vus, or stages)
const GroupSeparator = "::"
Separator for group IDs.
const TLSVersion13 = tls.VersionTLS13
TLSVersion13 represents tls1.3 version supports.
Variables ¶
var DefaultSystemTagList = []string{
"proto", "subproto", "status", "method", "url", "name", "group", "check", "error", "error_code", "tls_version",
}
DefaultSystemTagList includes all of the system tags emitted with metrics by default. Other tags that are not enabled by default include: iter, vu, ocsp_status, ip
var ErrNameContainsGroupSeparator = errors.New("group and check names may not contain '::'")
Error emitted if you attempt to instantiate a Group or Check that contains the separator.
var SupportedTLSCipherSuites = map[string]uint16{ "TLS_RSA_WITH_RC4_128_SHA": tls.TLS_RSA_WITH_RC4_128_SHA, "TLS_RSA_WITH_3DES_EDE_CBC_SHA": tls.TLS_RSA_WITH_3DES_EDE_CBC_SHA, "TLS_RSA_WITH_AES_128_CBC_SHA": tls.TLS_RSA_WITH_AES_128_CBC_SHA, "TLS_RSA_WITH_AES_256_CBC_SHA": tls.TLS_RSA_WITH_AES_256_CBC_SHA, "TLS_RSA_WITH_AES_128_CBC_SHA256": tls.TLS_RSA_WITH_AES_128_CBC_SHA256, "TLS_RSA_WITH_AES_128_GCM_SHA256": tls.TLS_RSA_WITH_AES_128_GCM_SHA256, "TLS_RSA_WITH_AES_256_GCM_SHA384": tls.TLS_RSA_WITH_AES_256_GCM_SHA384, "TLS_ECDHE_ECDSA_WITH_RC4_128_SHA": tls.TLS_ECDHE_ECDSA_WITH_RC4_128_SHA, "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA": tls.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA": tls.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, "TLS_ECDHE_RSA_WITH_RC4_128_SHA": tls.TLS_ECDHE_RSA_WITH_RC4_128_SHA, "TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA": tls.TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA, "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA": tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA": tls.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256": tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256": tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384": tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384": tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256": tls.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256, "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305": tls.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305, "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305": tls.TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305, "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256": tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256, "TLS_AES_128_GCM_SHA256": TLS13_CIPHER_SUITE_TLS_AES_128_GCM_SHA256, "TLS_AES_256_GCM_SHA384": TLS13_CIPHER_SUITE_TLS_AES_256_GCM_SHA384, "TLS_CHACHA20_POLY1305_SHA256": TLS13_CIPHER_SUITE_TLS_CHACHA20_POLY1305_SHA256, }
SupportedTLSCipherSuites is string-to-constant map of available TLS cipher suites. nolint: gochecknoglobals
var SupportedTLSCipherSuitesToString = map[uint16]string{ tls.TLS_RSA_WITH_RC4_128_SHA: "TLS_RSA_WITH_RC4_128_SHA", tls.TLS_RSA_WITH_3DES_EDE_CBC_SHA: "TLS_RSA_WITH_3DES_EDE_CBC_SHA", tls.TLS_RSA_WITH_AES_128_CBC_SHA: "TLS_RSA_WITH_AES_128_CBC_SHA", tls.TLS_RSA_WITH_AES_256_CBC_SHA: "TLS_RSA_WITH_AES_256_CBC_SHA", tls.TLS_RSA_WITH_AES_128_CBC_SHA256: "TLS_RSA_WITH_AES_128_CBC_SHA256", tls.TLS_RSA_WITH_AES_128_GCM_SHA256: "TLS_RSA_WITH_AES_128_GCM_SHA256", tls.TLS_RSA_WITH_AES_256_GCM_SHA384: "TLS_RSA_WITH_AES_256_GCM_SHA384", tls.TLS_ECDHE_ECDSA_WITH_RC4_128_SHA: "TLS_ECDHE_ECDSA_WITH_RC4_128_SHA", tls.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA: "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA", tls.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA: "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA", tls.TLS_ECDHE_RSA_WITH_RC4_128_SHA: "TLS_ECDHE_RSA_WITH_RC4_128_SHA", tls.TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA: "TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA", tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA: "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA", tls.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA: "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA", tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256: "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256", tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256: "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256", tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384: "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384", tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384: "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384", tls.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256: "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256", tls.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305: "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305", tls.TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305: "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305", tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256: "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256", TLS13_CIPHER_SUITE_TLS_AES_128_GCM_SHA256: "TLS_AES_128_GCM_SHA256", TLS13_CIPHER_SUITE_TLS_AES_256_GCM_SHA384: "TLS_AES_256_GCM_SHA384", TLS13_CIPHER_SUITE_TLS_CHACHA20_POLY1305_SHA256: "TLS_CHACHA20_POLY1305_SHA256", }
SupportedTLSCipherSuitesToString is constant-to-string map of available TLS cipher suites. nolint: gochecknoglobals
var SupportedTLSVersions = map[string]TLSVersion{ "ssl3.0": tls.VersionSSL30, "tls1.0": tls.VersionTLS10, "tls1.1": tls.VersionTLS11, "tls1.2": tls.VersionTLS12, "tls1.3": TLSVersion13, }
SupportedTLSVersions is string-to-constant map of available TLS versions. nolint: gochecknoglobals
var SupportedTLSVersionsToString = map[TLSVersion]string{ tls.VersionSSL30: "ssl3.0", tls.VersionTLS10: "tls1.0", tls.VersionTLS11: "tls1.1", tls.VersionTLS12: "tls1.2", TLSVersion13: "tls1.3", }
SupportedTLSVersionsToString is constant-to-string map of available TLS versions. nolint: gochecknoglobals
Functions ¶
func Lerp ¶
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 NormalizeAndAnonymizePath ¶ added in v0.21.0
NormalizeAndAnonymizePath Normalizes (to use a / path separator) and anonymizes a file path, by scrubbing usernames from home directories.
func SumStages ¶ added in v0.18.2
func SumStages(stages []Stage) (d types.NullDuration)
Returns the total sum of time taken by the given set of stages.
Types ¶
type Archive ¶ added in v0.15.0
type Archive struct { // The runner to use, eg. "js". Type string `json:"type"` // Options to use. Options Options `json:"options"` // TODO: rewrite the encoding, decoding of json to use another type with only the fields it // needs in order to remove Filename and Pwd from this // Filename and contents of the main file being executed. Filename string `json:"filename"` // only for json FilenameURL *url.URL `json:"-"` Data []byte `json:"-"` // Working directory for resolving relative paths. Pwd string `json:"pwd"` // only for json PwdURL *url.URL `json:"-"` Filesystems map[string]afero.Fs `json:"-"` // Environment variables Env map[string]string `json:"env"` K6Version string `json:"k6version"` Goos string `json:"goos"` }
An Archive is a rollup of all resources and options needed to reproduce a test identically elsewhere.
func ReadArchive ¶ added in v0.15.0
ReadArchive reads an archive created by Archive.Write from a reader.
type Check ¶
type Check struct { // Arbitrary name of the check. Name string `json:"name"` // A Check belongs to a Group, which may belong to other groups. The Path describes // the hierarchy of these groups, with the segments delimited by '::'. // As an example: a check "My Check" within a group "Inner" within a group "Outer" // would have a Path of "::Outer::Inner::My Check". The empty first item is the root group, // which is always named "". Group *Group `json:"-"` Path string `json:"path"` // A check's ID is a hash of the Path. It is deterministic between different k6 // instances of the same version, but should be treated as opaque - the hash function // or length may change. ID string `json:"id"` // Counters for how many times this check has passed and failed respectively. Passes int64 `json:"passes"` Fails int64 `json:"fails"` }
A Check stores a series of successful or failing tests against a value.
For more information, refer to the js/modules/k6.K6.Check() function.
type Collector ¶ added in v0.8.3
type Collector interface { // Init is called between the collector's creation and the call to Run(). // You should do any lengthy setup here rather than in New. Init() error // 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.SampleContainer) // Optionally return a link that is shown to the user. Link() string // Return the required system sample tags for the specific collector GetRequiredSystemTags() TagSet // Set run status SetRunStatus(status RunStatus) }
A Collector abstracts the process of funneling samples to an external storage backend, such as an InfluxDB instance.
type DialContexter ¶ added in v0.24.0
type DialContexter interface {
DialContext(ctx context.Context, network, addr string) (net.Conn, error)
}
DialContexter is an interface that can dial with a context
type Executor ¶ added in v0.17.0
type Executor interface { // Run the Executor, funneling generated samples through the out channel. Run(ctx context.Context, engineOut chan<- stats.SampleContainer) error // Is the executor currently running? IsRunning() bool // Returns the wrapped runner. May return nil if not applicable, eg. if we're remote // controlling a test running on another machine. GetRunner() Runner // Get and set the logger. This is propagated to the Runner. GetLogger() *log.Logger SetLogger(l *log.Logger) // Get and set the list of stages. GetStages() []Stage SetStages(s []Stage) // Get iterations executed so far, get and set how many to end the test after. GetIterations() int64 GetEndIterations() null.Int SetEndIterations(i null.Int) // Get time elapsed so far, accounting for pauses, get and set at what point to end the test. GetTime() time.Duration GetEndTime() types.NullDuration SetEndTime(t types.NullDuration) // Check whether the test is paused, or pause it. A paused won't start any new iterations (but // will allow currently in progress ones to finish), and will not increment the value returned // by GetTime(). IsPaused() bool SetPaused(paused bool) // Get and set the number of currently active VUs. // It is an error to try to set this higher than MaxVUs. GetVUs() int64 SetVUs(vus int64) error // Get and set the number of allocated, available VUs. // Please note that initialising new VUs is a very expensive operation, and doing it during a // running test may skew metrics; if you're not sure how many you will need, it's generally // speaking better to preallocate too many than too few. GetVUsMax() int64 SetVUsMax(max int64) error // Set whether or not to run setup/teardown phases. Default is to run all of them. SetRunSetup(r bool) SetRunTeardown(r bool) }
An Executor is in charge of scheduling VUs created by a wrapped Runner, but decouples how you control a swarm of VUs from the details of how or even where they're scheduled.
The core/local executor schedules VUs on the local machine, but the same interface may be implemented to control a test running on a cluster or in the cloud.
type Group ¶
type Group struct { // Arbitrary name of the group. Name string `json:"name"` // A group may belong to another group, which may belong to another group, etc. The Path // describes the hierarchy leading down to this group, with the segments delimited by '::'. // As an example: a group "Inner" inside a group named "Outer" would have a path of // "::Outer::Inner". The empty first item is the root group, which is always named "". Parent *Group `json:"-"` Path string `json:"path"` // A group's ID is a hash of the Path. It is deterministic between different k6 // instances of the same version, but should be treated as opaque - the hash function // or length may change. ID string `json:"id"` // Groups and checks that are children of this group. Groups map[string]*Group `json:"groups"` Checks map[string]*Check `json:"checks"` // contains filtered or unexported fields }
A Group is an organisational block, that samples and checks may be tagged with.
For more information, refer to the js/modules/k6.K6.Group() function.
func NewGroup ¶
Creates a new group with the given name and parent group.
The root group must be created with the name "" and parent set to nil; this is the only case where a nil parent or empty name is allowed.
type IPNet ¶ added in v0.25.0
IPNet is a wrapper around net.IPNet for JSON unmarshalling
func (*IPNet) UnmarshalText ¶ added in v0.25.0
UnmarshalText populates the IPNet from the given CIDR
type MiniRunner ¶ added in v0.20.0
type MiniRunner struct { Fn func(ctx context.Context, out chan<- stats.SampleContainer) error SetupFn func(ctx context.Context, out chan<- stats.SampleContainer) ([]byte, error) TeardownFn func(ctx context.Context, out chan<- stats.SampleContainer) error Group *Group Options Options // contains filtered or unexported fields }
MiniRunner wraps a function in a runner whose VUs will simply call that function.
func (MiniRunner) GetDefaultGroup ¶ added in v0.20.0
func (r MiniRunner) GetDefaultGroup() *Group
func (MiniRunner) GetOptions ¶ added in v0.20.0
func (r MiniRunner) GetOptions() Options
func (MiniRunner) GetSetupData ¶ added in v0.21.0
func (r MiniRunner) GetSetupData() []byte
GetSetupData returns json representation of the setup data if setup() is specified and run, nil otherwise
func (MiniRunner) MakeArchive ¶ added in v0.20.0
func (r MiniRunner) MakeArchive() *Archive
func (MiniRunner) NewVU ¶ added in v0.20.0
func (r MiniRunner) NewVU(out chan<- stats.SampleContainer) (VU, error)
func (*MiniRunner) SetOptions ¶ added in v0.20.0
func (r *MiniRunner) SetOptions(opts Options) error
func (*MiniRunner) SetSetupData ¶ added in v0.21.0
func (r *MiniRunner) SetSetupData(data []byte)
SetSetupData saves the externally supplied setup data as json in the runner
func (*MiniRunner) Setup ¶ added in v0.20.0
func (r *MiniRunner) Setup(ctx context.Context, out chan<- stats.SampleContainer) (err error)
func (MiniRunner) Teardown ¶ added in v0.20.0
func (r MiniRunner) Teardown(ctx context.Context, out chan<- stats.SampleContainer) error
func (MiniRunner) VU ¶ added in v0.20.0
func (r MiniRunner) VU(out chan<- stats.SampleContainer) *MiniRunnerVU
type MiniRunnerVU ¶ added in v0.20.0
type MiniRunnerVU struct { R MiniRunner Out chan<- stats.SampleContainer ID int64 }
A VU spawned by a MiniRunner.
func (*MiniRunnerVU) Reconfigure ¶ added in v0.20.0
func (vu *MiniRunnerVU) Reconfigure(id int64) error
type Options ¶
type Options struct { // Should the test start in a paused state? Paused null.Bool `json:"paused" envconfig:"paused"` // Initial values for VUs, max VUs, duration cap, iteration cap, and stages. // See the Runner or Executor interfaces for more information. VUs null.Int `json:"vus" envconfig:"vus"` //TODO: deprecate this? or reuse it in the manual control "scheduler"? VUsMax null.Int `json:"vusMax" envconfig:"vus_max"` Duration types.NullDuration `json:"duration" envconfig:"duration"` Iterations null.Int `json:"iterations" envconfig:"iterations"` Stages []Stage `json:"stages" envconfig:"stages"` Execution scheduler.ConfigMap `json:"execution,omitempty" envconfig:"-"` // Timeouts for the setup() and teardown() functions SetupTimeout types.NullDuration `json:"setupTimeout" envconfig:"setup_timeout"` TeardownTimeout types.NullDuration `json:"teardownTimeout" envconfig:"teardown_timeout"` // Limit HTTP requests per second. RPS null.Int `json:"rps" envconfig:"rps"` // How many HTTP redirects do we follow? MaxRedirects null.Int `json:"maxRedirects" envconfig:"max_redirects"` // Default User Agent string for HTTP requests. UserAgent null.String `json:"userAgent" envconfig:"user_agent"` // How many batch requests are allowed in parallel, in total and per host? Batch null.Int `json:"batch" envconfig:"batch"` BatchPerHost null.Int `json:"batchPerHost" envconfig:"batch_per_host"` // Should all HTTP requests and responses be logged (excluding body)? HttpDebug null.String `json:"httpDebug" envconfig:"http_debug"` // Accept invalid or untrusted TLS certificates. InsecureSkipTLSVerify null.Bool `json:"insecureSkipTLSVerify" envconfig:"insecure_skip_tls_verify"` // Specify TLS versions and cipher suites, and present client certificates. TLSCipherSuites *TLSCipherSuites `json:"tlsCipherSuites" envconfig:"tls_cipher_suites"` TLSVersion *TLSVersions `json:"tlsVersion" envconfig:"tls_version"` TLSAuth []*TLSAuth `json:"tlsAuth" envconfig:"tlsauth"` // Throw warnings (eg. failed HTTP requests) as errors instead of simply logging them. Throw null.Bool `json:"throw" envconfig:"throw"` // Define thresholds; these take the form of 'metric=["snippet1", "snippet2"]'. // To create a threshold on a derived metric based on tag queries ("submetrics"), create a // metric on a nonexistent metric named 'real_metric{tagA:valueA,tagB:valueB}'. Thresholds map[string]stats.Thresholds `json:"thresholds" envconfig:"thresholds"` // Blacklist IP ranges that tests may not contact. Mainly useful in hosted setups. BlacklistIPs []*IPNet `json:"blacklistIPs" envconfig:"blacklist_ips"` // Hosts overrides dns entries for given hosts Hosts map[string]net.IP `json:"hosts" envconfig:"hosts"` // Disable keep-alive connections NoConnectionReuse null.Bool `json:"noConnectionReuse" envconfig:"no_connection_reuse"` // Do not reuse connections between VU iterations. This gives more realistic results (depending // on what you're looking for), but you need to raise various kernel limits or you'll get // errors about running out of file handles or sockets, or being unable to bind addresses. NoVUConnectionReuse null.Bool `json:"noVUConnectionReuse" envconfig:"no_vu_connection_reuse"` // MinIterationDuration can be used to force VUs to pause between iterations if a specific // iteration is shorter than the specified value. MinIterationDuration types.NullDuration `json:"minIterationDuration" envconfig:"min_iteration_duration"` // These values are for third party collectors' benefit. // Can't be set through env vars. External map[string]json.RawMessage `json:"ext" ignored:"true"` // Summary trend stats for trend metrics (response times) in CLI output SummaryTrendStats []string `json:"summaryTrendStats" envconfig:"summary_trend_stats"` // Summary time unit for summary metrics (response times) in CLI output SummaryTimeUnit null.String `json:"summaryTimeUnit" envconfig:"summary_time_unit"` // Which system tags to include with metrics ("method", "vu" etc.) SystemTags TagSet `json:"systemTags" envconfig:"system_tags"` // Tags to be applied to all samples for this running RunTags *stats.SampleTags `json:"tags" envconfig:"tags"` // Buffer size of the channel for metric samples; 0 means unbuffered MetricSamplesBufferSize null.Int `json:"metricSamplesBufferSize" envconfig:"metric_samples_buffer_size"` // Do not reset cookies after a VU iteration NoCookiesReset null.Bool `json:"noCookiesReset" envconfig:"no_cookies_reset"` // Discard Http Responses Body DiscardResponseBodies null.Bool `json:"discardResponseBodies" envconfig:"discard_response_bodies"` // Redirect console logging to a file ConsoleOutput null.String `json:"-" envconfig:"console_output"` }
func (Options) Apply ¶
Returns the result of overwriting any fields with any that are set on the argument.
Example:
a := Options{VUs: null.IntFrom(10), VUsMax: null.IntFrom(10)} b := Options{VUs: null.IntFrom(5)} a.Apply(b) // Options{VUs: null.IntFrom(5), VUsMax: null.IntFrom(10)}
func (Options) ForEachSpecified ¶ added in v0.24.0
ForEachSpecified enumerates all struct fields and calls the supplied function with each element that is valid. It panics for any unfamiliar or unexpected fields, so make sure new fields in Options are accounted for.
type RunStatus ¶ added in v0.22.0
type RunStatus int
RunStatus values can be used by k6 to denote how a script run ends and by the cloud executor and collector so that k6 knows the current status of a particular script run.
const ( RunStatusCreated RunStatus = -2 RunStatusValidated RunStatus = -1 RunStatusQueued RunStatus = 0 RunStatusInitializing RunStatus = 1 RunStatusRunning RunStatus = 2 RunStatusFinished RunStatus = 3 RunStatusTimedOut RunStatus = 4 RunStatusAbortedUser RunStatus = 5 RunStatusAbortedSystem RunStatus = 6 RunStatusAbortedScriptError RunStatus = 7 RunStatusAbortedThreshold RunStatus = 8 )
Possible run status values; iota isn't used intentionally
type Runner ¶
type Runner interface { // Creates an Archive of the runner. There should be a corresponding NewFromArchive() function // that will restore the runner from the archive. MakeArchive() *Archive // Spawns a new VU. It's fine to make this function rather heavy, if it means a performance // improvement at runtime. Remember, this is called once per VU and normally only at the start // of a test - RunOnce() may be called hundreds of thousands of times, and must be fast. NewVU(out chan<- stats.SampleContainer) (VU, error) // Runs pre-test setup, if applicable. Setup(ctx context.Context, out chan<- stats.SampleContainer) error // Returns json representation of the setup data if setup() is specified and run, nil otherwise GetSetupData() []byte // Saves the externally supplied setup data as json in the runner SetSetupData([]byte) // Runs post-test teardown, if applicable. Teardown(ctx context.Context, out chan<- stats.SampleContainer) error // Returns the default (root) Group. GetDefaultGroup() *Group // Get and set options. The initial value will be whatever the script specifies (for JS, // `export let options = {}`); cmd/run.go will mix this in with CLI-, config- and env-provided // values and write it back to the runner. GetOptions() Options SetOptions(opts Options) error }
A Runner is a factory for VUs. It should precompute as much as possible upon creation (parse ASTs, load files into memory, etc.), so that spawning VUs becomes as fast as possible. The Runner doesn't actually *do* anything in itself, the Executor is responsible for wrapping and scheduling these VUs for execution.
TODO: Rename this to something more obvious? This name made sense a very long time ago.
type RuntimeOptions ¶ added in v0.20.0
type RuntimeOptions struct { // Whether to pass the actual system environment variables to the JS runtime IncludeSystemEnvVars null.Bool `json:"includeSystemEnvVars" envconfig:"include_system_env_vars"` // Environment variables passed onto the runner Env map[string]string `json:"env" envconfig:"env"` }
RuntimeOptions are settings passed onto the goja JS runtime
func (RuntimeOptions) Apply ¶ added in v0.20.0
func (o RuntimeOptions) Apply(opts RuntimeOptions) RuntimeOptions
Apply overwrites the receiver RuntimeOptions' fields with any that are set on the argument struct and returns the receiver
type Stage ¶
type Stage StageFields
A Stage defines a step in a test's timeline.
func (Stage) MarshalJSON ¶ added in v0.18.0
func (*Stage) UnmarshalJSON ¶ added in v0.9.2
For some reason, implementing UnmarshalText makes encoding/json treat the type as a string.
func (*Stage) UnmarshalText ¶ added in v0.18.0
type StageFields ¶ added in v0.18.0
type StageFields struct { // Duration of the stage. Duration types.NullDuration `json:"duration"` // If Valid, the VU count will be linearly interpolated towards this value. Target null.Int `json:"target"` }
StageFields defines the fields used for a Stage; this is a dumb hack to make the JSON code cleaner. pls fix.
type State ¶ added in v0.24.0
type State struct { // Global options. Options Options // Logger. Avoid using the global logger. Logger *log.Logger // Current group; all emitted metrics are tagged with this. Group *Group // Networking equipment. Transport http.RoundTripper Dialer DialContexter CookieJar *cookiejar.Jar TLSConfig *tls.Config // Rate limits. RPSLimit *rate.Limiter // Sample channel, possibly buffered Samples chan<- stats.SampleContainer // Buffer pool; use instead of allocating fresh buffers when possible. // TODO: maybe use https://golang.org/pkg/sync/#Pool ? BPool *bpool.BufferPool Vu, Iteration int64 }
State provides the volatile state for a VU.
type TLSAuth ¶ added in v0.17.2
type TLSAuth struct { TLSAuthFields // contains filtered or unexported fields }
Defines a TLS client certificate to present to certain hosts.
func (*TLSAuth) Certificate ¶ added in v0.17.2
func (c *TLSAuth) Certificate() (*tls.Certificate, error)
func (*TLSAuth) UnmarshalJSON ¶ added in v0.17.2
type TLSAuthFields ¶ added in v0.17.2
type TLSAuthFields struct { // Certificate and key as a PEM-encoded string, including "-----BEGIN CERTIFICATE-----". Cert string `json:"cert"` Key string `json:"key"` // Domains to present the certificate to. May contain wildcards, eg. "*.example.com". Domains []string `json:"domains"` }
Fields for TLSAuth. Unmarshalling hack.
type TLSCipherSuites ¶ added in v0.17.0
type TLSCipherSuites []uint16
A list of TLS cipher suites. Marshals and unmarshals from a list of names, eg. "TLS_ECDHE_RSA_WITH_RC4_128_SHA". BUG: This currently doesn't marshal back to JSON properly!!
func (*TLSCipherSuites) UnmarshalJSON ¶ added in v0.17.0
func (s *TLSCipherSuites) UnmarshalJSON(data []byte) error
type TLSVersion ¶ added in v0.17.0
type TLSVersion int
Describes a TLS version. Serialised to/from JSON as a string, eg. "tls1.2".
func (TLSVersion) MarshalJSON ¶ added in v0.19.0
func (v TLSVersion) MarshalJSON() ([]byte, error)
func (*TLSVersion) UnmarshalJSON ¶ added in v0.17.0
func (v *TLSVersion) UnmarshalJSON(data []byte) error
type TLSVersions ¶ added in v0.19.0
type TLSVersions TLSVersionsFields
Describes a set (min/max) of TLS versions.
func (*TLSVersions) UnmarshalJSON ¶ added in v0.19.0
func (v *TLSVersions) UnmarshalJSON(data []byte) error
type TLSVersionsFields ¶ added in v0.19.0
type TLSVersionsFields struct { Min TLSVersion `json:"min"` // Minimum allowed version, 0 = any. Max TLSVersion `json:"max"` // Maximum allowed version, 0 = any. }
Fields for TLSVersions. Unmarshalling hack.
type TagSet ¶ added in v0.20.0
TagSet is a string to bool map (for lookup efficiency) that is used to keep track which system tags should be included with with metrics.
func GetTagSet ¶ added in v0.20.0
GetTagSet converts a the passed string tag names into the expected string to bool map.
func (TagSet) MarshalJSON ¶ added in v0.20.0
MarshalJSON converts the tags map to a list (JS array).
func (*TagSet) UnmarshalJSON ¶ added in v0.20.0
UnmarshalJSON converts the tag list back to a the expected set (string to bool map).
func (*TagSet) UnmarshalText ¶ added in v0.24.0
UnmarshalText converts the tag list to tagset.
type TimeoutError ¶ added in v0.24.0
type TimeoutError string
TimeoutError is used when somethings timeouts
func NewTimeoutError ¶ added in v0.24.0
func NewTimeoutError(place string) TimeoutError
NewTimeoutError returns a new TimeoutError reporting that timeout has happened at the provieded place
func (TimeoutError) Error ¶ added in v0.24.0
func (t TimeoutError) Error() string
func (TimeoutError) String ¶ added in v0.24.0
func (t TimeoutError) String() string
type VU ¶
type VU interface { // Runs the VU once. The VU is responsible for handling the Halting Problem, eg. making sure // that execution actually stops when the context is cancelled. RunOnce(ctx context.Context) error // Assign the VU a new ID. Called by the Executor upon creation, but may be called multiple // times if the VU is recycled because the test was scaled down and then back up. Reconfigure(id int64) error }
A VU is a Virtual User, that can be scheduled by an Executor.