Skip to content
This repository has been archived by the owner on Nov 9, 2022. It is now read-only.
/ xk6-chaos Public archive

xk6 extension for running chaos experiments with k6 💣

License

Notifications You must be signed in to change notification settings

grafana/xk6-chaos

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Deprecation notice

⚠️ k6-chaos has been deprecated in favor or xk6-disruptor a k6 extension providing fault injection capabilities.



logo

xk6-chaos

A k6 extension for testing for the unknown unknowns. Built for k6 using xk6.

Build

To build a k6 binary with this extension, first ensure you have the prerequisites:

Then:

  1. Download xk6:
$ go install go.k6.io/xk6/cmd/xk6@latest
  1. Build the binary:
$ xk6 build --with github.com/grafana/xk6-chaos@latest

Example

import chaos from 'k6/x/chaos';
import { Pods } from 'k6/x/chaos/k8s';

export default function () {
  console.log(`Running grafana/xk6-chaos@${chaos.version}.`);
  const p = new Pods();
  console.log(
    `There are currently ${p.list().length} pods in the default namespace.`
  );
  killPod(p);
  console.log(
    `There are now ${p.list().length} pods in the default namespace.`
  );
}

function killPod(p) {
  const victim = p.list()[0];
  console.log(`Killing pod ${victim}`);
  p.killByName('default', victim);
}

Result output:

$ ./k6 run script.js

          /\      |‾‾| /‾‾/   /‾‾/   
     /\  /  \     |  |/  /   /  /    
    /  \/    \    |     (   /   ‾‾\  
   /          \   |  |\  \ |  (‾)  | 
  / __________ \  |__| \__\ \_____/ .io

  execution: local
     script: test.js
     output: -

  scenarios: (100.00%) 1 scenario, 1 max VUs, 10m30s max duration (incl. graceful stop):
           * default: 1 iterations for each of 1 VUs (maxDuration: 10m0s, gracefulStop: 30s)

INFO[0000] Running grafana/[email protected].             source=console
INFO[0000] There are currently 33 pods in the default namespace.  source=console
INFO[0000] Killing pod chaos-webserver-54bd848884-ds2g9           source=console
INFO[0000] There are now 32 pods in the default namespace.        source=console

running (00m00.1s), 0/1 VUs, 1 complete and 0 interrupted iterations
default ✓ [======================================] 1 VUs  00m00.1s/10m0s  1/1 iters, 1 per VU

    data_received........: 0 B 0 B/s
    data_sent............: 0 B 0 B/s
    iteration_duration...: avg=111.72ms min=111.72ms med=111.72ms max=111.72ms p(90)=111.72ms p(95)=111.72ms
    iterations...........: 1   7.513995/s