|
| 1 | +k6 v0.42.0 is here! :tada: |
| 2 | + |
| 3 | +This release includes: |
| 4 | +- A tiny breaking change to improve WebSockets response handling. |
| 5 | +- A new experimental output. |
| 6 | +- More features in our experimental WebSocket module. |
| 7 | +- Wildcard support for `hosts`. |
| 8 | +- Some bug fixes, UX improvements, and maintenance. |
| 9 | + |
| 10 | +## Breaking changes |
| 11 | + |
| 12 | +- [#2712](https://github.com/grafana/k6/pull/2712) `k6/ws` returns an HTTP response for failed connections instead of an undefined behavior. Thanks, @brietaylor. |
| 13 | + |
| 14 | +## New Features |
| 15 | + |
| 16 | +### Experimental Prometheus Remote Write Output [#2784](https://github.com/grafana/k6/pull/2784) |
| 17 | + |
| 18 | +This release brings a new builtin Output to any [Prometheus Remote Write](https://docs.google.com/document/d/1LPhVRSFkGNSuU1fBd81ulhsCPR4hkSZyyBj1SZ8fWOM/edit) implementations (e.g. [Prometheus](https://prometheus.io/docs/prometheus/latest/feature_flags/#remote-write-receiver), [Mimir](https://grafana.com/docs/mimir/latest/operators-guide/reference-http-api/#remote-write)). This is an experimental feature, and future releases could introduce breaking changes. |
| 19 | + |
| 20 | +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): |
| 21 | + |
| 22 | +```sh |
| 23 | +k6 run -o experimental-prometheus-rw script.js |
| 24 | +``` |
| 25 | + |
| 26 | +It supports the new and convenient experimental [Native Histogram](https://prometheus.io/docs/practices/histograms) 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](https://k6.io/docs/javascript-api/k6-metrics/trend) 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`. |
| 27 | + |
| 28 | +You can find [complete documentation](https://k6.io/docs/results-output/real-time/prometheus-remote-write) with more examples, use cases, and available configurations. |
| 29 | + |
| 30 | +### More features for the experimental websockets module [#2786](https://github.com/grafana/k6/pull/2786) |
| 31 | + |
| 32 | +The `k6/experimental/websockets` module that we announced in the [v0.40.0 release](https://github.com/grafana/k6/releases/tag/v0.40.0) got an update that extends its functionality. |
| 33 | + |
| 34 | +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. |
| 35 | + |
| 36 | +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](https://github.com/grafana/xk6-websockets/issues). |
| 37 | + |
| 38 | +<details> |
| 39 | +<summary> Expand to see an example of the new WebSockets functionality</summary> |
| 40 | + |
| 41 | +This example customizes tags for a WebSocket connection, sets up handlers using the new `on*` syntax, and demonstrates the `ping`/`pong` feature. |
| 42 | + |
| 43 | +```javascript |
| 44 | +import { WebSocket } from "k6/experimental/websockets"; |
| 45 | +import { |
| 46 | + setTimeout, |
| 47 | + clearTimeout, |
| 48 | + setInterval, |
| 49 | + clearInterval |
| 50 | +} from "k6/experimental/timers"; |
| 51 | + |
| 52 | +const CLOSED_STATE = 3 |
| 53 | + |
| 54 | +export default function () { |
| 55 | + const params = { |
| 56 | + "tags": { |
| 57 | + "my_tag": "hello" |
| 58 | + } |
| 59 | + }; |
| 60 | + |
| 61 | + const ws = new WebSocket('ws://localhost:10000', null, params); |
| 62 | + |
| 63 | + ws.onopen = () => { |
| 64 | + console.log('connected'); |
| 65 | + ws.send(Date.now().toString()); |
| 66 | + }; |
| 67 | + |
| 68 | + let intervalId = setInterval(() => { |
| 69 | + ws.ping(); |
| 70 | + console.log("Pinging every 1 sec (setInterval test)"); |
| 71 | + }, 1000); |
| 72 | + |
| 73 | + let timeout1id = setTimeout(function () { |
| 74 | + console.log('2 seconds passed, closing the socket'); |
| 75 | + clearInterval(intervalId); |
| 76 | + ws.close(); |
| 77 | + }, 2000); |
| 78 | + |
| 79 | + ws.onclose = () => { |
| 80 | + clearTimeout(timeout1id); |
| 81 | + console.log('disconnected'); |
| 82 | + }; |
| 83 | + |
| 84 | + ws.onping = () => { |
| 85 | + console.log("PING!"); |
| 86 | + }; |
| 87 | + |
| 88 | + ws.onpong = () => { |
| 89 | + console.log("PONG!"); |
| 90 | + }; |
| 91 | + |
| 92 | + // Multiple event handlers on the same event |
| 93 | + ws.addEventListener("pong", () => { |
| 94 | + console.log("OTHER PONG!"); |
| 95 | + }); |
| 96 | + |
| 97 | + ws.onmessage = (m) => { |
| 98 | + let parsed = parseInt(m.data, 10) |
| 99 | + if (Number.isNaN(parsed)) { |
| 100 | + console.log('Not a number received: ', m.data); |
| 101 | + return |
| 102 | + } |
| 103 | + |
| 104 | + console.log(`Roundtrip time: ${Date.now() - parsed} ms`); |
| 105 | + |
| 106 | + let timeoutId = setTimeout(function () { |
| 107 | + if (ws.readyState == CLOSED_STATE) { |
| 108 | + console.log("Socket closed, not sending anything"); |
| 109 | + |
| 110 | + clearTimeout(timeoutId); |
| 111 | + return; |
| 112 | + } |
| 113 | + |
| 114 | + ws.send(Date.now().toString()); |
| 115 | + }, 500); |
| 116 | + }; |
| 117 | + |
| 118 | + ws.onerror = (e) => { |
| 119 | + if (e.error != "websocket: close sent") { |
| 120 | + console.log('An unexpected error occurred: ', e.error); |
| 121 | + } |
| 122 | + }; |
| 123 | +}; |
| 124 | +``` |
| 125 | +</details> |
| 126 | + |
| 127 | +The [module docs](https://k6.io/docs/javascript-api/k6-experimental/websockets) has a complete reference, and some examples. |
| 128 | + |
| 129 | +### Wildcard support for `hosts` option [#2747](https://github.com/grafana/k6/pull/2747) |
| 130 | + |
| 131 | +Thanks to the great effort from @eugercek, the [hosts](https://k6.io/docs/using-k6/k6-options/reference/#hosts) option now accepts domains that contain a wildcard at the beginning. |
| 132 | +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'`. |
| 133 | + |
| 134 | +```js |
| 135 | +export const options = { |
| 136 | + hosts: { |
| 137 | + '*.k6.io': '1.2.3.4', |
| 138 | + }, |
| 139 | +} |
| 140 | +``` |
| 141 | + |
| 142 | +### Enhancements and UX improvements |
| 143 | + |
| 144 | +- [#2660](https://github.com/grafana/k6/pull/2660) Pre-loads the operating system TLS certificates. Thanks, @tbourrely. |
| 145 | +- [#2791](https://github.com/grafana/k6/pull/2791) Initializes VUs for `setup()` and `teardown()` only if they are defined in the script. |
| 146 | + |
| 147 | +## Bug fixes |
| 148 | + |
| 149 | +- [#2759](https://github.com/grafana/k6/pull/2759) Ensures the evaluation of thresholds over trend metrics' median. |
| 150 | +- [#2759](https://github.com/grafana/k6/pull/2789) Fixes a few potential Output data races for interrupted test runs. |
| 151 | +- [#2767](https://github.com/grafana/k6/pull/2767) Fixes the emission of `ws_session_duration` when setup throws an error. |
| 152 | +- [#2773](https://github.com/grafana/k6/pull/2773) Ensures that JavaScript runtime makes only one copy of the exports for each module including built-in ones. |
| 153 | + |
| 154 | +## Maintenance and internal improvements |
| 155 | + |
| 156 | +We had a few minor changes in this release: |
| 157 | + |
| 158 | +- [#2757](https://github.com/grafana/k6/pull/2757) goja runtime has been updated. |
| 159 | +- [#2768](https://github.com/grafana/k6/pull/2768) `WS.Connect()` has been refactored. |
| 160 | +- [#2770](https://github.com/grafana/k6/pull/2770) Refactored parts of the js module. |
| 161 | +- [#2782](https://github.com/grafana/k6/pull/2782) Covered more relative path test cases for `require` and `open`. |
| 162 | +- [#2789](https://github.com/grafana/k6/pull/2789), [#2792](https://github.com/grafana/k6/pull/2792), [#2795](https://github.com/grafana/k6/pull/2795), [#2796](https://github.com/grafana/k6/pull/2796) Improved stability of the integration tests. |
| 163 | +- [#2791](https://github.com/grafana/k6/pull/2777) Optimized the performance of the internal Trie implementation. Thanks, @eugercek. |
| 164 | + |
| 165 | +**Full Changelog**: https://github.com/grafana/k6/compare/v0.41.0...v0.42.0 |
0 commit comments