No results for

Powered byAlgolia

The ServiceDisruptor class can inject different types of faults into the pods that back a Kubernetes service.

To construct a ServiceDisruptor, use the ServiceDisruptor() constructor.

Methods

MethodDescription
ServiceDisruptor.injectHTTPFaults()Inject HTTTP faults in the target Pods

Example

The following example:

  • Creates a disruptor for the nginx service
  • Injects a delay of 100ms and a 10 percent of requests that return an http response code 500.
import { ServiceDisruptor } from 'k6/x/disruptor';
const fault = {
averageDelay: 100,
errorRate: 0.1,
errorCode: 500,
};
export default function () {
const disruptor = new ServiceDisruptor('nginx', 'default');
const targets = disruptor.targets();
if (targets.length != 1) {
throw new Error('expected list to have one target');
}
disruptor.injectHTTPFaults(fault, 30);
}
note
> You can test this script by creating first a pod running nginx and exposing it as a service with the commands below, assuming you have [kubectl](https://kubernetes.io/docs/tasks/tools/#kubectl) installed in your environment: ```bash > kubectl run nginx --image=nginx > kubectl expose pod nginx --port 80 ```

You can also use the xk6-kubernetes extension for creating these resources from your test script.