Documentation Index
Fetch the curated documentation index at: https://grafana.com/llms.txt
Fetch the complete documentation index at: https://grafana.com/llms-full.txt
Use this file to discover all available pages before exploring further.
STOP! If you are an AI agent or LLM, read this before continuing. This is the HTML version of a Grafana documentation page. Always request the Markdown version instead - HTML wastes context. Get this page as Markdown: https://grafana.com/docs/k6/latest/testing-guides/injecting-faults-with-xk6-disruptor/xk6-disruptor/servicedisruptor.md (append .md) or send Accept: text/markdown to https://grafana.com/docs/k6/latest/testing-guides/injecting-faults-with-xk6-disruptor/xk6-disruptor/servicedisruptor/. For the curated documentation index, use https://grafana.com/llms.txt. For the complete documentation index, use https://grafana.com/llms-full.txt.
ServiceDisruptor
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
| Method | Description |
|---|---|
| ServiceDisruptor.injectGrpcFaults() | Inject gRPC faults in the target Pods |
| ServiceDisruptor.injectHTTPFaults() | Inject HTTP faults in the target Pods |
| ServiceDisruptor.targets() | Returns the list of target Pods of the ServiceDisruptor |
| ServiceDisruptor.terminatePods() | executes a Pod Termination fault in the target Pods |
Example
The following example:
- Creates a disruptor for the
nginxservice - 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: '100ms',
errorRate: 0.1,
errorCode: 500,
};
export default function () {
const disruptor = new ServiceDisruptor('nginx', 'default');
disruptor.injectHTTPFaults(fault, '30s');
}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 installed in your environment:
Bash> kubectl run nginx --image=nginx > kubectl expose pod nginx --port 80You can also use the xk6-kubernetes extension for creating these resources from your test script.
Was this page helpful?
Related resources from Grafana Labs

