@assertrx/dino 1.0.10 → 1.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/prompts/generate-k6-test-from-endpoint.md +68 -0
- package/prompts/generate-k6-test-from-openapi.md +85 -0
- package/prompts/setup-k6.md +130 -0
- package/scripts/api-server.mjs +23 -0
- package/skills/analyzing-test-results/SKILL.md +150 -0
- package/skills/analyzing-test-results/reference/bottleneck-patterns.md +130 -0
- package/skills/analyzing-test-results/reference/metrics.md +134 -0
- package/skills/analyzing-test-results/reference/visualization.md +152 -0
- package/skills/designing-test-scenarios/SKILL.md +247 -0
- package/skills/designing-test-scenarios/reference/executors.md +215 -0
- package/skills/designing-test-scenarios/reference/test-types.md +215 -0
- package/skills/designing-test-scenarios/reference/thresholds.md +208 -0
- package/skills/generating-api-load-tests/SKILL.md +199 -0
- package/skills/generating-api-load-tests/reference/data-parameterization.md +343 -0
- package/skills/generating-api-load-tests/reference/grpc.md +315 -0
- package/skills/generating-api-load-tests/reference/http.md +380 -0
- package/skills/generating-api-load-tests/reference/websocket.md +369 -0
- package/skills/generating-browser-tests/SKILL.md +269 -0
- package/skills/generating-browser-tests/reference/browser-api.md +251 -0
- package/skills/generating-browser-tests/reference/web-vitals.md +148 -0
- package/skills/generating-tests-from-code/SKILL.md +142 -0
- package/skills/generating-tests-from-code/reference/auth-analysis.md +220 -0
- package/skills/generating-tests-from-code/reference/framework-patterns.md +242 -0
- package/skills/generating-tests-from-openapi/SKILL.md +234 -0
- package/skills/generating-tests-from-openapi/reference/openapi-auth-mapping.md +247 -0
- package/skills/generating-tests-from-openapi/reference/openapi-parsing.md +194 -0
- package/skills/operating-k6-in-ci-cd/SKILL.md +98 -0
- package/skills/operating-k6-in-ci-cd/reference/ci-cd-pipelines.md +265 -0
- package/skills/operating-k6-in-ci-cd/reference/extensions.md +144 -0
- package/skills/operating-k6-in-ci-cd/reference/k6-operator.md +214 -0
- package/skills/testing-resilience/SKILL.md +230 -0
- package/skills/testing-resilience/reference/fault-injection.md +153 -0
- package/skills/testing-resilience/reference/resilience-patterns.md +500 -0
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
# k6 Executors Reference
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
k6 provides 6 executor types organized into two models:
|
|
6
|
+
|
|
7
|
+
**Closed Model** (VU-based): Iteration rate depends on system response time
|
|
8
|
+
- `shared-iterations`, `per-vu-iterations`, `constant-vus`, `ramping-vus`
|
|
9
|
+
|
|
10
|
+
**Open Model** (arrival-rate): Iteration rate is fixed regardless of response time
|
|
11
|
+
- `constant-arrival-rate`, `ramping-arrival-rate`
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## shared-iterations
|
|
16
|
+
|
|
17
|
+
A fixed total number of iterations shared between VUs. Test ends when all iterations complete.
|
|
18
|
+
|
|
19
|
+
| Parameter | Type | Default | Description |
|
|
20
|
+
|-----------|------|---------|-------------|
|
|
21
|
+
| `vus` | integer | 1 | Number of VUs to run concurrently |
|
|
22
|
+
| `iterations` | integer | 1 | Total iterations across all VUs |
|
|
23
|
+
| `maxDuration` | string | `"10m"` | Max scenario duration |
|
|
24
|
+
|
|
25
|
+
**Distribution is NOT guaranteed even.** Faster VUs execute more iterations.
|
|
26
|
+
|
|
27
|
+
```javascript
|
|
28
|
+
export const options = {
|
|
29
|
+
scenarios: {
|
|
30
|
+
quick_test: {
|
|
31
|
+
executor: 'shared-iterations',
|
|
32
|
+
vus: 10,
|
|
33
|
+
iterations: 200,
|
|
34
|
+
maxDuration: '30s',
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
**Use when:** You need a fixed total iteration count and don't care about even distribution.
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
## per-vu-iterations
|
|
45
|
+
|
|
46
|
+
Each VU executes an exact number of iterations. Total = VUs x iterations.
|
|
47
|
+
|
|
48
|
+
| Parameter | Type | Default | Description |
|
|
49
|
+
|-----------|------|---------|-------------|
|
|
50
|
+
| `vus` | integer | 1 | Number of VUs to run concurrently |
|
|
51
|
+
| `iterations` | integer | 1 | Iterations per VU |
|
|
52
|
+
| `maxDuration` | string | `"10m"` | Max scenario duration |
|
|
53
|
+
|
|
54
|
+
```javascript
|
|
55
|
+
export const options = {
|
|
56
|
+
scenarios: {
|
|
57
|
+
even_distribution: {
|
|
58
|
+
executor: 'per-vu-iterations',
|
|
59
|
+
vus: 10,
|
|
60
|
+
iterations: 20, // Each VU does exactly 20 iterations (200 total)
|
|
61
|
+
maxDuration: '1m',
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
**Use when:** Each VU needs a guaranteed number of iterations (e.g., partitioned test data).
|
|
68
|
+
|
|
69
|
+
---
|
|
70
|
+
|
|
71
|
+
## constant-vus
|
|
72
|
+
|
|
73
|
+
Fixed VU count runs for a set duration. VUs execute as many iterations as possible.
|
|
74
|
+
|
|
75
|
+
| Parameter | Type | Default | Description |
|
|
76
|
+
|-----------|------|---------|-------------|
|
|
77
|
+
| `duration` | string | required | Scenario duration |
|
|
78
|
+
| `vus` | integer | 1 | Number of concurrent VUs |
|
|
79
|
+
|
|
80
|
+
```javascript
|
|
81
|
+
export const options = {
|
|
82
|
+
scenarios: {
|
|
83
|
+
constant_load: {
|
|
84
|
+
executor: 'constant-vus',
|
|
85
|
+
vus: 50,
|
|
86
|
+
duration: '5m',
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
**Use when:** Simple constant load for a fixed duration.
|
|
93
|
+
|
|
94
|
+
---
|
|
95
|
+
|
|
96
|
+
## ramping-vus
|
|
97
|
+
|
|
98
|
+
VU count changes over time via stages. VUs execute as many iterations as possible.
|
|
99
|
+
|
|
100
|
+
| Parameter | Type | Default | Description |
|
|
101
|
+
|-----------|------|---------|-------------|
|
|
102
|
+
| `stages` | array | required | Array of `{ duration, target }` objects |
|
|
103
|
+
| `startVUs` | integer | 1 | Initial VU count |
|
|
104
|
+
| `gracefulRampDown` | string | `"30s"` | Wait time during ramp-down |
|
|
105
|
+
|
|
106
|
+
```javascript
|
|
107
|
+
export const options = {
|
|
108
|
+
scenarios: {
|
|
109
|
+
ramping_load: {
|
|
110
|
+
executor: 'ramping-vus',
|
|
111
|
+
startVUs: 0,
|
|
112
|
+
stages: [
|
|
113
|
+
{ duration: '5m', target: 100 }, // Ramp up to 100
|
|
114
|
+
{ duration: '30m', target: 100 }, // Stay at 100
|
|
115
|
+
{ duration: '5m', target: 0 }, // Ramp down to 0
|
|
116
|
+
],
|
|
117
|
+
gracefulRampDown: '30s',
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
};
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
**Stage behavior:** VU count transitions linearly from previous target to current target over the stage duration.
|
|
124
|
+
|
|
125
|
+
**Use when:** Load tests with ramp-up/ramp-down phases (load, stress, soak, spike tests).
|
|
126
|
+
|
|
127
|
+
---
|
|
128
|
+
|
|
129
|
+
## constant-arrival-rate
|
|
130
|
+
|
|
131
|
+
Fixed iteration rate independent of system response time (open model).
|
|
132
|
+
|
|
133
|
+
| Parameter | Type | Default | Description |
|
|
134
|
+
|-----------|------|---------|-------------|
|
|
135
|
+
| `duration` | string | required | Scenario duration |
|
|
136
|
+
| `rate` | integer | required | Iterations per `timeUnit` |
|
|
137
|
+
| `timeUnit` | string | `"1s"` | Time period for rate |
|
|
138
|
+
| `preAllocatedVUs` | integer | required | VUs pre-allocated before start |
|
|
139
|
+
| `maxVUs` | integer | preAllocatedVUs | Maximum VU count |
|
|
140
|
+
|
|
141
|
+
**Important:** Iterations start at evenly spaced intervals. At `rate: 10, timeUnit: '1s'`, one iteration starts every 100ms.
|
|
142
|
+
|
|
143
|
+
**Do NOT use `sleep()` at end of iteration** — pacing is handled by rate/timeUnit.
|
|
144
|
+
|
|
145
|
+
```javascript
|
|
146
|
+
export const options = {
|
|
147
|
+
scenarios: {
|
|
148
|
+
constant_rps: {
|
|
149
|
+
executor: 'constant-arrival-rate',
|
|
150
|
+
rate: 50, // 50 iterations per second
|
|
151
|
+
timeUnit: '1s',
|
|
152
|
+
duration: '5m',
|
|
153
|
+
preAllocatedVUs: 20, // Start with 20 VUs
|
|
154
|
+
maxVUs: 100, // Scale up to 100 if needed
|
|
155
|
+
},
|
|
156
|
+
},
|
|
157
|
+
};
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
**Use when:** You need a guaranteed request rate (RPS), regardless of system performance. Preferred for realistic load testing.
|
|
161
|
+
|
|
162
|
+
**Tuning preAllocatedVUs:** If too low, k6 spends time allocating VUs and may not hit target rate initially. Set to expected concurrent VU count based on `rate × average_iteration_duration`.
|
|
163
|
+
|
|
164
|
+
---
|
|
165
|
+
|
|
166
|
+
## ramping-arrival-rate
|
|
167
|
+
|
|
168
|
+
Variable iteration rate over time via stages (open model).
|
|
169
|
+
|
|
170
|
+
| Parameter | Type | Default | Description |
|
|
171
|
+
|-----------|------|---------|-------------|
|
|
172
|
+
| `stages` | array | required | Array of `{ duration, target }` objects |
|
|
173
|
+
| `startRate` | integer | 0 | Initial iteration rate per `timeUnit` |
|
|
174
|
+
| `timeUnit` | string | `"1s"` | Time period for rate (constant for entire scenario) |
|
|
175
|
+
| `preAllocatedVUs` | integer | required | VUs pre-allocated before start |
|
|
176
|
+
| `maxVUs` | integer | preAllocatedVUs | Maximum VU count |
|
|
177
|
+
|
|
178
|
+
**Do NOT use `sleep()` at end of iteration.**
|
|
179
|
+
|
|
180
|
+
```javascript
|
|
181
|
+
export const options = {
|
|
182
|
+
scenarios: {
|
|
183
|
+
ramping_rps: {
|
|
184
|
+
executor: 'ramping-arrival-rate',
|
|
185
|
+
startRate: 10,
|
|
186
|
+
timeUnit: '1s',
|
|
187
|
+
preAllocatedVUs: 50,
|
|
188
|
+
maxVUs: 200,
|
|
189
|
+
stages: [
|
|
190
|
+
{ duration: '2m', target: 10 }, // Stay at 10 RPS
|
|
191
|
+
{ duration: '5m', target: 100 }, // Ramp to 100 RPS
|
|
192
|
+
{ duration: '5m', target: 100 }, // Stay at 100 RPS
|
|
193
|
+
{ duration: '2m', target: 0 }, // Ramp down to 0
|
|
194
|
+
],
|
|
195
|
+
},
|
|
196
|
+
},
|
|
197
|
+
};
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
**Use when:** Ramp request rate up/down over time. Ideal for breakpoint tests (finding system limits) and realistic traffic simulation.
|
|
201
|
+
|
|
202
|
+
---
|
|
203
|
+
|
|
204
|
+
## Executor Selection Quick Reference
|
|
205
|
+
|
|
206
|
+
| Scenario | Recommended Executor |
|
|
207
|
+
|----------|---------------------|
|
|
208
|
+
| Quick smoke test | `shared-iterations` (low vus, few iterations) |
|
|
209
|
+
| Each VU tests different data | `per-vu-iterations` |
|
|
210
|
+
| Simple constant load | `constant-vus` |
|
|
211
|
+
| Load/stress/soak with ramp | `ramping-vus` |
|
|
212
|
+
| Maintain exact RPS | `constant-arrival-rate` |
|
|
213
|
+
| Ramp RPS up/down | `ramping-arrival-rate` |
|
|
214
|
+
| Breakpoint (find limits) | `ramping-arrival-rate` |
|
|
215
|
+
| Spike test | `ramping-vus` (fast ramp) or `ramping-arrival-rate` |
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
# k6 Test Types Reference
|
|
2
|
+
|
|
3
|
+
## Summary
|
|
4
|
+
|
|
5
|
+
| Test Type | VUs | Duration | Purpose |
|
|
6
|
+
|-----------|-----|----------|---------|
|
|
7
|
+
| Smoke | 2-5 | 30s-3m | Verify script works, baseline metrics |
|
|
8
|
+
| Load | Average production | 5-60min | Typical load performance |
|
|
9
|
+
| Stress | 50-100%+ above avg | 10-60min | Heavy load behavior |
|
|
10
|
+
| Soak | Average production | 3-72 hours | Long-running reliability |
|
|
11
|
+
| Spike | Very high, sudden | 2-5min | Sudden traffic burst |
|
|
12
|
+
| Breakpoint | Incremental | Until failure | Find system limits |
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## Smoke Test
|
|
17
|
+
|
|
18
|
+
Minimal load to verify the script works and establish baseline metrics.
|
|
19
|
+
|
|
20
|
+
```javascript
|
|
21
|
+
export const options = {
|
|
22
|
+
vus: 3,
|
|
23
|
+
duration: '1m',
|
|
24
|
+
thresholds: {
|
|
25
|
+
http_req_failed: ['rate<0.01'],
|
|
26
|
+
http_req_duration: ['p(95)<500'],
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
**When to run:** After every script change. Before any other test type.
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
## Load Test (Average Load)
|
|
36
|
+
|
|
37
|
+
Assess performance under typical production load.
|
|
38
|
+
|
|
39
|
+
**Stage pattern:** Ramp-up (5-15% of total) → Plateau (5x ramp-up) → Ramp-down
|
|
40
|
+
|
|
41
|
+
```javascript
|
|
42
|
+
export const options = {
|
|
43
|
+
stages: [
|
|
44
|
+
{ duration: '5m', target: 100 }, // Ramp up
|
|
45
|
+
{ duration: '30m', target: 100 }, // Plateau
|
|
46
|
+
{ duration: '5m', target: 0 }, // Ramp down
|
|
47
|
+
],
|
|
48
|
+
thresholds: {
|
|
49
|
+
http_req_duration: ['p(95)<500'],
|
|
50
|
+
http_req_failed: ['rate<0.01'],
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
**When to run:** Regularly after code changes. Foundation for all other test types.
|
|
56
|
+
|
|
57
|
+
**What to look for:**
|
|
58
|
+
- Compare response times during ramp-up vs full load
|
|
59
|
+
- Response time stability during plateau
|
|
60
|
+
- Error rate trends
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
## Stress Test
|
|
65
|
+
|
|
66
|
+
Assess performance under heavier-than-normal load (50-100%+ above average).
|
|
67
|
+
|
|
68
|
+
```javascript
|
|
69
|
+
export const options = {
|
|
70
|
+
stages: [
|
|
71
|
+
{ duration: '10m', target: 200 }, // Ramp up to 2x normal
|
|
72
|
+
{ duration: '30m', target: 200 }, // Sustained heavy load
|
|
73
|
+
{ duration: '5m', target: 0 }, // Ramp down
|
|
74
|
+
],
|
|
75
|
+
thresholds: {
|
|
76
|
+
http_req_duration: ['p(95)<1000'],
|
|
77
|
+
http_req_failed: ['rate<0.05'],
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
**When to run:** After successful load tests. Before anticipated high-traffic events.
|
|
83
|
+
|
|
84
|
+
**What to look for:**
|
|
85
|
+
- Performance degradation rate
|
|
86
|
+
- Error rate increase patterns
|
|
87
|
+
- Recovery behavior during ramp-down
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
## Soak Test
|
|
92
|
+
|
|
93
|
+
Test reliability and performance over extended periods. Same load as load test but much longer duration.
|
|
94
|
+
|
|
95
|
+
```javascript
|
|
96
|
+
export const options = {
|
|
97
|
+
stages: [
|
|
98
|
+
{ duration: '5m', target: 100 }, // Ramp up
|
|
99
|
+
{ duration: '8h', target: 100 }, // Extended plateau (hours!)
|
|
100
|
+
{ duration: '5m', target: 0 }, // Ramp down
|
|
101
|
+
],
|
|
102
|
+
thresholds: {
|
|
103
|
+
http_req_duration: ['p(95)<500'],
|
|
104
|
+
http_req_failed: ['rate<0.01'],
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
**When to run:** After successful load and stress tests. Before production deployments.
|
|
110
|
+
|
|
111
|
+
**What to look for:**
|
|
112
|
+
- Memory leaks (gradual increase in response times)
|
|
113
|
+
- Database connection pool exhaustion
|
|
114
|
+
- Log/storage growth issues
|
|
115
|
+
- Gradual metric degradation over time
|
|
116
|
+
|
|
117
|
+
---
|
|
118
|
+
|
|
119
|
+
## Spike Test
|
|
120
|
+
|
|
121
|
+
Verify system survives sudden, massive traffic bursts.
|
|
122
|
+
|
|
123
|
+
```javascript
|
|
124
|
+
export const options = {
|
|
125
|
+
stages: [
|
|
126
|
+
{ duration: '2m', target: 2000 }, // Fast ramp to extreme load
|
|
127
|
+
{ duration: '1m', target: 0 }, // Quick ramp down
|
|
128
|
+
],
|
|
129
|
+
};
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
**Alternative — multiple spikes:**
|
|
133
|
+
|
|
134
|
+
```javascript
|
|
135
|
+
export const options = {
|
|
136
|
+
stages: [
|
|
137
|
+
{ duration: '1m', target: 100 }, // Normal load
|
|
138
|
+
{ duration: '30s', target: 1500 }, // Spike 1
|
|
139
|
+
{ duration: '30s', target: 100 }, // Recovery
|
|
140
|
+
{ duration: '30s', target: 1500 }, // Spike 2
|
|
141
|
+
{ duration: '1m', target: 0 }, // Ramp down
|
|
142
|
+
],
|
|
143
|
+
};
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
**When to run:** For systems expecting sudden traffic (sales events, broadcasts, deadlines).
|
|
147
|
+
|
|
148
|
+
**What to look for:**
|
|
149
|
+
- System survival (does it crash?)
|
|
150
|
+
- Auto-scaling response time
|
|
151
|
+
- Recovery time after spike
|
|
152
|
+
- Error patterns during peak
|
|
153
|
+
|
|
154
|
+
---
|
|
155
|
+
|
|
156
|
+
## Breakpoint Test
|
|
157
|
+
|
|
158
|
+
Find system capacity limits by continuously increasing load until failure.
|
|
159
|
+
|
|
160
|
+
**Recommended executor:** `ramping-arrival-rate` (maintains throughput despite degradation)
|
|
161
|
+
|
|
162
|
+
```javascript
|
|
163
|
+
export const options = {
|
|
164
|
+
scenarios: {
|
|
165
|
+
breakpoint: {
|
|
166
|
+
executor: 'ramping-arrival-rate',
|
|
167
|
+
preAllocatedVUs: 100,
|
|
168
|
+
maxVUs: 2000,
|
|
169
|
+
stages: [
|
|
170
|
+
{ duration: '2h', target: 20000 }, // Slow continuous ramp
|
|
171
|
+
],
|
|
172
|
+
},
|
|
173
|
+
},
|
|
174
|
+
thresholds: {
|
|
175
|
+
http_req_failed: [{
|
|
176
|
+
threshold: 'rate>0.1',
|
|
177
|
+
abortOnFail: true,
|
|
178
|
+
delayAbortEval: '1m',
|
|
179
|
+
}],
|
|
180
|
+
},
|
|
181
|
+
};
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
**When to run:** To discover system capacity limits. After tuning system to verify new limits.
|
|
185
|
+
|
|
186
|
+
**What to look for (progressive failure stages):**
|
|
187
|
+
1. Degraded performance → response times increase
|
|
188
|
+
2. Troublesome → severe user experience degradation
|
|
189
|
+
3. Timeouts → requests start timing out
|
|
190
|
+
4. Errors → HTTP error codes appear
|
|
191
|
+
5. System failure → complete collapse
|
|
192
|
+
|
|
193
|
+
**Warning:** Avoid in elastic cloud environments without disabling auto-scaling, or you may only discover your cloud bill limit.
|
|
194
|
+
|
|
195
|
+
---
|
|
196
|
+
|
|
197
|
+
## Test Type Decision Guide
|
|
198
|
+
|
|
199
|
+
```
|
|
200
|
+
What do you want to learn?
|
|
201
|
+
│
|
|
202
|
+
├─ "Does my script work?" → Smoke Test
|
|
203
|
+
│
|
|
204
|
+
├─ "How does it perform normally?" → Load Test
|
|
205
|
+
│
|
|
206
|
+
├─ "Can it handle peak traffic?" → Stress Test
|
|
207
|
+
│
|
|
208
|
+
├─ "Is it reliable over time?" → Soak Test
|
|
209
|
+
│
|
|
210
|
+
├─ "Can it survive sudden bursts?" → Spike Test
|
|
211
|
+
│
|
|
212
|
+
└─ "Where does it break?" → Breakpoint Test
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
**Recommended progression:** Smoke → Load → Stress → Soak → Spike → Breakpoint
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
# k6 Thresholds Reference
|
|
2
|
+
|
|
3
|
+
## Defining Thresholds
|
|
4
|
+
|
|
5
|
+
### Short Format (Array of Strings)
|
|
6
|
+
|
|
7
|
+
```javascript
|
|
8
|
+
export const options = {
|
|
9
|
+
thresholds: {
|
|
10
|
+
http_req_duration: ['p(95)<500', 'p(99)<1000'],
|
|
11
|
+
http_req_failed: ['rate<0.01'],
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
### Long Format (With Abort Control)
|
|
17
|
+
|
|
18
|
+
```javascript
|
|
19
|
+
export const options = {
|
|
20
|
+
thresholds: {
|
|
21
|
+
http_req_duration: [{
|
|
22
|
+
threshold: 'p(99)<1000',
|
|
23
|
+
abortOnFail: true,
|
|
24
|
+
delayAbortEval: '30s',
|
|
25
|
+
}],
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
| Field | Type | Description |
|
|
31
|
+
|-------|------|-------------|
|
|
32
|
+
| `threshold` | string | Threshold expression |
|
|
33
|
+
| `abortOnFail` | boolean | Stop test if threshold fails |
|
|
34
|
+
| `delayAbortEval` | string | Wait before evaluating abort (e.g., `"10s"`) |
|
|
35
|
+
|
|
36
|
+
## Threshold Expression Syntax
|
|
37
|
+
|
|
38
|
+
```
|
|
39
|
+
<aggregation_method> <operator> <value>
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
**Operators:** `<`, `<=`, `>`, `>=`, `==`, `!=`
|
|
43
|
+
|
|
44
|
+
## Aggregation Methods by Metric Type
|
|
45
|
+
|
|
46
|
+
| Metric Type | Methods | Example Metrics |
|
|
47
|
+
|-------------|---------|-----------------|
|
|
48
|
+
| **Counter** | `count`, `rate` | `http_reqs`, `data_received` |
|
|
49
|
+
| **Gauge** | `value` | `vus`, `vus_max` |
|
|
50
|
+
| **Rate** | `rate` | `http_req_failed`, `checks` |
|
|
51
|
+
| **Trend** | `avg`, `min`, `max`, `med`, `p(N)` | `http_req_duration`, `iteration_duration` |
|
|
52
|
+
|
|
53
|
+
**Percentile syntax:** `p(N)` where N is 0.0 to 100 (e.g., `p(90)`, `p(95)`, `p(99)`, `p(99.9)`)
|
|
54
|
+
|
|
55
|
+
## Common Threshold Patterns
|
|
56
|
+
|
|
57
|
+
### Response Time
|
|
58
|
+
|
|
59
|
+
```javascript
|
|
60
|
+
thresholds: {
|
|
61
|
+
http_req_duration: [
|
|
62
|
+
'p(50)<200', // Median under 200ms
|
|
63
|
+
'p(90)<400', // 90th percentile under 400ms
|
|
64
|
+
'p(95)<500', // 95th percentile under 500ms
|
|
65
|
+
'p(99)<1000', // 99th percentile under 1s
|
|
66
|
+
'avg<300', // Average under 300ms
|
|
67
|
+
'max<3000', // Max under 3s
|
|
68
|
+
],
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Error Rate
|
|
73
|
+
|
|
74
|
+
```javascript
|
|
75
|
+
thresholds: {
|
|
76
|
+
http_req_failed: ['rate<0.01'], // Less than 1% errors
|
|
77
|
+
checks: ['rate>0.99'], // 99% of checks pass
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Throughput
|
|
82
|
+
|
|
83
|
+
```javascript
|
|
84
|
+
thresholds: {
|
|
85
|
+
http_reqs: ['rate>100'], // At least 100 RPS
|
|
86
|
+
http_reqs: ['count>10000'], // At least 10000 total requests
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Custom Metrics
|
|
91
|
+
|
|
92
|
+
```javascript
|
|
93
|
+
import { Trend, Rate, Counter, Gauge } from 'k6/metrics';
|
|
94
|
+
|
|
95
|
+
const apiLatency = new Trend('api_latency');
|
|
96
|
+
const successRate = new Rate('success_rate');
|
|
97
|
+
const errorCount = new Counter('error_count');
|
|
98
|
+
const queueSize = new Gauge('queue_size');
|
|
99
|
+
|
|
100
|
+
export const options = {
|
|
101
|
+
thresholds: {
|
|
102
|
+
api_latency: ['p(95)<500', 'avg<200'], // Trend
|
|
103
|
+
success_rate: ['rate>0.95'], // Rate
|
|
104
|
+
error_count: ['count<100'], // Counter
|
|
105
|
+
queue_size: ['value<1000'], // Gauge
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Tag-Based Thresholds
|
|
111
|
+
|
|
112
|
+
Apply different thresholds to different request groups:
|
|
113
|
+
|
|
114
|
+
```javascript
|
|
115
|
+
export const options = {
|
|
116
|
+
thresholds: {
|
|
117
|
+
// Global threshold
|
|
118
|
+
http_req_duration: ['p(95)<500'],
|
|
119
|
+
// Per-endpoint thresholds
|
|
120
|
+
'http_req_duration{name:GetUsers}': ['p(95)<300'],
|
|
121
|
+
'http_req_duration{name:CreateOrder}': ['p(95)<800'],
|
|
122
|
+
'http_req_duration{name:UploadFile}': ['p(95)<2000'],
|
|
123
|
+
// Per-type thresholds
|
|
124
|
+
'http_req_duration{type:api}': ['p(95)<500'],
|
|
125
|
+
'http_req_duration{type:static}': ['p(95)<100'],
|
|
126
|
+
},
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
export default function () {
|
|
130
|
+
http.get('https://api.example.com/users', {
|
|
131
|
+
tags: { name: 'GetUsers', type: 'api' },
|
|
132
|
+
});
|
|
133
|
+
http.post('https://api.example.com/orders', payload, {
|
|
134
|
+
tags: { name: 'CreateOrder', type: 'api' },
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### Group Duration Thresholds
|
|
140
|
+
|
|
141
|
+
```javascript
|
|
142
|
+
export const options = {
|
|
143
|
+
thresholds: {
|
|
144
|
+
'group_duration{group:::login_flow}': ['avg<3000'],
|
|
145
|
+
'group_duration{group:::checkout}': ['avg<5000'],
|
|
146
|
+
},
|
|
147
|
+
};
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
Note: Group names in threshold tags use `:::` as separator.
|
|
151
|
+
|
|
152
|
+
## Combining Checks with Thresholds
|
|
153
|
+
|
|
154
|
+
Checks alone do NOT affect test exit status. Use thresholds on check rate:
|
|
155
|
+
|
|
156
|
+
```javascript
|
|
157
|
+
export const options = {
|
|
158
|
+
thresholds: {
|
|
159
|
+
checks: ['rate>0.99'], // All checks combined
|
|
160
|
+
'checks{myTag:critical}': ['rate>0.999'], // Tagged checks
|
|
161
|
+
},
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
export default function () {
|
|
165
|
+
const res = http.get(url);
|
|
166
|
+
|
|
167
|
+
// Regular check
|
|
168
|
+
check(res, { 'status 200': (r) => r.status === 200 });
|
|
169
|
+
|
|
170
|
+
// Tagged check (higher threshold)
|
|
171
|
+
check(res,
|
|
172
|
+
{ 'body valid': (r) => r.body.includes('expected') },
|
|
173
|
+
{ myTag: 'critical' }
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
## Typical SLA Thresholds
|
|
179
|
+
|
|
180
|
+
### Web Application
|
|
181
|
+
|
|
182
|
+
```javascript
|
|
183
|
+
thresholds: {
|
|
184
|
+
http_req_duration: ['p(95)<500', 'p(99)<1500'],
|
|
185
|
+
http_req_failed: ['rate<0.01'],
|
|
186
|
+
checks: ['rate>0.99'],
|
|
187
|
+
}
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
### API Service
|
|
191
|
+
|
|
192
|
+
```javascript
|
|
193
|
+
thresholds: {
|
|
194
|
+
http_req_duration: ['p(95)<200', 'p(99)<500'],
|
|
195
|
+
http_req_failed: ['rate<0.001'],
|
|
196
|
+
http_reqs: ['rate>500'],
|
|
197
|
+
}
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
### Real-Time Application
|
|
201
|
+
|
|
202
|
+
```javascript
|
|
203
|
+
thresholds: {
|
|
204
|
+
http_req_duration: ['p(99)<100'],
|
|
205
|
+
http_req_failed: ['rate<0.0001'],
|
|
206
|
+
ws_session_duration: ['p(95)<30000'],
|
|
207
|
+
}
|
|
208
|
+
```
|