Xk6-browser result output in influxdb

Hi Team,

I have running my some of api test using k6, and there we push output in influx db v2 using GitHub - grafana/xk6-output-influxdb: k6 extension to output real-time test metrics to an InfluxDB 2.x database..

K6_INFLUXDB_ORGANIZATION=“” K6_INFLUXDB_TOKEN=“” ./k6 run -o xk6-influxdb=https://ip:8088/k6_performance script.js

Now I am trying to add a browser test in same suite using xk6-browser .i.e. both browser and api test together in a single file like -

import { chromium } from 'k6/x/browser';
import { check } from 'k6';
import http from 'k6/http';

export const options = {
  scenarios: {
    browser: {
      executor: 'constant-vus',
      exec: 'browser',
      vus: 1,
      duration: '10s',
    },
    news: {
      executor: 'constant-vus',
      exec: 'news',
      vus: 20,
      duration: '1m',
    },
  },
};

export function browser() {
  const browser = chromium.launch({ headless: false });
  const page = browser.newPage();

  page
    .goto('https://test.k6.io/browser.php', { waitUntil: 'networkidle' })
    .then(() => {
      page.locator('#checkbox1').check();

      check(page, {
        'checkbox is checked': (p) =>
          p.locator('#checkbox-info-display').textContent() === 'Thanks for checking the box',
      });
    })
    .finally(() => {
      page.close();
      browser.close();
    });
}

export function news() {
  const res = http.get('https://test.k6.io/news.php');

  check(res, {
    'status is 200': (r) => r.status === 200,
  });
}

and to run this I am using

xk6-browser run script.js

but since I am using below command to push my results in influx db


K6_INFLUXDB_ORGANIZATION="" K6_INFLUXDB_TOKEN="" ./k6 run -o xk6-influxdb=https://ip:8088/k6_performance  script.js

So I thought to replace

./k6 run with xk6-browser run

and my command looks like

K6_INFLUXDB_ORGANIZATION="" K6_INFLUXDB_TOKEN="" ./xk6-browser run -o xk6-influxdb=https://ip:8088/k6_performance  script.js

But i am getting error as -

type not supported …invalid output type ‘xk6-influxdb’, , available types are: cloud, csv, experimental-prometheus-rw, influxdb, json, statsd

and if I am using “influxdb” in place of “xk6-influxdb” then getting error as influxdb v2 not supported

Any suggestions ?

Hi @vish_s02,

Thanks for sharing your case.

xk6-browser is currently being developed as a k6 extension. Consequently, you have to run a k6 version built with the browser extension to use the browser-level APIs in your k6 tests. And if you want to also run with the influxdb v2 extension, you would have to build k6 with both extensions.

For that you can visit k6 Bundle Builder, and check the two extensions you want to run. You’ll get the command to build the k6 binary.

xk6 build v0.42.0 --with github.com/grafana/xk6-browser --with github.com/grafana/xk6-output-influxdb

With this binary, you should be able to run both extensions.

K6_INFLUXDB_ORGANIZATION=“” K6_INFLUXDB_TOKEN=“” ./k6 run -o xk6-influxdb=https://ip:8088/k6_performance script.js

An alternative to send the output InfluxDB v2.x without using the InfluxDb v2 extension, is to use the experimental prometheus remote write, which is compatible with InfluxDb 2.x.

Something like this:

K6_PROMETHEUS_RW_SERVER_URL=http://influxdb:8086/api/v1/prom/write?db=k6 ./k6 run -o experimental-prometheus-rw script.js

I hope this helps. Let me know if you still have issues.

Cheers!

Thanks, It’s working fine

1 Like

A post was split to a new topic: Xk6-playwright output summary and influxdb extensions