release notes/v0.35.0.md
k6 v0.35.0 is here! :tada: It introduces several new features that nicely enhance its usability and also contains a whole lot of fixes and ongoing efforts with refactoring.
In total, we have closed 14 issues. We have also branched out three new xk6 extensions during this release :star:
k6 now supports setting tags for VUs as part of the Execution API with an easy key-value interface. These tags are attached to the metrics emitted by the VU. Example usage:
import http from 'k6/http';
import exec from 'k6/execution';
export const options = {
duration: '10s',
vus: 3,
};
export default function () {
exec.vu.tags['mytag'] = 'value';
exec.vu.tags['vuId'] = exec.vu.idInTest;
console.log(`mytag is ${exec.vu.tags['mytag']} and my VU's ID in tags ${exec.vu.tags['vuId']}`);
// the metrics these HTTP requests emit will get tagged with `mytag` and `vuId`:
http.batch(['https://test.k6.io', 'https://test-api.k6.io']);
}
One of the most requested use cases for this feature is that now we can tag all metrics with the current stage number. With a bit of JS code it is possible to calculate which stage of a ramping-vus or ramping-arrival-rate scenario the VU is currently in. This in turn allows the setting of thresholds only on the metrics that were emitted in specific stages of the test run! :tada:
There are some caveats, however: values can be only of String, Number or Boolean type, while values of other types will result either in a warning or an exception if throw option is enabled. Additionally, given that k6 has a whole bunch of system tags, one should be careful with using them as keys. You can read complete information about VU tags in k6/execution docs.
With the goja update in #2197, you can now make a Promise and chain it in your k6 scripts:
export default function () {
var p = new Promise((resolve, reject) => {
console.log('do something promising!');
reject('here');
});
p.then(
(s) => { console.log('fulfilled with', s) },
(s) => { console.log('rejected with', s) },
);
}
It must be noted that Promises are not used by k6 itself yet but this addition is a stepping stone for implementing async functionality in future releases. Thanks, @dop251, for your awesome work in developing goja! :heart:
k6's gRPC capabilities were extended with a support for server reflection which allows one to use gRPC even without a proto file at hand. In other words, the following script is now possible:
import grpc from 'k6/net/grpc';
import { check } from "k6";
let client = new grpc.Client();
export default () => {
client.connect("127.0.0.1:10000", {plaintext: true, reflect: true})
const response = client.invoke("main.RouteGuide/GetFeature", {
latitude: 410248224,
longitude: -747127767
})
check(response, {"status is OK": (r) => r && r.status === grpc.StatusOK});
console.log(JSON.stringify(response.message))
client.close()
}
You can read more about the protocol here. Thanks, @joshcarp, for putting a lot of effort into this feature!
k6/ws (#2193).metric.Add calls to let NaN values through. Instead, k6 will log nice warnings or throw an exception if --throw is enabled (#1876, #2219).nil response body (#2195). Thanks, @daniel-shuy!xk6-browser is a browser automation extension which relies on Chrome Devtools Protocol. With xk6-browser, you can interact with the browser to test your web applications end-to-end while accessing all of the k6 core features, including protocol-level APIs and other k6 extensions. It’s a single tool for both protocol and browser-level testing.
The browser extension comes with an API that aims for rough compatibility with the Playwright API for NodeJS, meaning k6 users do not have to learn an entirely new API.
Prometheus is now officially supported in k6 OSS with a xk6-output-remote-write extension. This is an output extension with implementation for Prometheus Remote-Write protocol which means that beyond Prometheus, any compatible remote-write solution can be used with it. You can read the full guide to using the extension in the relevant tutorial.
After hard work at working out how to integrate InfluxDB v2 API, it was decided to pull that integration into a new xk6-output-influxdb extension for now. The built-in influxdb output in k6 still supports only InfluxDB v1, as before, with some minor optimizations (#2190).
Please try out the new extensions and tell us what you think!
new Counter("http_req_duration") will now abort. Similarly, an attempt to redefine a metric with the same name but with different type will error out. Builtin metrics may no longer be referenced as global objects in xk6 extensions either.K6_NO_SETUP and K6_NO_TEARDOWN options instead of NO_SETUP and NO_TEARDOWN (#2140).afero.FS: implement a newer version of the afero.FS interface for internal filesystems so that extension depending on that or newer version can be built (#2216).User-Agent setting (#2151). Thanks, @cooliscool!mapstructure (#2223).k6 participated in this year's hacktoberfest and we would like to thank all contributors! Here're some additional improvements made by the community members:
Thank you, @knittl, @cooliscool, @JosephWoodward, @b5710546232, @nontw, @divshacker, @daniel-shuy, @Sayanta66, @marooncoder09, @idivyanshbansal, @saintmalik, @EricSmekens, for helping make k6 better :smile: