Skip to content

Commit 35c325b

Browse files
authored
Merge branch 'main' into patch-1
2 parents 1a2d313 + 947c92e commit 35c325b

File tree

7 files changed

+103
-87
lines changed

7 files changed

+103
-87
lines changed

CONTRIBUTING/README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,23 +43,28 @@ If you don't want to build with Docker (refer to repo README), you'll need the f
4343

4444
To build locally:
4545

46-
1. Clone the project
46+
1. Clone the project.
47+
4748
```bash
4849
git clone [email protected]:grafana/k6-docs.git
4950
cd k6-docs
50-
npm install # or yarn install
5151
```
52+
5253
2. Use the version manager to install a version of node compatible with the version in `package.json`.
54+
5355
```bash
5456
nvm install 16.16
5557
nvm use 16.16
5658
```
59+
5760
3. Install dependencies (only necessary the first time).
61+
5862
```bash
5963
npm install # or yarn install
6064
```
6165

62-
4. Run the docs locally:
66+
4. Run the docs locally.
67+
6368
```bash
6469
npm start # or yarn start
6570
```

src/components/shared/seo/seo.view.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ export const SEO = ({
1818
facebook,
1919
pageTranslations = null,
2020
pageVersions = null,
21-
version = LATEST_VERSION,
2221
} = {}) => {
2322
const {
2423
site: {
@@ -49,11 +48,6 @@ export const SEO = ({
4948
const currentUrl = slug && slug !== '*' ? getPageHref(docs, slug) : docs;
5049
const currentRobotsContent = useRef('index, follow');
5150
let versionedCanonicalUrl = currentUrl;
52-
let currentLanguage = 'en';
53-
54-
if ((slug && slug.startsWith('es/')) || (slug && slug.startsWith('/es/'))) {
55-
currentLanguage = 'es';
56-
}
5751

5852
// set canonical path to latest version URL if it's available
5953
if (pageVersions && typeof pageVersions[LATEST_VERSION] !== 'undefined') {
@@ -125,8 +119,7 @@ export const SEO = ({
125119
<meta name={'twitter:card'} content={'summary'} />
126120
<meta name={'twitter:creator'} content={authorTwitterAccount} />
127121

128-
<meta name="docsearch:language" content={currentLanguage} />
129-
<meta name="docsearch:version" content={version} />
122+
<meta name="category" content="Documentation" />
130123

131124
{/* Canonical links for versioned pages */}
132125
<link href={versionedCanonicalUrl} rel="canonical" />

src/data/markdown/docs/05 Examples/02 Tutorials/01 Get started with k6/100 Test-for-functional-behavior.md

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,23 @@ After the test finishes, k6 reports the [default result summary](/results-output
6666
...
6767
```
6868
69-
To make sure you're getting the right response, you could log the response body to the console as follows:
69+
As an optional step, you can log the response body to the console to make sure you're getting the right response.
70+
71+
<CodeGroup labels={["api-test.js"]} lineNumbers={[]} showCopyButton={[true]}>
7072
7173
```javascript
72-
const res = http.post(url, payload, params);
73-
console.log(res.body);
74+
export default function () {
75+
...
76+
77+
const res = http.post(url, payload, params);
78+
79+
// Log the request body
80+
console.log(res.body);
81+
}
7482
```
7583
84+
</CodeGroup>
85+
7686
## Add response checks
7787
7888
Once you're sure the request is well-formed, add a [check](/using-k6/checks) that validates whether the system responds with the expected status code.
@@ -111,6 +121,12 @@ Once you're sure the request is well-formed, add a [check](/using-k6/checks) tha
111121
112122
</CodeGroup>
113123
124+
1. Run the script again.
125+
126+
```bash
127+
k6 run api-test.js
128+
```
129+
114130
1. Inspect the result output for your check.
115131
It should look something like this.
116132

src/data/markdown/docs/05 Examples/02 Tutorials/01 Get started with k6/200 Test for performance.md

Lines changed: 44 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ In this tutorial, learn how to:
1111
- Use [thresholds](/using-k6/thresholds) to assert for performance criteria
1212
- Configure load increases through [scenarios](/using-k6/scenarios)
1313

14-
These examples build on the script from the previous section.
14+
These examples build on the script from the [previous section](/examples/tutorials/get-started-with-k6/test-for-functional-behavior/).
1515

1616
## Context: meet service-level objectives
1717

@@ -24,33 +24,34 @@ The service must meet these SLOs under different types of usual traffic.
2424
## Assert for performance with thresholds
2525

2626
To codify the SLOs, add [_thresholds_](/using-k6/thresholds) to test that your system performs to its goal criteria.
27-
Thresholds are set in options.
27+
28+
Thresholds are set in the [`options`](/using-k6/k6-options/) object.
2829

2930

3031
```javascript
3132
export const options = {
32-
//define thresholds
33+
// define thresholds
3334
thresholds: {
3435
http_req_failed: ['rate<0.01'], // http errors should be less than 1%
3536
http_req_duration: ['p(99)<1000'], // 99% of requests should be below 1s
3637
},
3738
};
3839
```
3940

40-
Add this [`options`](/using-k6/k6-options/) object with thresholds to your script `api-test.js`.
41+
Add this `options` object with thresholds to your script `api-test.js`.
4142

4243

4344
<CodeGroup labels={["api-test.js"]} lineNumbers={[true]} showCopyButton={[true]}
4445
heightTogglers={[true]}>
4546

4647
```javascript
47-
// Import necessary modules
48+
// import necessary modules
4849
import { check } from "k6";
4950
import http from "k6/http";
5051

51-
//define configuration
52+
// define configuration
5253
export const options = {
53-
//define thresholds
54+
// define thresholds
5455
thresholds: {
5556
http_req_failed: ['rate<0.01'], // http errors should be less than 1%
5657
http_req_duration: ["p(99)<1000"], // 99% of requests should be below 1s
@@ -75,21 +76,20 @@ export default function () {
7576

7677
// check that response is 200
7778
check(res, {
78-
"login response was 200": (res) => res.status == 200,
79+
"response code was 200": (res) => res.status == 200,
7980
});
8081
}
8182

8283
```
8384

8485
</CodeGroup>
8586

86-
Run the test as usual:
87+
Run the test.
8788

8889
```bash
8990
k6 run api-test.js
9091
```
9192

92-
9393
Inspect the console output to determine whether performance crossed a threshold.
9494

9595
```
@@ -98,7 +98,7 @@ Inspect the console output to determine whether performance crossed a threshold.
9898
✗ http_req_failed................: 0.00% ✓ 0 ✗ 1
9999
```
100100

101-
101+
The ✓ and ✗ symbols indicate whether the performance thresholds passed or failed.
102102

103103
## Test performance under increasing load
104104

@@ -110,7 +110,7 @@ Scenarios schedule load according to the number of VUs, number of iterations, VU
110110

111111
### Run a smoke test
112112

113-
Start small. Run a [smoke test](/test-types/smoke-testing "a small test to confirm the script works properly") to see your script can handle minimal load.
113+
Start small. Run a [smoke test](/test-types/smoke-testing "a small test to confirm the script works properly") to check that your script can handle a minimal load.
114114

115115
To do so, use the [`--iterations`](/using-k6/k6-options/reference/#iterations) flag with an argument of 10 or fewer.
116116

@@ -123,19 +123,22 @@ Good thing you ran the test early!
123123

124124
### Run a test against an average load
125125

126-
Now increase the load.
127-
128126
Generally, traffic doesn't arrive all at once.
129127
Rather, it gradually increases to a peak load.
130128
To simulate this, testers increase the load in _stages_.
131129

132-
Since this is a learning environment, the stages are still quite short.
133-
Add the following _scenario_ to your options `object` and rerun the test.
134-
Where the smoke test defined the load in terms of iterations, this configuration uses the [`ramping-vus` executor](/using-k6/scenarios/executors/ramping-vus/) to express load through virtual users and duration.
130+
Add the following `scenario` property to your `options` object and rerun the test.
135131

136-
```json
132+
```javascript
133+
export const options = {
134+
// define thresholds
135+
thresholds: {
136+
http_req_failed: ['rate<0.01'], // http errors should be less than 1%
137+
http_req_duration: ['p(99)<1000'], // 99% of requests should be below 1s
138+
},
139+
// define scenarios
137140
scenarios: {
138-
//arbitrary name of scenario
141+
// arbitrary name of scenario
139142
average_load: {
140143
executor: "ramping-vus",
141144
stages: [
@@ -148,8 +151,12 @@ Where the smoke test defined the load in terms of iterations, this configuration
148151
],
149152
},
150153
}
154+
};
151155
```
152156

157+
Since this is a learning environment, the stages are still quite short.
158+
Where the smoke test defined the load in terms of iterations, this configuration uses the [`ramping-vus` executor](/using-k6/scenarios/executors/ramping-vus/) to express load through virtual users and duration.
159+
153160
Run the test with no command-line flags:
154161

155162
```bash
@@ -159,7 +166,6 @@ k6 run api-test.js
159166
The load is small, so the server should perform within thresholds.
160167
However, this test server may be under load by many k6 learners, so the results are unpredictable.
161168

162-
163169
<Blockquote mod="note" title="To visualize results...">
164170

165171
At this point, it'd be nice to have a graphical interface to visualize metrics as they occur.
@@ -176,13 +182,13 @@ In this case, run the test until the availability (error rate) threshold is cros
176182

177183
To do this:
178184

179-
1. Configure the threshold to abort when it fails.
185+
1. Add the `abortOnFail` property to `http_req_failed`.
180186

181187
```javascript
182188
http_req_failed: [{ threshold: "rate<0.01", abortOnFail: true }], // http errors should be less than 1%, otherwise abort the test
183189
```
184190

185-
1. Configure the load to ramp the test up until it fails.
191+
1. Update the `scenarios` property to ramp the test up until it fails.
186192

187193
```javascript
188194
export const options = {
@@ -191,7 +197,7 @@ To do this:
191197
http_req_duration: ['p(99)<1000'],
192198
},
193199
scenarios: {
194-
//arbitrary name of scenario:
200+
// define scenarios
195201
breaking: {
196202
executor: "ramping-vus",
197203
stages: [
@@ -211,20 +217,24 @@ To do this:
211217
```
212218

213219
Here is the full script.
214-
Copy and run it with `k6 run api-test.js`.
215220

216221
<CodeGroup labels={["api-test.js"]} lineNumbers={[true]} showCopyButton={[true]}
217222
heightTogglers={[true]}>
218223

219224
```javascript
220-
// Import necessary modules
225+
// import necessary modules
221226
import { check } from "k6";
222227
import http from "k6/http";
223228

224-
//define configuration
229+
// define configuration
225230
export const options = {
231+
// define thresholds
232+
thresholds: {
233+
http_req_failed: [{ threshold: "rate<0.01", abortOnFail: true }], // availability threshold for error rate
234+
http_req_duration: ["p(99)<1000"], // Latency threshold for percentile
235+
},
236+
// define scenarios
226237
scenarios: {
227-
//arbitrary name of scenario:
228238
breaking: {
229239
executor: "ramping-vus",
230240
stages: [
@@ -240,11 +250,6 @@ export const options = {
240250
],
241251
},
242252
},
243-
//define thresholds
244-
thresholds: {
245-
http_req_failed: [{ threshold: "rate<0.01", abortOnFail: true }], // availability threshold for error rate
246-
http_req_duration: ["p(99)<1000"], // Latency threshold for percentile
247-
},
248253
};
249254

250255
export default function () {
@@ -265,21 +270,26 @@ export default function () {
265270

266271
// check that response is 200
267272
check(res, {
268-
"login response was 200": (res) => res.status == 200,
273+
"response code was 200": (res) => res.status == 200,
269274
});
270275
}
271276

272277
```
273278

274279
</CodeGroup>
275280

281+
Run the test.
282+
283+
```bash
284+
k6 run api-test.js
285+
```
286+
276287
Did the threshold fail? If not, add another stage with a higher target and try again. Repeat until the threshold aborts the test:
277288

278289
```bash
279290
ERRO[0010] thresholds on metrics 'http_req_duration, http_req_failed' were breached; at least one has abortOnFail enabled, stopping test prematurely
280291
```
281292

282-
283293
## Next steps
284294

285295
In this tutorial, you used [thresholds](/using-k6/thresholds/) to assert performance and [Scenarios](/using-k6/scenarios) to schedule different load patterns. To learn more about the usual load patterns and their goals, read [Load Test Types](/test-types/load-test-types/)

0 commit comments

Comments
 (0)