Skip to content

Commit 1f69074

Browse files
authored
Merge pull request #2 from gunnargrosch/develop
Develop
2 parents 751825b + 97cba1c commit 1f69074

File tree

5 files changed

+667
-530
lines changed

5 files changed

+667
-530
lines changed

README.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Description
44

5-
`failure-cloudfunctions` is a small Node module for injecting failure into Google Cloud Functions (https://cloud.google.com/functions/). It offers a simple failure injection wrapper for your Cloud Functions handler where you then can choose to inject failure by setting the `failureMode` to `latency`, `exception`, `blacklist`, `diskspace` or `statuscode`. You control your failure injection using a secret in Secret Manager.
5+
`failure-cloudfunctions` is a small Node module for injecting failure into Google Cloud Functions (https://cloud.google.com/functions/). It offers a simple failure injection wrapper for your Cloud Functions handler where you then can choose to inject failure by setting the `failureMode` to `latency`, `exception`, `denylist`, `diskspace` or `statuscode`. You control your failure injection using a secret in Secret Manager.
66

77
## How to install
88

@@ -22,11 +22,11 @@ exports.handler = failureCloudFunctions(async (req, res) => {
2222
```
2323
4. Create a secret in Secret Manager.
2424
```json
25-
{"isEnabled": false, "failureMode": "latency", "rate": 1, "minLatency": 100, "maxLatency": 400, "exceptionMsg": "Exception message!", "statusCode": 404, "diskSpace": 100, "blacklist": ["storage.googleapis.com"]}
25+
{"isEnabled": false, "failureMode": "latency", "rate": 1, "minLatency": 100, "maxLatency": 400, "exceptionMsg": "Exception message!", "statusCode": 404, "diskSpace": 100, "denylist": ["storage.googleapis.com"]}
2626
```
2727
```bash
2828
gcloud beta secrets create <your-secret-name> --replication-policy="automatic"
29-
echo -n "{\"isEnabled\": false, \"failureMode\": \"latency\", \"rate\": 1, \"minLatency\": 100, \"maxLatency\": 400, \"exceptionMsg\": \"Exception message!\", \"statusCode\": 404, \"diskSpace\": 100, \"blacklist\": [\"storage.googleapis.com\"]}" | gcloud beta secrets versions add <your-secret-name> --data-file=-
29+
echo -n "{\"isEnabled\": false, \"failureMode\": \"latency\", \"rate\": 1, \"minLatency\": 100, \"maxLatency\": 400, \"exceptionMsg\": \"Exception message!\", \"statusCode\": 404, \"diskSpace\": 100, \"denylist\": [\"storage.googleapis.com\"]}" | gcloud beta secrets versions add <your-secret-name> --data-file=-
3030
```
3131
5. Add environment variables to your Cloud Function with values from above.
3232
```bash
@@ -45,13 +45,13 @@ Edit the values of your parameter in Secret Manager to use the failure injection
4545

4646
* `isEnabled: true` means that failure is injected into your Cloud Function.
4747
* `isEnabled: false` means that the failure injection module is disabled and no failure is injected.
48-
* `failureMode` selects which failure you want to inject. The options are `latency`, `exception`, `blacklist`, `diskspace` or `statuscode` as explained below.
48+
* `failureMode` selects which failure you want to inject. The options are `latency`, `exception`, `denylist`, `diskspace` or `statuscode` as explained below.
4949
* `rate` controls the rate of failure. 1 means that failure is injected on all invocations and 0.5 that failure is injected on about half of all invocations.
5050
* `minLatency` and `maxLatency` is the span of latency in milliseconds injected into your function when `failureMode` is set to `latency`.
5151
* `exceptionMsg` is the message thrown with the exception created when `failureMode` is set to `exception`.
5252
* `statusCode` is the status code returned by your function when `failureMode` is set to `statuscode`.
5353
* `diskSpace` is size in MB of the file created in tmp when `failureMode` is set to `diskspace`.
54-
* `blacklist` is an array of regular expressions, if a connection is made to a host matching one of the regular expressions it will be blocked.
54+
* `denylist` is an array of regular expressions, if a connection is made to a host matching one of the regular expressions it will be blocked.
5555

5656
## Example
5757

@@ -63,6 +63,12 @@ Inspired by Yan Cui's articles on latency injection for Google Cloud Functions (
6363

6464
## Changelog
6565

66+
### 2020-08-24 v0.3.0
67+
68+
* Changed mitm mode from connect to connection for quicker enable/disable of failure injection.
69+
* Renamed block list failure injection to denylist (breaking change for that failure mode).
70+
* Updated dependencies.
71+
6672
### 2020-03-01 v0.2.1
6773

6874
* Added permission info to documentation.

example/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"dependencies": {
3-
"failure-cloudfunctions": "^0.2.1"
3+
"failure-cloudfunctions": ""
44
}
55
}

lib/failure.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ var injectFailure = function (fn) {
4040
} else if (config.failureMode === 'diskspace') {
4141
console.log('Injecting disk space: ' + config.diskSpace + ' MB')
4242
childProcess.spawnSync('dd', ['if=/dev/zero', 'of=/tmp/diskspace-failure-' + Date.now() + '.tmp', 'count=1000', 'bs=' + config.diskSpace * 1000])
43-
} else if (config.failureMode === 'blacklist') {
44-
console.log('Injecting dependency failure through a network blackhole for blacklisted sites: ' + config.blacklist)
43+
} else if (config.failureMode === 'denylist') {
44+
console.log('Injecting dependency failure through a network block for denylisted sites: ' + config.denylist)
4545
let mitm = Mitm()
4646
let blRegexs = []
47-
config.blacklist.forEach(function (regexStr) {
47+
config.denylist.forEach(function (regexStr) {
4848
blRegexs.push(new RegExp(regexStr))
4949
})
50-
mitm.on('connect', function (socket, opts) {
50+
mitm.on('connection', function (socket, opts) {
5151
let block = false
5252
blRegexs.forEach(function (blRegex) {
5353
if (blRegex.test(opts.host)) {

0 commit comments

Comments
 (0)