[Archived] Thresholds overhaul - the ideal state of thresholds #1441
Labels
evaluation needed
proposal needs to be validated or tested before fully implementing it in k6
refactor
New Threshold specification
Motivation
There are several problems with the current Threshold implementation:
k6 cloud
are parsed and executed in Python. This doesn't work for non-trivial cases.http_req_duration{status:200,status:201}
group_duration{group:::publicCrocodiles}
.Quick overview of the new format
Improvements
The new format will bring the following benefits:
aggregation methods
that are not used. (no need to calculateavg
when threshold only usesmin
)Drawbacks of the new format
Implementation details
backwards compatibility
To provide backwards compatibility, the new k6 thresholds are defined in an array. The old thresholds are using an object {}.
Old:
New
The old format should continue to be supported, but it should raise a WARNING.
Parsing
To provide consistency between local and cloud execution, threshold parsing should happen only in k6.
When the test is executed in the cloud, k6 should parse and provide the agreed-upon format to the k6-cloud backend.
The proposed format is
Filtering
Metrics can be filtered by tags and attributes. In the previous definition of Thresholds, filtered metrics were called "sub-metrics".
I suggest we start calling them "filtered metrics".
Filtering syntax is similar to the threshold syntax
tagname operator value
Example:
Validation
Thresholds should be validated and abort the execution in case of validation errors.
metric_name
validationAll default metrics should be importable from built-in modules. The proposed place is:
The reasoning behind using an import instead of a string is:
http_req_duration
is in factTrend("http_req_duration", true)
;metric_type
validationThe Metric object passed to Threshold, must be of type Rate, Trend, Gauge or Counter. Any other types should raise an appropriate exception and abort the test execution.
filters
validationExample:
Spaces between left-hand, operator and right-hand are allowed but should be stripped away by the parser.
Filters should support only these operators:
==
===
// same as==
. It's supported to make it more js-like.Specifying any other operator should raise an exception and abort the test.
Note, other operators may be added in the future (see the tags section below).
left-hand
should follow the ECMAScript variable-name restrictions - https://mathiasbynens.be/notes/javascript-identifiersor more strict restrictions (left for the implementer to decide).
right-hand-type
can only be a string at the moment. Strings should be quoted by the user, but quotes should be stripped away by the parser.conditions
array validationEach threshold can have multiple conditions. Conditions can't be combined. Each condition must be a separate string.
Invalid
Valid
"conditions" array has a similar restriction as "filters" and should be parsed in a similar way.
aggregation method
validationInvalid aggregation method should raise an exception and abort the test execution.
The
aggregation methods
available for Metric types are specified below.Counter
count
(number of times the.add("whatever")
has been called )sum
(sum of numeric values passed to.add(5)
)rate
(count/s)Gauge
last
min
max
value
(undocumented alias for last)Rate
rate
Trend
min
mean
avg
max
p(N)
Operators
>
>=
<
<=
==
===
!=
!==
tags
Currently, tags support only "strings" as a value type.
In the future,
int
andfloat
may be allowed to facilitate more fine-grained filtering of Thresholds.Example:
Note: This proposal does NOT cover this use case.
The text was updated successfully, but these errors were encountered: