Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
196 changes: 196 additions & 0 deletions docs/sources/k6/next/release-notes/v1.4.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
---
title: Version 1.4.0 release notes
menuTitle: v1.4.0
description: The release notes for Grafana k6 version 1.4.0
weight: 9985
---

# Version 1.4.0 release notes

<!-- md-k6:skipall -->

k6 `v1.4.0` is here 🎉! This release includes:

- OpenTelemetry output graduated from experimental to stable status.
- Changes in the Browser module:
- `page.waitForRequest` for waiting on specific HTTP requests.
- `QueryAll` methods now return elements in DOM order.
- `locator.evaluate` and `locator.evaluateHandle` for executing JavaScript code in the page context with access to the matching element.
- `page.unroute(url)` and `page.unrouteAll` for removing routes registered with `page.route`.

## Breaking changes

As per our [stability guarantees](https://grafana.com/docs/k6/latest/reference/versioning-and-stability-guarantees/), breaking changes across minor releases are allowed only for experimental features.

### Breaking changes for experimental modules

- [#5164](https://github.com/grafana/k6/pull/5164) OpenTelemetry output now exports rate metrics as a single counter with `zero`/`nonzero` labels instead of separate metrics.
- [#5333](https://github.com/grafana/k6/pull/5333) OpenTelemetry output configuration: `K6_OTEL_EXPORTER_TYPE` is deprecated in favor of `K6_OTEL_EXPORTER_PROTOCOL` to align with OpenTelemetry standards.

### Breaking changes for undefined behaviours
- [#5320](https://github.com/grafana/k6/pull/5320), [#5239](https://github.com/grafana/k6/pull/5239), [#5342](https://github.com/grafana/k6/pull/5342) Automatic extension resolution now only inspects ES module `import` statements and no longer supports CommonJS `require()` calls. CommonJS `require()` calls are dynamic, and it is not possible to know for certain if they will be called, or if they will be called with static strings - the only way they were even previously loaded. This functionality was a quirk of the previous implementation and had numerous problems. Additionally, `use k6` directives are now only recognized when they appear at the beginning of files (after optional shebang and whitespace/comments). This was the original intention, but due to implementation bugs, it did not accurately reflect what was happening.

## New features

### OpenTelemetry output graduation [#5334](https://github.com/grafana/k6/pull/5334)

The OpenTelemetry output has graduated from experimental status and is now available as a stable output using the name `opentelemetry`. This change makes OpenTelemetry the recommended vendor-agnostic solution for exporting k6 telemetry data.

You can now use the stable output name in your k6 commands:

```bash
# Previous experimental usage (still supported for backward compatibility)
k6 run --out experimental-opentelemetry script.js

# New stable usage
k6 run --out opentelemetry script.js
```

The `experimental-opentelemetry` name will continue to work for backward compatibility for now but it's deprecated and we might remove it in future versions. We recommend migrating to use the new `opentelemetry` name.

### `page.waitForRequest` [#5330](https://github.com/grafana/k6/pull/5330)

The browser module now supports [`page.waitForRequest()`](https://grafana.com/docs/k6/latest/javascript-api/k6-browser/page/waitforrequest/), which allows you to wait for HTTP requests that match specific URL patterns during browser automation. This method is particularly valuable for testing scenarios where you need to ensure specific network requests are initiated before proceeding with test actions.

The method supports multiple URL pattern matching strategies:

```javascript
// Wait for exact URL match
const requestPromise = page.waitForRequest('https://api.example.com/data');
await page.click('button[data-testid="load-data"]');
const request = await requestPromise;

// Wait for regex pattern match
await page.waitForRequest(/\/api\/.*\.json$/);

// Use with Promise.all for coordinated actions
await Promise.all([
page.waitForRequest('https://api.example.com/user-data'),
page.click('button[data-testid="load-user-data"]')
]);
```

This complements the existing [`page.waitForResponse()`](https://grafana.com/docs/k6/latest/javascript-api/k6-browser/page/waitforresponse/) method by focusing on HTTP requests rather than responses, providing more granular control over network-dependent test scenarios.

### `page.unroute(url)` and `page.unrouteAll()` [#5223](https://github.com/grafana/k6/pull/5223)

The browser module now supports [`page.unroute(url)`](https://grafana.com/docs/k6/latest/javascript-api/k6-browser/page/unroute/) and [`page.unrouteAll()`](https://grafana.com/docs/k6/latest/javascript-api/k6-browser/page/unrouteall/), allowing you to remove routes previously registered with `page.route`.

Example usage:
```javascript
await page.route(/.*\/api\/pizza/, function (route) {
console.log('Modifying request to /api/pizza');
route.continue({
postData: JSON.stringify({
customName: 'My Pizza',
}),
});
});
...

await page.unroute(/.*\/api\/pizza/); // The URL needs to be exactly the same as the one used in the call to the `route` function
```

```javascript
await page.route(/.*\/api\/pizza/, function (route) {
console.log('Modifying request to /api/pizza');
route.continue({
postData: JSON.stringify({
customName: 'My Pizza',
}),
});
});
...

await page.unrouteAll();
```

### `locator.evaluate` and `locator.evaluateHandle` [#5306](https://github.com/grafana/k6/pull/5306)

The browser module now supports [`locator.evaluate`](https://grafana.com/docs/k6/latest/javascript-api/k6-browser/locator/evaluate/) and [`locator.evaluateHandle`](https://grafana.com/docs/k6/latest/javascript-api/k6-browser/locator/evaluatehandle/), allowing you to execute JavaScript code in the page context with access to the matching element. The only difference between `evaluate` and `evaluateHandle` is that `evaluateHandle` returns a [JSHandle](https://grafana.com/docs/k6/latest/javascript-api/k6-browser/jshandle/).

Example usage:
```javascript
await check(page, {
'calling evaluate': async p => {
const n = await p.locator('#pizza-name').evaluate(pizzaName => pizzaName.textContent);
return n == 'Our recommendation:';
}
});

await check(page, {
'calling evaluate with arguments': async p => {
const n = await p.locator('#pizza-name').evaluate((pizzaName, extra) => pizzaName.textContent + extra, ' Super pizza!');
return n == 'Our recommendation: Super pizza!';
}
});
```

```javascript
const jsHandle = await page.locator('#pizza-name').evaluateHandle((pizzaName) => pizzaName);

const obj = await jsHandle.evaluateHandle((handle) => {
return { innerText: handle.innerText };
});
console.log(await obj.jsonValue()); // {"innerText":"Our recommendation:"}
```

### New officially supported [k6 DNS extension](https://github.com/grafana/xk6-dns)

The [`xk6-dns` extension](https://grafana.com/docs/k6/latest/javascript-api/k6-x-dns) is now officially supported in k6 OSS and k6 Cloud. You can import `k6/x/dns` directly in your scripts thanks to [automatic extension resolution](https://grafana.com/docs/grafana-cloud/testing/k6/author-run/use-k6-extensions/), with no custom build required.

Use it to perform DNS resolution testing as part of your tests: resolve names via custom or system DNS, measure resolution latency and errors, validate records before HTTP steps, compare resolvers, and even load test DNS servers in end‑to‑end scenarios.

For example:

```javascript
import dns from 'k6/x/dns';

export default function () {
const answer = dns.resolve('grafana.com', { recordType: 'A' });
console.log(answer.records.map(({ address }) => address).join(', '));
}
```

The extension currently supports A and AAAA record lookups. If you would like to see additional record types supported, please consider [contributing to the extension](https://github.com/grafana/xk6-dns).


### Automatic extension resolution improvements [#5320](https://github.com/grafana/k6/pull/5320), [#5239](https://github.com/grafana/k6/pull/5239), [#5342](https://github.com/grafana/k6/pull/5342), [#5332](https://github.com/grafana/k6/pull/5332), [#5240](https://github.com/grafana/k6/pull/5240)

Automatic extension resolution has been completely reimplemented to use k6's internal module loader instead of the external `k6deps`/esbuild pipeline. This change brings significant improvements in reliability and maintainability.

As part of the rewrite, a few issues and unintended _features_ were found, namely:
1. Trying to follow `require` calls, which, due to their dynamic nature, don't work particularly stably. That is, depending on where and how the `require` call was used, k6 might decide whether it is needed or not. And it definitely doesn't work when using actual string variables. Support for CommonJS is primarily for backward compatibility, so after an internal discussion, we opted not to support it at all. We could bring this back until v2, if there is enough interest. However, in the long term, it is intended that this not be part of k6.
2. "use k6 with ..." directives were parsed from the whole file instead of just the beginning, which leads to numerous problems, and was not the intended case. As such, they are now only parsed at the beginning of files (not just the main one) with potential empty lines and comments preceding them.

**Example:**

```javascript
// main.js
"use k6 with k6/x/faker"
import { faker } from 'k6/x/faker';
import { helper } from './utils.js';

export default function() {
console.log(faker.name());
helper();
}
```
Or, an example using the directive with CommonJS
```javascript
// utils.js
"use k6 with k6/x/redis"
const redis = require('k6/x/redis');

exports.helper = function() {
// Use redis extension
}
```

In this example, k6 will detect both `k6/x/faker` and `k6/x/redis` extensions from the `use k6` directives in both files and provision a binary that includes both extensions if needed.

Other fixes this brings are:
1. Fixes for path related issues (irregardless of usage of the feature) on windows, especially between drives. It is possible there were problems on other OSes that were just not reported. [#5176](https://github.com/grafana/k6/issues/5176)
2. Syntax errors were not reported as such, as the underlying `esbuild` parsing will fail, but won't be handled well. [#5127](https://github.com/grafana/k6/issues/5127), [#5104](https://github.com/grafana/k6/issues/5104)

3. Propagating exit codes from a sub-process running the new k6. This lets you use the result of the exit code.
95 changes: 95 additions & 0 deletions docs/sources/k6/v1.4.x/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
---
aliases:
- /docs/k6/
description: 'The k6 documentation covers everything you need to know about k6 OSS, load testing, and performance testing.'
menuTitle: Grafana k6
title: Grafana k6
weight: -10
hero:
title: Grafana k6
level: 1
image: /media/docs/k6/GrafanaLogo_k6_orange_icon.svg
width: 100
height: 100
description: Grafana k6 is an open-source, developer-friendly, and extensible load testing tool. k6 allows you to prevent performance issues and proactively improve reliability.
cards:
title_class: pt-0 lh-1
items:
- title: Run your first k6 test
href: ./get-started/
description: Learn how to install the k6 CLI, run your first k6 test, and view metric results in the terminal.
height: 24
- title: Using k6
href: ./using-k6/
description: Learn about k6 options and concepts such as thresholds, metrics, lifecycle hooks, and more.
height: 24
- title: Testing guides
href: ./testing-guides/
description: Discover how to plan and define your performance testing strategy with these guides.
height: 24
- title: k6 JavaScript API
href: ./javascript-api/
description: Explore the k6 APIs through their documentation and examples.
height: 24
- title: Explore k6 extensions
href: ./extensions/
description: Have a particular testing need? Find k6 extensions that extend the native k6 functionality.
height: 24
- title: k6 script examples
href: ./examples/
description: Learn how to write test scripts with this list of common k6 examples.
height: 24
- title: Grafana Cloud k6
href: https://grafana.com/docs/grafana-cloud/testing/k6/
description: Leverage the k6 OSS capabilities in Grafana Cloud, with built-in dashboards, insights into your application performance, and the ability to bring together teams in one place to resolve issues faster.
height: 24
- title: k6 Studio
href: https://grafana.com/docs/k6-studio/
description: Use the k6 Studio desktop application to quickly generate test scripts using a visual interface.
height: 24
---

{{< docs/hero-simple key="hero" >}}

---

## Overview

Using k6, you can test the reliability and performance of your application and infrastructure.

k6 helps engineering teams prevent errors and SLO breaches, enabling them to build resilient and high-performing applications that scale.

Engineering teams, including Developers, QA Engineers, SDETs, and SREs, commonly use k6 for:

- **Load and performance testing**

k6 is optimized for minimal resource consumption and designed for running high-load performance tests such as
[spike](https://grafana.com/docs/k6/<K6_VERSION>/testing-guides/test-types/spike-testing), [stress](https://grafana.com/docs/k6/<K6_VERSION>/testing-guides/test-types/stress-testing), or [soak tests](https://grafana.com/docs/k6/<K6_VERSION>/testing-guides/test-types/soak-testing).

- **Browser performance testing**

Through the [k6 browser API](https://grafana.com/docs/k6/<K6_VERSION>/using-k6-browser), you can run browser-based performance tests and collect browser metrics to identify performance issues related to browsers. Additionally, you can mix browser tests with other performance tests to get a comprehensive view of your website's performance.

- **Performance and synthetic monitoring**

You can schedule tests to run with minimal load very frequently, continuously validating the performance and availability of your production environment. For this, you can also use [Grafana Cloud Synthetic Monitoring](https://grafana.com/docs/grafana-cloud/testing/synthetic-monitoring/create-checks/checks/k6/), which supports running k6 scripts.

- **Automation of performance tests**

k6 integrates seamlessly with CI/CD and automation tools, enabling engineering teams to [automate performance testing](https://grafana.com/docs/k6/<K6_VERSION>/testing-guides/automated-performance-testing/) as part of their development and release cycle.

- **Chaos and resilience testing**

You can use k6 to simulate traffic as part of your chaos experiments, trigger them from your k6 tests or inject different types of faults in Kubernetes with [xk6-disruptor](https://grafana.com/docs/k6/<K6_VERSION>/testing-guides/injecting-faults-with-xk6-disruptor/xk6-disruptor).

- **Infrastructure testing**

With [k6 extensions](https://grafana.com/docs/k6/<K6_VERSION>/extensions/), you can add support to k6 for new protocols or use a particular client to directly test individual systems within your infrastructure.

Watch the video below to learn more about k6 and why it could be the missing puzzle in your Grafana stack.

{{< youtube id="1mtYVDA2_iQ" >}}

## Explore

{{< card-grid key="cards" type="simple" >}}
10 changes: 10 additions & 0 deletions docs/sources/k6/v1.4.x/examples/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
title: Examples
weight: 800
---

# Examples

<!-- TODO: Add content -->

{{< section >}}
Loading
Loading