Skip to content

Commit 3cefbeb

Browse files
authored
Add Grpc fault injection (#1108)
* Add grpc faults to API * Add grpc example Signed-off-by: Pablo Chacin <[email protected]>
1 parent 5fac38f commit 3cefbeb

File tree

13 files changed

+556
-1
lines changed

13 files changed

+556
-1
lines changed

.eslintignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ node_modules/
44
docs/sources/get-started/run-cloud-tests-from-the-CLI.md
55
docs/sources/get-started/run-your-first-tests.md
66
CONTRIBUTING_FILE_FORMAT.md
7-
src/data/markdown/docs/40 xk6-disruptor/04 Examples/01 Inject HTTP faults into Pod.md
7+
src/data/markdown/docs/40 xk6-disruptor/04 Examples/01 Inject Grpc faults into Service.md
8+
src/data/markdown/docs/40 xk6-disruptor/04 Examples/02 Inject HTTP faults into Pod.md

src/data/markdown/docs/40 xk6-disruptor/03 API/01 Faults.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ A fault is as an abnormal condition that affects a system component and which ma
77

88
| Fault type | Description |
99
| ---------- | ---------- |
10+
| [gRPC Fault](/javascript-api/xk6-disruptor/api/faults/grpc) | Fault affecting gRPC requests from a target |
1011
| [HTTP Fault](/javascript-api/xk6-disruptor/api/faults/http) | Fault affecting HTTP requests from a target |
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
title: 'gRPC'
3+
excerpt: 'xk6-disruptor: gRPC Fault attributes'
4+
---
5+
6+
A gRPC Fault describes the characteristics of the faults to be injected in the gRPC requests served by a target.
7+
8+
A gRPC fault is described by the following attributes:
9+
10+
| Attribute | Description |
11+
| --------- | ------------|
12+
| averageDelay | average delay added to requests in milliseconds (default `0ms`) |
13+
| delayVariation| variation in the injected delay in milliseconds (default `0ms`) |
14+
| statusMessage | message to be returned when an error is injected |
15+
| statusCode | status to be returned when an error is injected |
16+
| errorRate | rate of requests that will return an error, represented as a float in the range `0.0` to `1.0` (default `0.0`) |
17+
| exclude | comma-separated list of services to be excluded from disruption |
18+
| port | port on which the requests will be intercepted |
19+
20+
<Blockquote mod="note">
21+
22+
`averageDelay` and `delayVariation` are applied to all requests affected by the fault, regardless of the value of `errorRate`. `statusCode` is returned only to a fraction of requests defined by `errorRate`.
23+
24+
</Blockquote>
25+
26+
## Example
27+
28+
This example defines a gRPC fault that introduces a delay of `50ms` in all requests and returns a status code `13` in `10%` of the requests.
29+
30+
```javascript
31+
const fault = {
32+
averageDelay: 50,
33+
statusCode: 10,
34+
errorRate: 0.1,
35+
};
36+
```
File renamed without changes.

src/data/markdown/docs/40 xk6-disruptor/03 API/02 PodDisruptor.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ To construct a `PodDisruptor`, use the [PodDisruptor() constructor](/javascript-
1111

1212
| Method | Description |
1313
| ------ | ----------- |
14+
| [PodDisruptor.injectGrpcFaults()](/javascript-api/xk6-disruptor/api/poddisruptor/injectgrpcfaults) | Inject [gRPC faults](/javascript-api/xk6-disruptor/api/faults/grpc) in the target Pods|
1415
| [PodDisruptor.injectHTTPFaults()](/javascript-api/xk6-disruptor/api/poddisruptor/injecthttpfaults) | Inject [HTTTP faults](/javascript-api/xk6-disruptor/api/faults/http) in the target Pods|
1516
| PodDisruptor.targets() | Returns the list of target Pods of the PodDisruptor |
1617

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
title: 'injectGrpcFaults()'
3+
excerpt: 'xk6-disruptor: PodDisruptor.injectGrpcFaults method'
4+
---
5+
6+
injectGrpcFaults injects gRPC faults in the requests served by a target Pod.
7+
8+
| Parameter | Description |
9+
| ---------- | ----------- |
10+
| fault | description of the [gRPC faults](/javascript-api/xk6-disruptor/api/faults/grpc) to be injected |
11+
| duration | duration of the disruption in seconds |
12+
| [options](#options) | options that control the injection of the fault |
13+
14+
15+
## options
16+
17+
The injection of the fault is controlled by the following options:
18+
19+
| Option | Description |
20+
| ------ | ----------- |
21+
| proxyPort | port the agent will use to listen for requests in the target pods ( default `8080`) |
22+
| iface | network interface where the agent will capture the traffic ( default `eth0`) |
23+
24+
25+
## Example
26+
27+
<!-- eslint-skip -->
28+
29+
```javascript
30+
const fault = {
31+
averageDelay: 50,
32+
statusCode: 13,
33+
errorRate: 0.1
34+
}
35+
disruptor.injectGrpcFaults(fault, 30)
36+
```
File renamed without changes.

src/data/markdown/docs/40 xk6-disruptor/03 API/03 ServiceDisruptor.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ To construct a `ServiceDisruptor`, use the [ServiceDisruptor() constructor](/jav
1212

1313
| Method | Description |
1414
| ------ | ----------- |
15+
| [ServiceDisruptor.injectGrpcFaults()](/javascript-api/xk6-disruptor/api/servicedisruptor/injectgrpcfaults) | Inject [gRPC faults](/javascript-api/xk6-disruptor/api/faults/Grpc) in the target Pods|
1516
| [ServiceDisruptor.injectHTTPFaults()](/javascript-api/xk6-disruptor/api/servicedisruptor/injecthttpfaults) | Inject [HTTTP faults](/javascript-api/xk6-disruptor/api/faults/http) in the target Pods|
1617

1718

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
title: 'injectGrpcFaults'
3+
excerpt: 'xk6-disruptor: ServiceDisruptor.injectGrpcFaults method'
4+
---
5+
6+
injectGrpcFaults injects gRPC faults in the requests served by a target Service.
7+
8+
| Parameters | Description |
9+
| ---------- | ----------- |
10+
| fault | description of the [gRPC faults](/javascript-api/xk6-disruptor/api/faults/grpc) to be injected |
11+
| duration | duration of the disruption in seconds |
12+
| [options](#options) | options that control the injection of the fault |
13+
14+
## Options
15+
16+
The injection of the fault is controlled by the following options:
17+
18+
| Option | Description |
19+
| ------ | ----------- |
20+
| proxyPort | port the agent will use to listen for requests in the target pods ( default `8080`) |
21+
| iface | network interface where the agent will capture the traffic ( default `eth0`) |
22+
23+
24+
## Example
25+
26+
<!-- eslint-skip -->
27+
28+
```javascript
29+
const fault = {
30+
averageDelay: 50,
31+
statusCode: 13,
32+
errorRate: 0.1
33+
}
34+
disruptor.injectGrpcFaults(fault, 30)
35+
```
File renamed without changes.

0 commit comments

Comments
 (0)