Giter Club home page Giter Club logo

xk6-chaos's Introduction

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

xk6-chaos's People

Contributors

javaducky avatar mstoykov avatar nicolevanderhoeven avatar pablochacin avatar simskij avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

xk6-chaos's Issues

Migrate to a k6/js.modules.Module (ModulesV2)

What?

In the k6 we deprecated, the usage of the old modules API and in the middle of the process of the migration to a new ModulesV2 API.

To do that, we need to clean up the usages of the deprecated methods:

grep --exclude-dir=vendor -Ri "common.Bind" .
./internal/k8s/k8s.go:	return common.Bind(rt, p, ctx), nil
./internal/experiments/experiments.go:	return common.Bind(rt, p, ctx), nil

A good starting point can be our guide Create an extension.

Why?

The traditional approach of initializing JS modules involves calling common.Bind() on any objects that need to be exposed to JS. This method has a few technical issues we want to improve and isn't flexible enough to implement new features like giving extensions access to internal k6 objects.

invalid memory address or nil pointer dereference

Running the example from README.md results in the below errors. Please check.

INFO[0000] Running grafana/[email protected].             source=console
ERRO[0000] panic: runtime error: invalid memory address or nil pointer dereference
goroutine 79 [running]:
runtime/debug.Stack()
        runtime/debug/stack.go:24 +0x65
go.k6.io/k6/js/common.RunWithPanicCatching.func1()
        go.k6.io/[email protected]/js/common/util.go:101 +0x191
panic({0x1afa5e0, 0x3189400})
        runtime/panic.go:838 +0x207
github.com/dop251/goja.AssertFunction.func1.1()
        github.com/dop251/[email protected]/runtime.go:2300 +0x6e
panic({0x1afa5e0, 0x3189400})
        runtime/panic.go:838 +0x207
github.com/dop251/goja.(*vm).try.func1()
        github.com/dop251/[email protected]/vm.go:537 +0x635
panic({0x1afa5e0, 0x3189400})
        runtime/panic.go:838 +0x207
golang.org/x/time/rate.(*Limiter).WaitN(0xc000c680a0, {0x0, 0x0}, 0x1)
        golang.org/x/[email protected]/rate/rate.go:234 +0x1bd
golang.org/x/time/rate.(*Limiter).Wait(...)
        golang.org/x/[email protected]/rate/rate.go:216
k8s.io/client-go/util/flowcontrol.(*tokenBucketRateLimiter).Wait(0x214e840?, {0x0?, 0x0?})
        k8s.io/[email protected]/util/flowcontrol/throttle.go:106 +0x2b
k8s.io/client-go/rest.(*Request).tryThrottleWithInfo(0xc000c38690, {0x0, 0x0}, {0x0, 0x0})
        k8s.io/[email protected]/rest/request.go:587 +0xba
k8s.io/client-go/rest.(*Request).tryThrottle(...)
        k8s.io/[email protected]/rest/request.go:613
k8s.io/client-go/rest.(*Request).request(0xc000c38690, {0x0, 0x0}, 0x318ee50?)
        k8s.io/[email protected]/rest/request.go:873 +0x29d
k8s.io/client-go/rest.(*Request).Do(0x7ff24e7c5da8?, {0x0?, 0x0?})
        k8s.io/[email protected]/rest/request.go:980 +0xc7
k8s.io/client-go/kubernetes/typed/core/v1.(*pods).List(0xc000440780, {0x0, 0x0}, {{{0x0, 0x0}, {0x0, 0x0}}, {0x0, 0x0}, {0x0, ...}, ...})
        k8s.io/[email protected]/kubernetes/typed/core/v1/pod.go:100 +0x185
github.com/grafana/xk6-chaos/internal/k8s/pods.(*Pods).List(0x5?, {0x0, 0x0}, {0x0?, 0x8?})
        github.com/grafana/[email protected]/internal/k8s/pods/pods.go:25 +0x8c
reflect.Value.call({0x1b9cdc0?, 0xc0002d9310?, 0x7ff2754cbf18?}, {0x1d85ca0, 0x4}, {0xc00242af30, 0x2, 0xc000c5cf80?})
        reflect/value.go:556 +0x845
reflect.Value.Call({0x1b9cdc0?, 0xc0002d9310?, 0x6c802f?}, {0xc00242af30, 0x2, 0x2})
        reflect/value.go:339 +0xbf
