v0.42.0
版本发布时间: 2022-12-20 17:35:36
grafana/k6最新发布版本:v0.54.0(2024-09-30 17:50:44)
k6 v0.42.0 is here! :tada:
This release includes:
- A tiny breaking change to improve WebSockets response handling.
- A new experimental output.
- More features in our experimental WebSocket module.
- Wildcard support for
hosts
. - Some bug fixes, UX improvements, and maintenance.
Breaking changes
-
#2712
k6/ws
returns an HTTP response for failed connections instead of an undefined behavior. Thanks, @brietaylor.
New Features
Experimental Prometheus Remote Write Output #2784
This release brings a new builtin Output to any Prometheus Remote Write implementations (e.g. Prometheus, Mimir). This is an experimental feature, and future releases could introduce breaking changes.
The following example uses k6 run
with the new output. It uses the defaults options, such as the Remote Write server URL (http://localhost:9090/api/v1/write):
k6 run -o experimental-prometheus-rw script.js
It supports the new and convenient experimental Native Histogram feature, added in Prometheus v2.40.0
. It's not enabled by default, but we expect to make it the default way to map k6 Trend metrics once the Prometheus project signals that its mature enough and when more Remote Write implementations support it. For now, if you want to use it, you need to set the environment variable K6_PROMETHEUS_RW_TREND_AS_NATIVE_HISTOGRAM
to true
.
You can find complete documentation with more examples, use cases, and available configurations.
More features for the experimental websockets module #2786
The k6/experimental/websockets
module that we announced in the v0.40.0 release got an update that extends its functionality.
It brings some useful features that the k6/ws
module already has, like cookies, custom headers, compression and tags customization support, the syntax to define event handlers (onopen
, onmessage
, etc.) and ping
/pong
functionality.
This is still an experimental module, but with the recent changes we think it's usable for most users. So whether you're writing a new WebSocket test, or currently using the k6/ws
module, we invite you to give it a try, and report any issues in the project's issue tracker.
Expand to see an example of the new WebSockets functionality
This example customizes tags for a WebSocket connection, sets up handlers using the new on*
syntax, and demonstrates the ping
/pong
feature.
import { WebSocket } from "k6/experimental/websockets";
import {
setTimeout,
clearTimeout,
setInterval,
clearInterval
} from "k6/experimental/timers";
const CLOSED_STATE = 3
export default function () {
const params = {
"tags": {
"my_tag": "hello"
}
};
const ws = new WebSocket('ws://localhost:10000', null, params);
ws.onopen = () => {
console.log('connected');
ws.send(Date.now().toString());
};
let intervalId = setInterval(() => {
ws.ping();
console.log("Pinging every 1 sec (setInterval test)");
}, 1000);
let timeout1id = setTimeout(function () {
console.log('2 seconds passed, closing the socket');
clearInterval(intervalId);
ws.close();
}, 2000);
ws.onclose = () => {
clearTimeout(timeout1id);
console.log('disconnected');
};
ws.onping = () => {
console.log("PING!");
};
ws.onpong = () => {
console.log("PONG!");
};
// Multiple event handlers on the same event
ws.addEventListener("pong", () => {
console.log("OTHER PONG!");
});
ws.onmessage = (m) => {
let parsed = parseInt(m.data, 10)
if (Number.isNaN(parsed)) {
console.log('Not a number received: ', m.data);
return
}
console.log(`Roundtrip time: ${Date.now() - parsed} ms`);
let timeoutId = setTimeout(function () {
if (ws.readyState == CLOSED_STATE) {
console.log("Socket closed, not sending anything");
clearTimeout(timeoutId);
return;
}
ws.send(Date.now().toString());
}, 500);
};
ws.onerror = (e) => {
if (e.error != "websocket: close sent") {
console.log('An unexpected error occurred: ', e.error);
}
};
};
The module docs has a complete reference, and some examples.
Wildcard support for hosts
option #2747
Thanks to the great effort from @eugercek, the hosts option now accepts domains that contain a wildcard at the beginning.
It can be helpful for setting multiple subdomains of the same domain, so instead of setting subdomain1.k6.io': '1.2.3.4', 'subdomain2.k6.io': '1.2.3.4'
it is possible to use the wildcard for setting directly *.k6.io: '1.2.3.4'
.
export const options = {
hosts: {
'*.k6.io': '1.2.3.4',
},
}
Enhancements and UX improvements
- #2660 Pre-loads the operating system TLS certificates. Thanks, @tbourrely.
-
#2791 Initializes VUs for
setup()
andteardown()
only if they are defined in the script.
Bug fixes
- #2759 Ensures the evaluation of thresholds over trend metrics' median.
- #2759 Fixes a few potential Output data races for interrupted test runs.
-
#2767 Fixes the emission of
ws_session_duration
when setup throws an error. - #2773 Ensures that JavaScript runtime makes only one copy of the exports for each module including built-in ones.
Maintenance and internal improvements
We had a few minor changes in this release:
- #2757 goja runtime has been updated.
-
#2768
WS.Connect()
has been refactored. - #2770 Refactored parts of the js module.
-
#2782 Covered more relative path test cases for
require
andopen
. - #2789, #2792, #2795, #2796 Improved stability of the integration tests.
- #2791 Optimized the performance of the internal Trie implementation. Thanks, @eugercek.
Full Changelog: https://github.com/grafana/k6/compare/v0.41.0...v0.42.0
1、 k6-v0.42.0-checksums.txt 754B
2、 k6-v0.42.0-linux-amd64.deb 17.52MB
3、 k6-v0.42.0-linux-amd64.rpm 19.24MB
4、 k6-v0.42.0-linux-amd64.tar.gz 18.43MB
5、 k6-v0.42.0-linux-arm64.tar.gz 17.26MB
6、 k6-v0.42.0-macos-amd64.zip 18.11MB
7、 k6-v0.42.0-macos-arm64.zip 17.53MB
8、 k6-v0.42.0-windows-amd64.msi 18.96MB
9、 k6-v0.42.0-windows-amd64.zip 18.55MB