Skip to content

Commit

Permalink
Relocate the xk6-disruptor API to the Disruptor guide (#1549)
Browse files Browse the repository at this point in the history
  • Loading branch information
ppcano authored Apr 16, 2024
1 parent 9f8995d commit 881447b
Show file tree
Hide file tree
Showing 27 changed files with 83 additions and 65 deletions.
2 changes: 1 addition & 1 deletion docs/sources/next/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ Common k6 use cases are:

- **Chaos and resilience testing**

You can use k6 to simulate traffic as part of your chaos experiments, trigger them from your k6 tests or inject different types of faults in Kubernetes with [xk6-disruptor](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/xk6-disruptor).
You can use k6 to simulate traffic as part of your chaos experiments, trigger them from your k6 tests or inject different types of faults in Kubernetes with [xk6-disruptor](https://grafana.com/docs/k6/<K6_VERSION>/testing-guides/injecting-faults-with-xk6-disruptor/xk6-disruptor).

- **Performance and synthetic monitoring**

Expand Down
15 changes: 0 additions & 15 deletions docs/sources/next/javascript-api/xk6-disruptor/faults/_index.md

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion docs/sources/next/misc/integrations.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ By automating load testing with your CI / CD tools, you can quickly see when a c
## Chaos engineering

- [Steadybit](https://k6.io/blog/chaos-engineering-with-k6-and-steadybit) - Using k6 and Steadybit for chaos engineering.
- [xk6-disruptor](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/xk6-disruptor) - A k6 extension for injecting faults into k6 tests.
- [xk6-disruptor](https://grafana.com/docs/k6/<K6_VERSION>/testing-guides/injecting-faults-with-xk6-disruptor/xk6-disruptor) - A k6 extension for injecting faults into k6 tests.
- [ChaosToolkit](http://chaostoolkit.org/drivers/k6/) - A collection of k6 actions and probes.

## Test management
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
---
aliases:
- ../javascript-api/xk6-disruptor/get-started # docs/k6/<K6_VERSION>/javascript-api/xk6-disruptor/get-started/
title: 'Injecting faults with xk6-disruptor'
description: 'xk6-disruptor is a k6 extension providing fault injection capabilities to test system reliability under turbulent conditions.'
weight: 06
Expand All @@ -18,7 +20,7 @@ Key features include:

Currently, the disruptor is intended to test applications running in Kubernetes. Other platforms are not supported at this time.

It provides a Javascript API to inject different [faults](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/xk6-disruptor/faults/) in HTTP and gRPC requests, such as errors and delays, into the selected Kubernetes [Pods](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/xk6-disruptor/poddisruptor/) or [Services](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/xk6-disruptor/servicedisruptor/).
It provides a Javascript API to inject different [faults](https://grafana.com/docs/k6/<K6_VERSION>/testing-guides/injecting-faults-with-xk6-disruptor/xk6-disruptor/faults/) in HTTP and gRPC requests, such as errors and delays, into the selected Kubernetes [Pods](https://grafana.com/docs/k6/<K6_VERSION>/testing-guides/injecting-faults-with-xk6-disruptor/xk6-disruptor/poddisruptor/) or [Services](https://grafana.com/docs/k6/<K6_VERSION>/testing-guides/injecting-faults-with-xk6-disruptor/xk6-disruptor/servicedisruptor/).

Other types of faults and disruptors will be introduced in the future. The [Roadmap](https://github.com/grafana/xk6-disruptor/blob/main/ROADMAP.md) presents the project's goals for the coming months regarding new functionalities and enhancements.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: 'xk6-disruptor examples'
description: 'Examples of how to use the xk6-disruptor extension to introduce faults in k6 tests.'
weight: 06
weight: 07
---

# xk6-disruptor examples
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ weight: 01

# Inject gRPC faults into Service

This example shows a way to use the [ServiceDisruptor](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/xk6-disruptor/servicedisruptor) to test the effect of faults injected in the gRPC requests served by a service.
This example shows a way to use the [ServiceDisruptor](https://grafana.com/docs/k6/<K6_VERSION>/testing-guides/injecting-faults-with-xk6-disruptor/xk6-disruptor/servicedisruptor) to test the effect of faults injected in the gRPC requests served by a service.

The complete [source code](#source-code) is at the end of this document. The next sections examine the code in detail.

Expand All @@ -18,7 +18,7 @@ For the Kubernetes manifests and the instructions on how to deploy it to a clust

## Initialization

The initialization code imports the external dependencies required by the test. The [ServiceDisruptor](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/xk6-disruptor/servicedisruptor) class imported from the `xk6-disruptor` extension provides functions for injecting faults in services. The [k6/net/grpc](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-net-grpc) module provides functions for executing gRPC requests. The [check](https://grafana.com/docs/k6/<K6_VERSION>/using-k6/checks) function verifies the results from the requests.
The initialization code imports the external dependencies required by the test. The [ServiceDisruptor](https://grafana.com/docs/k6/<K6_VERSION>/testing-guides/injecting-faults-with-xk6-disruptor/xk6-disruptor/servicedisruptor) class imported from the `xk6-disruptor` extension provides functions for injecting faults in services. The [k6/net/grpc](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-net-grpc) module provides functions for executing gRPC requests. The [check](https://grafana.com/docs/k6/<K6_VERSION>/using-k6/checks) function verifies the results from the requests.

```javascript
import { ServiceDisruptor } from 'k6/x/disruptor';
Expand Down Expand Up @@ -60,7 +60,7 @@ export default function () {

The `disrupt` function creates a `ServiceDisruptor` for the `grpcbin` service in the namespace `grpcbin`.

The gRPC faults are injected by calling the [ServiceDisruptor.injectGrpcFaults](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/xk6-disruptor/servicedisruptor/injectgrpcfaults) method using a fault definition that introduces a delay of `300ms` on each request and an error with status code `13` ("Internal error") in `10%` of the requests.
The gRPC faults are injected by calling the [ServiceDisruptor.injectGrpcFaults](https://grafana.com/docs/k6/<K6_VERSION>/testing-guides/injecting-faults-with-xk6-disruptor/xk6-disruptor/servicedisruptor/injectgrpcfaults) method using a fault definition that introduces a delay of `300ms` on each request and an error with status code `13` ("Internal error") in `10%` of the requests.

```javascript
export function disrupt() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ weight: 02

# Inject HTTP faults into Pod

This example shows how [PodDisruptor](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/xk6-disruptor/poddisruptor) can be used for testing the effect of faults injected in the HTTP requests served by a pod.
This example shows how [PodDisruptor](https://grafana.com/docs/k6/<K6_VERSION>/testing-guides/injecting-faults-with-xk6-disruptor/xk6-disruptor/poddisruptor) can be used for testing the effect of faults injected in the HTTP requests served by a pod.

You will find the complete [source code](#source-code) at the end of this document. Next sections examine the code in detail.

Expand Down Expand Up @@ -45,7 +45,7 @@ The test uses the `delay` endpoint which return after the requested delay. It re

The `disrupt` function creates a `PodDisruptor` using a selector that matches pods in the namespace `httpbin` with the label `app: httpbin`.

The http faults are injected by calling the [PodDisruptor.injectHTTPFaults](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/xk6-disruptor/poddisruptor/injecthttpfaults) method using a fault definition that introduces a delay of `50ms` on each request and an error code `500` in `10%` of the requests.
The http faults are injected by calling the [PodDisruptor.injectHTTPFaults](https://grafana.com/docs/k6/<K6_VERSION>/testing-guides/injecting-faults-with-xk6-disruptor/xk6-disruptor/poddisruptor/injecthttpfaults) method using a fault definition that introduces a delay of `50ms` on each request and an error code `500` in `10%` of the requests.

```javascript
export function disrupt(data) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ weight: 01

[xk6-disruptor](https://github.com/grafana/xk6-disruptor) is an extension that adds fault injection capabilities to k6.

It provides a Javascript [API](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/xk6-disruptor/) to inject [faults](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/xk6-disruptor/faults) such as errors and delays into HTTP and gRPC requests served by selected Kubernetes [Pods](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/xk6-disruptor/poddisruptor) or [Services](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/xk6-disruptor/servicedisruptor).
It provides a Javascript [API](https://grafana.com/docs/k6/<K6_VERSION>/testing-guides/injecting-faults-with-xk6-disruptor/xk6-disruptor/) to inject [faults](https://grafana.com/docs/k6/<K6_VERSION>/testing-guides/injecting-faults-with-xk6-disruptor/xk6-disruptor/faults) such as errors and delays into HTTP and gRPC requests served by selected Kubernetes [Pods](https://grafana.com/docs/k6/<K6_VERSION>/testing-guides/injecting-faults-with-xk6-disruptor/xk6-disruptor/poddisruptor) or [Services](https://grafana.com/docs/k6/<K6_VERSION>/testing-guides/injecting-faults-with-xk6-disruptor/xk6-disruptor/servicedisruptor).

```javascript
export default function () {
Expand All @@ -27,7 +27,7 @@ export default function () {

## Next steps

Explore the fault injection [API](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/xk6-disruptor/)
Explore the fault injection [API](https://grafana.com/docs/k6/<K6_VERSION>/testing-guides/injecting-faults-with-xk6-disruptor/xk6-disruptor/)

See [step-by-step examples](https://grafana.com/docs/k6/<K6_VERSION>/testing-guides/injecting-faults-with-xk6-disruptor/examples).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ The xk6-disruptor extension installs the agent in the target and sends commands

The following diagram shows how PodDisruptor works:

1. The PodDisruptor selects the target pods based on the selector attributes defined in the [constructor](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/xk6-disruptor/poddisruptor/constructor)
1. The PodDisruptor selects the target pods based on the selector attributes defined in the [constructor](https://grafana.com/docs/k6/<K6_VERSION>/testing-guides/injecting-faults-with-xk6-disruptor/xk6-disruptor/poddisruptor/constructor)
2. The PodDisruptor attaches the xk6-disruptor-agent to each of the target pods
3. When a fault is injected (e.g. calling the [injectHTTTFault](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/xk6-disruptor/poddisruptor/injecthttpfaults)) the PodDisruptor sends a command to the agents to inject the fault in their respective pods
3. When a fault is injected (e.g. calling the [injectHTTTFault](https://grafana.com/docs/k6/<K6_VERSION>/testing-guides/injecting-faults-with-xk6-disruptor/xk6-disruptor/poddisruptor/injecthttpfaults)) the PodDisruptor sends a command to the agents to inject the fault in their respective pods

![How PodDisruptor works](/media/docs/k6-oss/xk6-disruptor-how-pod-disruptor-works.png)

## ServiceDisruptor

The ServiceDisruptor works as a wrapper around a PodDisruptor, which targets the pods that back the service.

1. The ServiceDisruptor uses the definition of the service specified in the [constructor](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/xk6-disruptor/servicedisruptor/constructor) to create a pod selector that matches the pods that back the service.
1. The ServiceDisruptor uses the definition of the service specified in the [constructor](https://grafana.com/docs/k6/<K6_VERSION>/testing-guides/injecting-faults-with-xk6-disruptor/xk6-disruptor/servicedisruptor/constructor) to create a pod selector that matches the pods that back the service.
2. The ServiceDisruptor creates a PodDisruptor using this pod selector.
3. The PodDisruptor installs the agent in the target pods.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ weight: 03

# Installation

xk6-disruptor is a [k6 extension](https://grafana.com/docs/k6/<K6_VERSION>/extensions). You have to run a k6 version built with the disruptor extension to use the [disruptor APIs](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/xk6-disruptor/) in your k6 tests.
xk6-disruptor is a [k6 extension](https://grafana.com/docs/k6/<K6_VERSION>/extensions). You have to run a k6 version built with the disruptor extension to use the [disruptor APIs](https://grafana.com/docs/k6/<K6_VERSION>/testing-guides/injecting-faults-with-xk6-disruptor/xk6-disruptor/) in your k6 tests.

The following sections explain the different options to get this custom binary.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
---
aliases:
- ../../javascript-api/xk6-disruptor # docs/k6/<K6_VERSION>/javascript-api/xk6-disruptor
title: xk6-disruptor API
description: 'An overview of the API for xk6-disruptor.'
weight: 14
weight: 06
---

# xk6-disruptor API

The xk6-disruptor API is organized around _disruptors_ that affect specific targets such as pods or services. These disruptors can inject different types of [faults](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/xk6-disruptor/faults) on their targets.
The xk6-disruptor API is organized around _disruptors_ that affect specific targets such as pods or services. These disruptors can inject different types of [faults](https://grafana.com/docs/k6/<K6_VERSION>/testing-guides/injecting-faults-with-xk6-disruptor/xk6-disruptor/faults) on their targets.

| Class | Description |
| ---------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------- |
| [PodDisruptor](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/xk6-disruptor/poddisruptor) | Targets the Pods that match selection attributes such as labels. |
| [ServiceDisruptor](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/xk6-disruptor/servicedisruptor) | Targets the Pods that back a Kubernetes Service |
| [PodDisruptor](https://grafana.com/docs/k6/<K6_VERSION>/testing-guides/injecting-faults-with-xk6-disruptor/xk6-disruptor/poddisruptor) | Targets the Pods that match selection attributes such as labels. |
| [ServiceDisruptor](https://grafana.com/docs/k6/<K6_VERSION>/testing-guides/injecting-faults-with-xk6-disruptor/xk6-disruptor/servicedisruptor) | Targets the Pods that back a Kubernetes Service |
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
aliases:
- ../../../javascript-api/xk6-disruptor/faults # docs/k6/<K6_VERSION>/javascript-api/xk6-disruptor/faults
title: 'Faults'
description: 'xk6-disruptor: Fault Description'
weight: 100
---

# Faults

A fault is as an abnormal condition that affects a system component and which may lead to a failure.

| Fault type | Description |
| --------------------------------------------------------------------------------------------------------------------- | ------------------------------------------- |
| [gRPC Fault](https://grafana.com/docs/k6/<K6_VERSION>/testing-guides/injecting-faults-with-xk6-disruptor/xk6-disruptor/faults/grpc) | Fault affecting gRPC requests from a target |
| [HTTP Fault](https://grafana.com/docs/k6/<K6_VERSION>/testing-guides/injecting-faults-with-xk6-disruptor/xk6-disruptor/faults/http) | Fault affecting HTTP requests from a target |
| [Pod Termination Fault](https://grafana.com/docs/k6/<K6_VERSION>/testing-guides/injecting-faults-with-xk6-disruptor/xk6-disruptor/faults/pod-termination) | Fault terminating a number of target Pods |
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
---
aliases:
- ../../../../javascript-api/xk6-disruptor/faults/grpc # docs/k6/<K6_VERSION>/javascript-api/xk6-disruptor/faults/grpc
title: 'gRPC'
description: 'xk6-disruptor: gRPC Fault attributes'
weight: 01
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
---
aliases:
- ../../../../javascript-api/xk6-disruptor/faults/http # docs/k6/<K6_VERSION>/javascript-api/xk6-disruptor/faults/http
title: 'HTTP'
description: 'xk6-disruptor: HTTP Fault attributes'
weight: 02
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
---
aliases:
- ../../../../javascript-api/xk6-disruptor/faults/pod-termination # docs/k6/<K6_VERSION>/javascript-api/xk6-disruptor/faults/pod-termination
title: 'Pod Termination'
description: 'xk6-disruptor: Pod Termination Fault attributes'
weight: 03
Expand Down
Loading

0 comments on commit 881447b

Please sign in to comment.