Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fix prettier config and run prettier on all files #1460

Merged
merged 13 commits into from
Jan 4, 2024
Merged
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion docs/sources/.prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{
"files": ["**/*.md"],
"options": {
"parser": "babel"
"parser": "markdown"
}
}
]
Expand Down
6 changes: 5 additions & 1 deletion docs/sources/next/examples/api-crud-operations.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,11 @@ export default (authToken) => {
```javascript
import { describe, expect } from 'https://jslib.k6.io/k6chaijs/4.3.4.3/index.js';
import { Httpx } from 'https://jslib.k6.io/httpx/0.1.0/index.js';
import { randomIntBetween, randomItem, randomString } from 'https://jslib.k6.io/k6-utils/1.2.0/index.js';
import {
randomIntBetween,
randomItem,
randomString,
} from 'https://jslib.k6.io/k6-utils/1.2.0/index.js';

export const options = {
// for the example, let's run only 1 VU with 1 iteration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export default function () {
**Relevant k6 APIs**:

- [Selection.find(selector)](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-html/selection/selection-find) (the [jQuery Selector API](http://api.jquery.com/category/selectors/)
docs are also a good resource on what possible selector queries can be made)
docs are also a good resource on what possible selector queries can be made)
- [Selection.attr(name)](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-html/selection/selection-attr)

### Generic extraction of values/tokens
Expand Down
6 changes: 5 additions & 1 deletion docs/sources/next/examples/data-uploads.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,11 @@ const txt = open('/path/to/text.txt');
export default function () {
const fd = new FormData();
fd.append('someTextField', 'someValue');
fd.append('aBinaryFile', { data: new Uint8Array(img1).buffer, filename: 'logo.png', content_type: 'image/png' });
fd.append('aBinaryFile', {
data: new Uint8Array(img1).buffer,
filename: 'logo.png',
content_type: 'image/png',
});
fd.append('anotherTextField', 'anotherValue');
fd.append('images', http.file(img1, 'image1.png', 'image/png'));
fd.append('images', http.file(img2, 'image2.jpg', 'image/jpeg'));
Expand Down
4 changes: 2 additions & 2 deletions docs/sources/next/examples/distribute-workloads.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ To inspect the results for a certain behavior, you can [create a custom metric](
These techniques can create very complex configurations.
However, more complexity creates more ambiguity in result interpretation

{{% /admonition %}}
{{% /admonition %}}

## Split logic across scenarios

{{% admonition type="note" %}}

In this context, _workload_ refers to the traffic pattern simulated by a scenario.

{{% /admonition %}}
{{% /admonition %}}

One way to distribute traffic is to use scenarios to schedule different workloads for different functions.

Expand Down
4 changes: 2 additions & 2 deletions docs/sources/next/examples/get-started-with-k6/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ The tutorial requires the following:

## Tutorials

| In this tutorial | Learn how to |
| ----------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------ |
| In this tutorial | Learn how to |
| ---------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------ |
| [Test for functional behavior](https://grafana.com/docs/k6/<K6_VERSION>/examples/get-started-with-k6/test-for-functional-behavior) | Use k6 to script requests and evaluate that performance is correct |
| [Test for performance](https://grafana.com/docs/k6/<K6_VERSION>/examples/get-started-with-k6/test-for-performance) | Use k6 to increase load and find faults |
| [Analyze results](https://grafana.com/docs/k6/<K6_VERSION>/examples/get-started-with-k6/analyze-results) | Filter results and make custom metrics |
Expand Down
90 changes: 47 additions & 43 deletions docs/sources/next/examples/get-started-with-k6/analyze-results.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ jq '. | select(.type == "Point" and .data.tags.status == "200")' results.json
Or calculate the aggregated value of any metric with any particular tags.

{{< code >}}

```average
jq '. | select(.type == "Point" and .metric == "http_req_duration") | .data.value' results.json | jq -s 'add/length'
```
Expand All @@ -86,6 +87,7 @@ jq '. | select(.type == "Point" and .metric == "http_req_duration") | .data.valu
```max
jq '. | select(.type == "Point" and .metric == "http_req_duration") | .data.value' results.json | jq -s max
```

{{< /code >}}

## Apply custom tags
Expand Down Expand Up @@ -132,7 +134,7 @@ export default function () {
}
```

{{< /code >}}
{{< /code >}}

Run the test:

Expand Down Expand Up @@ -193,8 +195,8 @@ export default function () {
sleep(1);
}
```
{{< /code >}}

{{< /code >}}

### Add Group functions

Expand All @@ -212,22 +214,22 @@ import { group, sleep } from 'k6';
const baseUrl = 'https://test.k6.io';

export default function () {
// visit some endpoints in one group
group('Contacts flow', function () {
http.get(`${baseUrl}/contacts.php`);
sleep(1);
// return to the home page
http.get(`${baseUrl}/`);
sleep(1);
});
// visit some endpoints in one group
group('Contacts flow', function () {
http.get(`${baseUrl}/contacts.php`);
sleep(1);
// return to the home page
http.get(`${baseUrl}/`);
sleep(1);
});

// Coinflip players in another group
group('Coinflip game', function () {
http.get(`${baseUrl}/flip_coin.php?bet=heads`);
sleep(1);
http.get(`${baseUrl}/flip_coin.php?bet=tails`);
sleep(1);
});
// Coinflip players in another group
group('Coinflip game', function () {
http.get(`${baseUrl}/flip_coin.php?bet=heads`);
sleep(1);
http.get(`${baseUrl}/flip_coin.php?bet=tails`);
sleep(1);
});
}
```

Expand Down Expand Up @@ -279,35 +281,35 @@ const contactsLatency = new Trend('contacts_duration');
const coinflipLatency = new Trend('coinflip_duration');

export default function () {
// Put visits to contact page in one group
let res;
group('Contacts flow', function () {
// save response as variable
res = http.get(`${baseUrl}/contacts.php`);
// add duration property to metric
contactsLatency.add(res.timings.duration);
sleep(1);

res = http.get(`${baseUrl}/`);
// add duration property to metric
contactsLatency.add(res.timings.duration);
sleep(1);
});
// Put visits to contact page in one group
let res;
group('Contacts flow', function () {
// save response as variable
res = http.get(`${baseUrl}/contacts.php`);
// add duration property to metric
contactsLatency.add(res.timings.duration);
sleep(1);

res = http.get(`${baseUrl}/`);
// add duration property to metric
contactsLatency.add(res.timings.duration);
sleep(1);
});

// Coinflip players in another group
// Coinflip players in another group

group('Coinflip game', function () {
// save response as variable
let res = http.get(`${baseUrl}/flip_coin.php?bet=heads`);
// add duration property to metric
coinflipLatency.add(res.timings.duration);
sleep(1);
group('Coinflip game', function () {
// save response as variable
let res = http.get(`${baseUrl}/flip_coin.php?bet=heads`);
// add duration property to metric
coinflipLatency.add(res.timings.duration);
sleep(1);

res = http.get(`${baseUrl}/flip_coin.php?bet=tails`);
// add duration property to metric
coinflipLatency.add(res.timings.duration);
sleep(1);
});
res = http.get(`${baseUrl}/flip_coin.php?bet=tails`);
// add duration property to metric
coinflipLatency.add(res.timings.duration);
sleep(1);
});
}
```

Expand All @@ -329,6 +331,7 @@ contacts_duration..............: avg=125.76985 min=116.973 med=120.6735 max=200
You can also query custom metric results from the JSON results. For example, to get the aggregated results as.

{{< code >}}

```avg
jq '. | select(.type == "Point" and .metric == "coinflip_duration") | .data.value' results.json | jq -s 'add/length'
```
Expand All @@ -340,6 +343,7 @@ jq '. | select(.type == "Point" and .metric == "coinflip_duration") | .data.valu
```max
jq '. | select(.type == "Point" and .metric == "coinflip_duration") | .data.value' results.json | jq -s max
```

{{< /code >}}

## Next steps
Expand Down