github.com/dop251/goja.(*Runtime).wrapReflectFunc.func1({{0x214a878, 0xc00242aa20}, {0xc0015e42d0, 0x0, 0x3}})
        github.com/dop251/[email protected]/runtime.go:1886 +0x1c5
github.com/dop251/goja.(*vm)._nativeCall(0xc0025ca000, 0xc000c41e00, 0x0)
        github.com/dop251/[email protected]/vm.go:2727 +0x217
github.com/dop251/goja.call.exec(0x4?, 0xc0025ca000)
        github.com/dop251/[email protected]/vm.go:2699 +0x95b
github.com/dop251/goja.(*vm).run(0xc0025ca000)
        github.com/dop251/[email protected]/vm.go:408 +0x8b
github.com/dop251/goja.(*baseJsFuncObject)._call(0xc001990210, {{0x214b160, 0x31e6fc0}, {0xc0010f8d40, 0x1, 0x1}}, {0x0?, 0x0}, {0x214b160, 0x31e6fc0})
        github.com/dop251/[email protected]/func.go:193 +0x3ff
github.com/dop251/goja.(*baseJsFuncObject).call(...)
        github.com/dop251/[email protected]/func.go:203
github.com/dop251/goja.(*baseJsFuncObject).Call(0xc000780000?, {{0x214b160, 0x31e6fc0}, {0xc0010f8d40, 0x1, 0x1}})
        github.com/dop251/[email protected]/func.go:156 +0xc7
github.com/dop251/goja.AssertFunction.func1.2()
        github.com/dop251/[email protected]/runtime.go:2305 +0x74
github.com/dop251/goja.(*vm).try(0xc00078d638?, 0x40d325?)
        github.com/dop251/[email protected]/vm.go:545 +0x176
github.com/dop251/goja.AssertFunction.func1({0x214b160?, 0x31e6fc0?}, {0xc0010f8d40?, 0x1?, 0x1?})   
        github.com/dop251/[email protected]/runtime.go:2304 +0x10c
go.k6.io/k6/js.(*VU).runFn.func1.1()
        go.k6.io/[email protected]/js/runner.go:800 +0x43
go.k6.io/k6/js/eventloop.(*EventLoop).Start(0xc000416140, 0xc001f51e00)
        go.k6.io/[email protected]/js/eventloop/eventloop.go:112 +0x177
go.k6.io/k6/js.(*VU).runFn.func1()
        go.k6.io/[email protected]/js/runner.go:799 +0xee
go.k6.io/k6/js/common.RunWithPanicCatching({0x214dd40?, 0xc000474a80?}, 0x8?, 0x90?)
        go.k6.io/[email protected]/js/common/util.go:105 +0x87
go.k6.io/k6/js.(*VU).runFn(0xc000671b80, {0x213f0d0, 0xc001660c00}, 0xa0?, 0xc000166330, 0xc0010f8d20, {0xc0010f8d40, 0x1, 0x1})
        go.k6.io/[email protected]/js/runner.go:798 +0x2a5
go.k6.io/k6/js.(*ActiveVU).RunOnce(0xc001660bc0)
        go.k6.io/[email protected]/js/runner.go:750 +0x40f
go.k6.io/k6/lib/executor.getIterationRunner.func1({0x213f178, 0xc001f51ad0}, {0x2127940?, 0xc001660bc0?})
        go.k6.io/[email protected]/lib/executor/helpers.go:145 +0x64
go.k6.io/k6/lib/executor.PerVUIterations.Run.func3({0x212ddc0, 0xc000671b80})
        go.k6.io/[email protected]/lib/executor/per_vu_iterations.go:236 +0x40a
created by go.k6.io/k6/lib/executor.PerVUIterations.Run
        go.k6.io/[email protected]/lib/executor/per_vu_iterations.go:249 +0xbf8

Goja stack:
native

running (00m00.1s), 0/1 VUs, 0 complete and 1 interrupted iterations
default ✗ [======================================] 1 VUs  00m00.0s/10m0s  1/1 iters, 1 per VU        
WARN[0000] No script iterations finished, consider making the test duration longer

SECURITY ERROR - This download does NOT match the one reported by the checksum server

Hi, when I try to build (xk6 build --with github.com/grafana/xk6-chaos@latest) with xk6 a k6 file, I get the following error:

SECURITY ERROR
This download does NOT match the one reported by the checksum server.
The bits may have been replaced on the origin server, or an attacker may
have intercepted the download attempt.

For more information, see 'go help module-auth'.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.