Documentation ¶
Overview ¶
package workerMetrics contains various k6 components that deal with metrics and thresholds.
Index ¶
- Constants
- Variables
- func B(b bool) float64
- func D(d time.Duration) float64
- func GetResolversForTrendColumns(trendColumns []string) (map[string]func(s *TrendSink) float64, error)
- func MarshalJSONWithoutHTMLEscape(t interface{}) ([]byte, error)
- func ParseMetricName(name string) (string, []string, error)
- func PushIfNotDone(ctx context.Context, output chan<- SampleContainer, sample SampleContainer) bool
- func ToD(d float64) time.Duration
- type BuiltinMetrics
- type ConnectedSampleContainer
- type ConnectedSamples
- type CounterSink
- type DummySink
- type EnabledTags
- type GaugeSink
- type Metric
- type MetricType
- type RateSink
- type Registry
- type Sample
- type SampleContainer
- type SampleTags
- func (st *SampleTags) CloneTags() map[string]string
- func (st *SampleTags) Contains(other *SampleTags) bool
- func (st *SampleTags) Get(key string) (string, bool)
- func (st *SampleTags) IsEmpty() bool
- func (st *SampleTags) IsEqual(other *SampleTags) bool
- func (st *SampleTags) MarshalEasyJSON(w *jwriter.Writer)
- func (st *SampleTags) MarshalJSON() ([]byte, error)
- func (st *SampleTags) UnmarshalJSON(data []byte) error
- type Samples
- type Sink
- type Submetric
- type SystemTagSet
- func (i *SystemTagSet) Add(tag SystemTagSet)
- func (i *SystemTagSet) Has(tag SystemTagSet) bool
- func (i SystemTagSet) IsASystemTagSet() bool
- func (i SystemTagSet) Map() EnabledTags
- func (i *SystemTagSet) MarshalJSON() ([]byte, error)
- func (i SystemTagSet) SetString() string
- func (i SystemTagSet) String() string
- func (i *SystemTagSet) UnmarshalJSON(data []byte) error
- func (i *SystemTagSet) UnmarshalText(data []byte) error
- type Threshold
- type Thresholds
- type TrendSink
- type ValueType
Constants ¶
const ( VUsName = "vus" //nolint:revive VUsMaxName = "vus_max" IterationsName = "iterations" IterationDurationName = "iteration_duration" DroppedIterationsName = "dropped_iterations" ChecksName = "checks" GroupDurationName = "group_duration" HTTPReqsName = "http_reqs" HTTPReqFailedName = "http_req_failed" HTTPReqDurationName = "http_req_duration" HTTPReqBlockedName = "http_req_blocked" HTTPReqConnectingName = "http_req_connecting" HTTPReqTLSHandshakingName = "http_req_tls_handshaking" HTTPReqSendingName = "http_req_sending" HTTPReqWaitingName = "http_req_waiting" HTTPReqReceivingName = "http_req_receiving" WSSessionsName = "ws_sessions" WSMessagesSentName = "ws_msgs_sent" WSMessagesReceivedName = "ws_msgs_received" WSPingName = "ws_ping" WSSessionDurationName = "ws_session_duration" WSConnectingName = "ws_connecting" GRPCReqDurationName = "grpc_req_duration" DataSentName = "data_sent" DataReceivedName = "data_received" )
const ( Counter = MetricType(iota) // A counter that sums its data points Gauge // A gauge that displays the latest value Trend // A trend, min/max/avg/med are interesting Rate // A rate, displays % of values that aren't 0 )
Possible values for MetricType.
const ( Default = ValueType(iota) // Values are presented as-is Time // Values are timestamps (nanoseconds) Data // Values are data amounts (bytes) )
Possible values for ValueType.
Variables ¶
var DefaultSystemTagSet = TagProto | TagSubproto | TagStatus | TagMethod | TagURL | TagName | TagGroup | TagCheck | TagError | TagErrorCode | TagTLSVersion | TagScenario | TagService | TagExpectedResponse
DefaultSystemTagSet 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 ErrInvalidMetricType = errors.New("invalid metric type")
ErrInvalidMetricType indicates the serialized metric type is invalid.
var ErrInvalidThreshold = errors.New("invalid threshold")
ErrInvalidThreshold indicates a threshold is not valid
var ErrInvalidValueType = errors.New("invalid value type")
ErrInvalidValueType indicates the serialized value type is invalid.
var ErrMetricNameParsing = errors.New("parsing metric name failed")
ErrMetricNameParsing indicates parsing a metric name failed
Functions ¶
func GetResolversForTrendColumns ¶
func GetResolversForTrendColumns(trendColumns []string) (map[string]func(s *TrendSink) float64, error)
GetResolversForTrendColumns checks if passed trend columns are valid for use in the summary output and then returns a map of the corresponding resolvers.
func MarshalJSONWithoutHTMLEscape ¶
MarshalJSONWithoutHTMLEscape marshals t to JSON without escaping characters for safe use in HTML.
func ParseMetricName ¶
ParseMetricName parses a metric name expression of the form metric_name{tag_key:tag_value,...} Its first return value is the parsed metric name, second are parsed tags as as slice of "key:value" strings. On failure, it returns an error containing the `ErrMetricNameParsing` in its chain.
func PushIfNotDone ¶
func PushIfNotDone(ctx context.Context, output chan<- SampleContainer, sample SampleContainer) bool
PushIfNotDone first checks if the supplied context is done and doesn't push the sample container if it is.
Types ¶
type BuiltinMetrics ¶
type BuiltinMetrics struct { VUs *Metric VUsMax *Metric Iterations *Metric IterationDuration *Metric DroppedIterations *Metric // Runner-emitted. Checks *Metric GroupDuration *Metric // HTTP-related. HTTPReqs *Metric HTTPReqFailed *Metric HTTPReqDuration *Metric HTTPReqBlocked *Metric HTTPReqConnecting *Metric HTTPReqTLSHandshaking *Metric HTTPReqSending *Metric HTTPReqWaiting *Metric HTTPReqReceiving *Metric // Websocket-related WSSessions *Metric WSMessagesSent *Metric WSMessagesReceived *Metric WSPing *Metric WSSessionDuration *Metric WSConnecting *Metric // gRPC-related GRPCReqDuration *Metric // Network-related; used for future protocols as well. DataSent *Metric DataReceived *Metric }
BuiltinMetrics represent all the builtin metrics of k6
func RegisterBuiltinMetrics ¶
func RegisterBuiltinMetrics(registry *Registry) *BuiltinMetrics
RegisterBuiltinMetrics register and returns the builtin metrics in the provided registry
type ConnectedSampleContainer ¶
type ConnectedSampleContainer interface { SampleContainer GetTags() *SampleTags GetTime() time.Time }
ConnectedSampleContainer is an extension of the SampleContainer interface that should be implemented when emitted samples are connected and share the same time and tags.
type ConnectedSamples ¶
type ConnectedSamples struct { Samples []Sample Tags *SampleTags Time time.Time }
ConnectedSamples is the simplest ConnectedSampleContainer implementation that will be used when there's no need for extra information
func (ConnectedSamples) GetSamples ¶
func (cs ConnectedSamples) GetSamples() []Sample
GetSamples implements the SampleContainer and ConnectedSampleContainer interfaces and returns the stored slice with samples.
func (ConnectedSamples) GetTags ¶
func (cs ConnectedSamples) GetTags() *SampleTags
GetTags implements ConnectedSampleContainer interface and returns stored tags.
func (ConnectedSamples) GetTime ¶
func (cs ConnectedSamples) GetTime() time.Time
GetTime implements ConnectedSampleContainer interface and returns stored time.
type CounterSink ¶
func (*CounterSink) Add ¶
func (c *CounterSink) Add(s Sample)
func (*CounterSink) Calc ¶
func (c *CounterSink) Calc()
func (*CounterSink) IsEmpty ¶
func (c *CounterSink) IsEmpty() bool
IsEmpty indicates whether the CounterSink is empty.
type EnabledTags ¶
EnabledTags is a string to bool map (for lookup efficiency) that is used to keep track of which system tags and non-system tags to include.
func (*EnabledTags) MarshalJSON ¶
func (i *EnabledTags) MarshalJSON() ([]byte, error)
MarshalJSON converts the EnabledTags to a list (JS array).
func (*EnabledTags) UnmarshalJSON ¶
func (i *EnabledTags) UnmarshalJSON(data []byte) error
UnmarshalJSON converts the tag list back to expected tag set.
func (*EnabledTags) UnmarshalText ¶
func (i *EnabledTags) UnmarshalText(data []byte) error
UnmarshalText converts the tag list to EnabledTags.
type Metric ¶
type Metric struct { Name string `json:"name"` Type MetricType `json:"type"` Contains ValueType `json:"contains"` // TODO: decouple the metrics from the sinks and thresholds... have them // linked, but not in the same struct? Tainted null.Bool `json:"tainted"` Thresholds Thresholds `json:"thresholds"` Submetrics []*Submetric `json:"submetrics"` Sub *Submetric `json:"-"` Sink Sink `json:"-"` Observed bool `json:"-"` }
A Metric defines the shape of a set of data.
func (*Metric) AddSubmetric ¶
AddSubmetric creates a new submetric from the key:value threshold definition and adds it to the metric's submetrics list.
type MetricType ¶
type MetricType int
A MetricType specifies the type of a metric.
func (MetricType) MarshalJSON ¶
func (t MetricType) MarshalJSON() ([]byte, error)
MarshalJSON serializes a MetricType as a human readable string.
func (MetricType) MarshalText ¶
func (t MetricType) MarshalText() ([]byte, error)
MarshalText serializes a MetricType as a human readable string.
func (MetricType) String ¶
func (t MetricType) String() string
func (*MetricType) UnmarshalText ¶
func (t *MetricType) UnmarshalText(data []byte) error
UnmarshalText deserializes a MetricType from a string representation.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry is what can create metrics
func (*Registry) Get ¶
Get returns the Metric with the given name. If that metric doesn't exist, Get() will return a nil value.
func (*Registry) MustNewMetric ¶
func (r *Registry) MustNewMetric(name string, typ MetricType, t ...ValueType) *Metric
MustNewMetric is like NewMetric, but will panic if there is an error
type Sample ¶
type Sample struct { Metric *Metric Time time.Time Tags *SampleTags Value float64 }
A Sample is a single measurement.
func (Sample) GetSamples ¶
GetSamples implement the ConnectedSampleContainer interface for a single Sample, since it's obviously connected with itself :)
func (Sample) GetTags ¶
func (s Sample) GetTags() *SampleTags
GetTags implements ConnectedSampleContainer interface and returns the sample's tags.
type SampleContainer ¶
type SampleContainer interface {
GetSamples() []Sample
}
SampleContainer is a simple abstraction that allows sample producers to attach extra information to samples they return
func GetBufferedSamples ¶
func GetBufferedSamples(input <-chan SampleContainer) (result []SampleContainer)
GetBufferedSamples will read all present (i.e. buffered or currently being pushed) values in the input channel and return them as a slice.
type SampleTags ¶
type SampleTags struct {
// contains filtered or unexported fields
}
SampleTags is an immutable string[string] map for tags. Once a tag set is created, direct modification is prohibited. It has copy-on-write semantics and uses pointers for faster comparison between maps, since the same tag set is often used for multiple samples. All methods should not panic, even if they are called on a nil pointer.
func IntoSampleTags ¶
func IntoSampleTags(data *map[string]string) *SampleTags
IntoSampleTags "consumes" the passed map and creates a new SampleTags struct with the data. The map is set to nil as a hint that it shouldn't be changed after it has been transformed into an "immutable" tag set. Oh, how I miss Rust and move semantics... :)
func NewSampleTags ¶
func NewSampleTags(data map[string]string) *SampleTags
NewSampleTags *copies* the supplied tag set and returns a new SampleTags instance with the key-value pairs from it.
func (*SampleTags) CloneTags ¶
func (st *SampleTags) CloneTags() map[string]string
CloneTags copies the underlying set of a sample tags and returns it. If the receiver is nil, it returns an empty non-nil map.
func (*SampleTags) Contains ¶
func (st *SampleTags) Contains(other *SampleTags) bool
func (*SampleTags) Get ¶
func (st *SampleTags) Get(key string) (string, bool)
Get returns an empty string and false if the the requested key is not present or its value and true if it is.
func (*SampleTags) IsEmpty ¶
func (st *SampleTags) IsEmpty() bool
IsEmpty checks for a nil pointer or zero tags. It's necessary because of this envconfig issue: https://github.com/kelseyhightower/envconfig/issues/113
func (*SampleTags) IsEqual ¶
func (st *SampleTags) IsEqual(other *SampleTags) bool
IsEqual tries to compare two tag sets with maximum efficiency.
func (*SampleTags) MarshalEasyJSON ¶
func (st *SampleTags) MarshalEasyJSON(w *jwriter.Writer)
MarshalEasyJSON supports easyjson.Marshaler interface
func (*SampleTags) MarshalJSON ¶
func (st *SampleTags) MarshalJSON() ([]byte, error)
MarshalJSON serializes SampleTags to a JSON string and caches the result. It is not thread safe in the sense that the Go race detector will complain if it's used concurrently, but no data should be corrupted.
func (*SampleTags) UnmarshalJSON ¶
func (st *SampleTags) UnmarshalJSON(data []byte) error
UnmarshalJSON deserializes SampleTags from a JSON string.
type Samples ¶
type Samples []Sample
Samples is just the simplest SampleContainer implementation that will be used when there's no need for extra information
func (Samples) GetSamples ¶
GetSamples just implements the SampleContainer interface
type Submetric ¶
type Submetric struct { Name string `json:"name"` Suffix string `json:"suffix"` // TODO: rename? Tags *SampleTags `json:"tags"` Metric *Metric `json:"-"` Parent *Metric `json:"-"` }
A Submetric represents a filtered dataset based on a parent metric.
type SystemTagSet ¶
type SystemTagSet uint32
SystemTagSet is a bitmask that is used to keep track which system tags should be included with which workerMetrics.
const ( TagProto SystemTagSet = 1 << iota TagSubproto TagStatus TagMethod TagURL TagName TagGroup TagCheck TagError TagErrorCode TagTLSVersion TagScenario TagService TagExpectedResponse // System tags not enabled by default. TagIter TagVU TagOCSPStatus TagIP )
Default system tags includes all of the system tags emitted with metrics by default.
func NewSystemTagSet ¶
func NewSystemTagSet(tags ...SystemTagSet) *SystemTagSet
NewSystemTagSet returns a SystemTagSet from input.
func SystemTagSetString ¶
func SystemTagSetString(s string) (SystemTagSet, error)
SystemTagSetString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.
func SystemTagSetValues ¶
func SystemTagSetValues() []SystemTagSet
SystemTagSetValues returns all values of the enum
func ToSystemTagSet ¶
func ToSystemTagSet(tags []string) *SystemTagSet
ToSystemTagSet converts list of tags to SystemTagSet TODO: emit error instead of discarding invalid values.
func (*SystemTagSet) Has ¶
func (i *SystemTagSet) Has(tag SystemTagSet) bool
Has checks a tag included in tag set.
func (SystemTagSet) IsASystemTagSet ¶
func (i SystemTagSet) IsASystemTagSet() bool
IsASystemTagSet returns "true" if the value is listed in the enum definition. "false" otherwise
func (SystemTagSet) Map ¶
func (i SystemTagSet) Map() EnabledTags
Map returns the EnabledTags with current value from SystemTagSet
func (*SystemTagSet) MarshalJSON ¶
func (i *SystemTagSet) MarshalJSON() ([]byte, error)
MarshalJSON converts the SystemTagSet to a list (JS array).
func (SystemTagSet) SetString ¶
func (i SystemTagSet) SetString() string
SetString returns comma separated list of the string representation of all values in the set
func (SystemTagSet) String ¶
func (i SystemTagSet) String() string
func (*SystemTagSet) UnmarshalJSON ¶
func (i *SystemTagSet) UnmarshalJSON(data []byte) error
UnmarshalJSON converts the tag list back to expected tag set.
func (*SystemTagSet) UnmarshalText ¶
func (i *SystemTagSet) UnmarshalText(data []byte) error
UnmarshalText converts the tag list to SystemTagSet.
type Threshold ¶
type Threshold struct { // Source is the text based source of the threshold Source string // LastFailed is a marker if the last testing of this threshold failed LastFailed bool // AbortOnFail marks if a given threshold fails that the whole test should be aborted AbortOnFail bool // AbortGracePeriod is a the minimum amount of time a test should be running before a failing // this threshold will abort the test AbortGracePeriod types.NullDuration // contains filtered or unexported fields }
Threshold is a representation of a single threshold for a single metric
type Thresholds ¶
type Thresholds struct { Thresholds []*Threshold Abort bool // contains filtered or unexported fields }
Thresholds is the combination of all Thresholds for a given metric
func NewThresholds ¶
func NewThresholds(sources []string) Thresholds
NewThresholds returns Thresholds objects representing the provided source strings
func (Thresholds) MarshalJSON ¶
func (ts Thresholds) MarshalJSON() ([]byte, error)
MarshalJSON is implementation of json.Marshaler
func (*Thresholds) Parse ¶
func (ts *Thresholds) Parse() error
Parse parses the Thresholds and fills each Threshold.parsed field with the result. It effectively asserts they are syntaxically correct.
func (*Thresholds) Run ¶
Run processes all the thresholds with the provided Sink at the provided time and returns if any of them fails
func (*Thresholds) UnmarshalJSON ¶
func (ts *Thresholds) UnmarshalJSON(data []byte) error
UnmarshalJSON is implementation of json.Unmarshaler
func (*Thresholds) Validate ¶
func (ts *Thresholds) Validate(metricName string, r *Registry) error
Validate ensures a threshold definition is consistent with the metric it applies to. Given a metric registry and a metric name to apply the expressions too, Validate will assert that each threshold expression uses an aggregation method that's supported by the provided metric. It returns an error otherwise. Note that this function expects the passed in thresholds to have been parsed already, and have their Parsed (ThresholdExpression) field already filled.
type TrendSink ¶
type TrendSink struct { Values []float64 Count uint64 Min, Max float64 Sum, Avg float64 Med float64 // contains filtered or unexported fields }
type ValueType ¶
type ValueType int
ValueType holds the type of values a metric contains.
func (ValueType) MarshalJSON ¶
MarshalJSON serializes a ValueType to a JSON string.
func (ValueType) MarshalText ¶
MarshalText serializes a ValueType as a human readable string.
func (*ValueType) UnmarshalText ¶
UnmarshalText deserializes a ValueType from a string representation.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package engine contains the internal metrics engine responsible for aggregating metrics during the test and evaluating thresholds against them.
|
Package engine contains the internal metrics engine responsible for aggregating metrics during the test and evaluating thresholds against them. |