https://github.com/msfidelis/gin-chaos-monkey
:cocktail: :cocktail: :cocktail: - Chaos Monkey assalts middleware for Gin Gonic
https://github.com/msfidelis/gin-chaos-monkey
chaos-engineering chaos-monkey gin-gonic gin-middleware
Last synced: 7 months ago
JSON representation
:cocktail: :cocktail: :cocktail: - Chaos Monkey assalts middleware for Gin Gonic
- Host: GitHub
- URL: https://github.com/msfidelis/gin-chaos-monkey
- Owner: msfidelis
- License: mit
- Created: 2020-11-04T05:19:34.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2021-11-05T14:41:29.000Z (almost 4 years ago)
- Last Synced: 2025-04-12T00:17:08.253Z (7 months ago)
- Topics: chaos-engineering, chaos-monkey, gin-gonic, gin-middleware
- Language: Go
- Homepage:
- Size: 147 KB
- Stars: 20
- Watchers: 4
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Gin Chaos Monkey - Assault Middleware for Gin :cocktail: :cocktail: :cocktail:
## Contents
- [Gin Web Framework](https://github.com/gin-gonic/gin)
- [Installation](#installation)
- [Usage](#usage)
- [Assault types](#assault-types)
- [Environment variables configuration](#environment-variables-configuration)
- [Development](#development)
## Installation
```
go get -v github.com/msfidelis/gin-chaos-monkey
```
# Usage
## Basic Usage
```go
package main
import (
chaos "github.com/msfidelis/gin-chaos-monkey"
"github.com/gin-gonic/gin"
)
func main() {
r := gin.Default()
//Middlewares
r.Use(gin.Recovery())
r.Use(chaos.Load())
// Healthcheck
r.GET("/healthcheck", healthcheck.Ok)
r.Run()
}
```
## Specific Routes
```golang
package main
import (
"net/http"
"github.com/gin-gonic/gin"
chaos "github.com/msfidelis/gin-chaos-monkey"
)
func main() {
router := gin.Default()
//Enable Chaos Monkey in Specific Route
router.GET("/healthcheck/chaos", chaos.Load(), healthcheck.Ok)
router.GET("/healthcheck", healthcheck.Ok)
router.Run()
}
```
# ASSAULT TYPES
### LATENCY ASSAULT
This assault increase latency on response time for web requests. You can set `CHAOS_MONKEY_LATENCY_MAX_TIMEOUT` environment variable to customize a max time to increase in requests.
### EXCEPTION ASSAULT
This assault randomly returns 5xx errors for HTTP requests. You can set `CHAOS_MONKEY_EXCEPTION_HTTP_STATUS_CODE` to customize status codes to return in HTTP exception. Default: `503`
### APP KILLER ASSAULT
This assault randomly inject an `panic` exception on application runtime
### MEMORY ASSAULT
Increases the RAM consumption of the application
### CPU ASSAULT
Increases the CPU consumption of the application
# CONFIGURATION
## Enable Chaos Monkey Assalts
```bash
export CHAOS_MONKEY_ENABLED=true
export CHAOS_MONKEY_MODE=soft
export CHAOS_MONKEY_LATENCY=true
export CHAOS_MONKEY_LATENCY_MIN_TIME=5000
export CHAOS_MONKEY_LATENCY_MAX_TIME=10000
```
## Environment Variables Configuration
| VARIABLE | OPTIONS | DEFAULT |
| ----------------------------------------- | --------------------------| --------- |
| CHAOS_MONKEY_ENABLED | true/false | false |
| CHAOS_MONKEY_MODE | soft/hard/critical/hell | soft |
| CHAOS_MONKEY_LATENCY | true/false | false |
| CHAOS_MONKEY_LATENCY_MIN_TIME | miliseconds | max_time |
| CHAOS_MONKEY_LATENCY_MAX_TIME | miliseconds | 1000 |
| CHAOS_MONKEY_EXCEPTION | true/false | false |
| CHAOS_MONKEY_EXCEPTION_HTTP_STATUS_CODE | 5xx | 503 |
| CHAOS_MONKEY_APP_KILLER | true/false | false |
| CHAOS_MONKEY_MEMORY | true/false | false |
| CHAOS_MONKEY_CPU | true/false | false |
## Development
### Running Tests
```
go test -v
```