-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added chaos monkey setup #177
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,5 +14,8 @@ target/ | |
.idea | ||
*.iml | ||
|
||
# Visual Studio Code | ||
.factorypath | ||
|
||
# Branch switching | ||
generated/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Spring Boot Chaos Monkey Scripts | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I propose to mention this readme and this feature in the root readme file. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Sure! Just FYI I had to create |
||
|
||
You can read more about the possible configuration options [here](https://codecentric.github.io/chaos-monkey-spring-boot/latest/#_properties). | ||
|
||
## Scripts | ||
|
||
In order to active Spring Boot Chaos Monkey's assault options and component instrumentation, you need to call the project's API. For your convenience we're providing a script that turns on various watchers and attacks. To print out the usage description just call the script without any parameters. | ||
|
||
```bash | ||
$ ./scripts/chaos/call_chaos.sh | ||
usage: ./scripts/chaos/call_chaos.sh: <customers|visits|vets> <attacks_enable_exception|attacks_enable_killapplication|attacks_enable_latency|attacks_enable_memory|watcher_enable_component|watcher_enable_controller|watcher_enable_repository|watcher_enable_restcontroller|watcher_enable_service|watcher_disable> | ||
First pick either customers, visits or vets | ||
Then pick what to enable. Order matters! | ||
Example | ||
./scripts/chaos/call_chaos.sh visits attacks_enable_exception watcher_enable_restcontroller | ||
``` | ||
|
||
The script takes in at minimum 2 parameters. First provides the name of the application for which you want to turn on Chaos Monkey features. The subsequent ones will enable attacks and watchers. The name of the desired feature maps to a json file that gets updated to `http://localhost:${PORT}/actuator/chaosmonkey/assaults` and `http://localhost:${PORT}/actuator/chaosmonkey/watchers` respectively. Example of enabling exception assault via rest controllers for the visits microservice: | ||
|
||
```bash | ||
$ ./scripts/chaos/call_chaos.sh visits attacks_enable_exception watcher_enable_restcontroller | ||
``` | ||
|
||
The default assault configuration is set to fail every 5th request. That means that the first four will work as if Chaos Monkey was be disabled. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"latencyActive": false, | ||
"exceptionsActive": false, | ||
"killApplicationActive": false, | ||
"memoryActive": false | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"exceptionsActive": true, | ||
"level" : 5 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"killApplicationActive": true | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"latencyActive": true, | ||
"latencyRangeStart" : 1000, | ||
"latencyRangeEnd" : 10000 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"memoryActive": true, | ||
"level" : 5 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -o errexit | ||
set -o errtrace | ||
set -o nounset | ||
set -o pipefail | ||
|
||
ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | ||
|
||
function usage { | ||
echo "usage: $0: <customers|visits|vets> <attacks_enable_exception|attacks_enable_killapplication|attacks_enable_latency|attacks_enable_memory|watcher_enable_component|watcher_enable_controller|watcher_enable_repository|watcher_enable_restcontroller|watcher_enable_service|watcher_disable>" | ||
echo "First pick either customers, visits or vets" | ||
echo "Then pick what to enable. Order matters!" | ||
echo "Example" | ||
echo "./scripts/chaos/call_chaos.sh visits attacks_enable_exception watcher_enable_restcontroller" | ||
exit 1 | ||
} | ||
|
||
if [[ $# -lt 2 ]]; then | ||
usage | ||
fi | ||
|
||
export PORT="${PORT:-}" | ||
|
||
while [[ $# > 0 ]] | ||
do | ||
key="$1" | ||
case $1 in | ||
customers) | ||
PORT=8081 | ||
;; | ||
visits) | ||
PORT=8082 | ||
;; | ||
vets) | ||
PORT=8083 | ||
;; | ||
attacks*) | ||
( cd "${ROOT_DIR}" && curl "http://localhost:${PORT}/actuator/chaosmonkey/assaults" -H "Content-Type: application/json" --data @"${1}".json --fail ) | ||
;; | ||
watcher*) | ||
( cd "${ROOT_DIR}" && curl "http://localhost:${PORT}/actuator/chaosmonkey/watchers" -H "Content-Type: application/json" --data @"${1}".json --fail ) | ||
;; | ||
*) | ||
usage | ||
;; | ||
esac | ||
shift | ||
done |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"controller": false, | ||
"restController": false, | ||
"service": false, | ||
"repository": false, | ||
"component": false | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"component": true | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"controller": true | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"repository": true | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"restController": true | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"service": true | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -o errexit | ||
set -o errtrace | ||
set -o nounset | ||
set -o pipefail | ||
|
||
pkill -9 -f spring-petclinic || echo "Failed to kill any apps" | ||
|
||
docker-compose kill || echo "No docker containers are running" | ||
|
||
echo "Running infra" | ||
docker-compose up -d grafana-server prometheus-server tracing-server | ||
|
||
echo "Running apps" | ||
mkdir -p target | ||
nohup java -jar spring-petclinic-config-server/target/*.jar --server.port=8888 --spring.profiles.active=chaos-monkey > target/config-server.log 2>&1 & | ||
echo "Waiting for config server to start" | ||
sleep 20 | ||
nohup java -jar spring-petclinic-discovery-server/target/*.jar --server.port=8761 --spring.profiles.active=chaos-monkey > target/discovery-server.log 2>&1 & | ||
echo "Waiting for discovery server to start" | ||
sleep 20 | ||
nohup java -jar spring-petclinic-customers-service/target/*.jar --server.port=8081 --spring.profiles.active=chaos-monkey > target/customers-service.log 2>&1 & | ||
nohup java -jar spring-petclinic-visits-service/target/*.jar --server.port=8082 --spring.profiles.active=chaos-monkey > target/visits-service.log 2>&1 & | ||
nohup java -jar spring-petclinic-vets-service/target/*.jar --server.port=8083 --spring.profiles.active=chaos-monkey > target/vets-service.log 2>&1 & | ||
nohup java -jar spring-petclinic-api-gateway/target/*.jar --server.port=8080 --spring.profiles.active=chaos-monkey > target/gateway-service.log 2>&1 & | ||
nohup java -jar spring-petclinic-admin-server/target/*.jar --server.port=9090 --spring.profiles.active=chaos-monkey > target/admin-server.log 2>&1 & | ||
echo "Waiting for apps to start" | ||
sleep 60 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In prevision of next Spring Boot version upgrade, do you know how to handle them the spring boot chaos monkey library?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's what they write on their website (https://codecentric.github.io/chaos-monkey-spring-boot/#docs)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok thank you. So there is not one version of Chaos Monkey per version of Spring Boot. It will be easier for upgrades.