You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix, reorder and simplify threshold instructions (#1147)
- Move instructions to set syntax to top of page
- Move extensive annotation directly to code comments
- Simplify the language and make it more scannable
@@ -23,7 +23,8 @@ Thresholds are also essential for [load-testing automation](/testing-guides/auto
23
23
24
24
After that, you need to worry about the test only after your SUT fails to meet its performance expectations.
25
25
26
-
## Example: Set threshold for HTTP errors and response duration
26
+
## Example: thresholds for HTTP errors and response duration
27
+
27
28
28
29
This sample script specifies two thresholds.
29
30
One threshold evaluates the rate of HTTP errors (`http_req_failed` metric).
@@ -66,8 +67,143 @@ In this case, the test met the criteria for both thresholds.
66
67
k6 considers this test a `pass` and exits with an exit code `0`.
67
68
68
69
If any of the thresholds had failed, the little green checkmark <span style="color:green; font-weight:bold">✓</span> next to the threshold name
69
-
(`http_req_failed`, `http_req_duration`) would have been a red cross <span style="color:red; font-weight:bold">✗</span>,
70
-
and k6 would have generated a non-zero exit code.
70
+
(`http_req_failed`, `http_req_duration`) would be a red cross <span style="color:red; font-weight:bold">✗</span>
71
+
and k6 would exit with a non-zero exit code.
72
+
73
+
## Threshold Syntax
74
+
75
+
To use a threshold, follow these steps:
76
+
77
+
1. In the `thresholds` property of the `options` object, set a key using the name of the metric you want the threshold for:
78
+
```
79
+
export const options = {
80
+
thresholds: {
81
+
...
82
+
}
83
+
```
84
+
2. Define at least one threshold expression. You can do this in two ways:
85
+
- The short format puts all threshold expressions as strings in an array.
86
+
- The long format puts each threshold in an object, with extra properties to [abort on failure](#abort).
87
+
88
+
```
89
+
export const options = {
90
+
thresholds: {
91
+
//short format
92
+
METRIC_NAME: ["THRESHOLD_EXPRESSION", `...`],
93
+
//long format
94
+
METRIC_NAME2: [
95
+
{
96
+
threshold: "THRESHOLD_EXPRESSION",
97
+
abortOnFail: true, // boolean
98
+
delayAbortEval: "10s", // string
99
+
},
100
+
], // full format
101
+
},
102
+
};
103
+
```
104
+
105
+
Note that `METRIC_NAME1` and `THRESHOLD_EXPRESSION` are placeholders.
106
+
The real text must be the name of the metric and the threshold expression.
107
+
108
+
109
+
This declaration configures thresholds for the metrics `metric_name1` and `metric_name2`.
110
+
To determine whether the threshold passes or fails, the script evaluates the `'threshold_expression'.`
111
+
112
+
### Threshold expression syntax
113
+
114
+
A threshold expression evaluates to `true` or `false`.
115
+
The threshold expression must be in the following format:
116
+
117
+
```
118
+
<aggregation_method><operator><value>
119
+
```
120
+
121
+
Some examples of threshold expressions are as follows:
122
+
123
+
- `avg < 200` // average duration must be less than 200ms
124
+
- `count >= 500` // count must be larger than or equal to 500
125
+
- `p(90) < 300` // 90% of samples must be below 300
126
+
127
+
128
+
### Aggregation methods by type
129
+
130
+
Each of the four [metric types](/using-k6/metrics/#metric-types) included in k6 provides a set of aggregation methods that you can use in threshold expressions.
| Trend |`avg`, `min`, `max`, `med` and `p(N)` where `N` specifies the threshold percentile value, expressed as a number between 0.0 and 100. E.g. `p(99.99)` means the 99.99th percentile. The values are in milliseconds. |
138
+
|||
139
+
140
+
This (slightly contrived) sample script uses all different types of metrics,
If you want to set multiple thresholds for a metric, specify them with an [array for the same key](/using-k6/thresholds/#multiple-thresholds-on-a-single-metric).
71
207
72
208
## Threshold examples to copy and paste
73
209
@@ -191,127 +327,7 @@ export default function () {
191
327
</CodeGroup>
192
328
193
329
194
-
## Threshold Syntax
195
-
196
-
To use a threshold, define at least one `threshold_expression`:
metric_name1: ['threshold_expression', `...`], // short format
204
-
metric_name2: [
205
-
{
206
-
threshold: 'threshold_expression',
207
-
abortOnFail: true, // boolean
208
-
delayAbortEval: '10s', // string
209
-
},
210
-
], // full format
211
-
},
212
-
};
213
-
```
214
-
215
-
</CodeGroup>
216
-
217
-
This declaration configures thresholds for the metrics `metric_name1` and `metric_name2`.
218
-
To determine whether the threshold passes or fails, the script evaluates the `'threshold_expression'.`
219
-
220
-
The threshold expression must be in the following format:
221
-
222
-
```
223
-
<aggregation_method><operator><value>
224
-
```
225
-
226
-
For example:
227
-
228
-
- `avg < 200` // average duration must be less than 200ms
229
-
- `count >= 500` // count must be larger than or equal to 500
230
-
- `p(90) < 300` // 90% of samples must be below 300
231
-
232
-
A threshold expression evaluates to `true` or `false`.
233
-
234
-
Each of the four [metric types](/using-k6/metrics/#metric-types) included in k6 provides a set of aggregation methods that you can use in threshold expressions.
| Trend |`avg`, `min`, `max`, `med` and `p(N)` where `N` is a number between 0.0 and 100.0 meaning the percentile value to look at, e.g. `p(99.99)` means the 99.99th percentile. The unit for these values is milliseconds. |
242
-
243
-
This (slightly contrived) sample script uses all different types of metrics,
0 commit comments