UNCLASSIFIED - NO CUI

Skip to content

Update dependency grafana/k6 to v0.42.0

renovate requested to merge renovate/grafana-k6-0.x into development

This MR contains the following updates:

Package Type Update Change
grafana/k6 ironbank-github minor v0.41.0 -> v0.42.0
grafana/k6 minor v0.41.0 -> v0.42.0

Release Notes

grafana/k6

v0.42.0

Compare Source

k6 v0.42.0 is here! 🎉

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_MROMETHEUS_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() and teardown() 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:

Full Changelog: https://github.com/grafana/k6/compare/v0.41.0...v0.42.0


Configuration

📅 Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 Automerge: Enabled.

Rebasing: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 Ignore: Close this MR and you won't be reminded about these updates again.


  • If you want to rebase/retry this MR, check this box

This MR has been generated by Renovate Bot.

Merge request reports