A powerful fault injection library for Go applications, enabling controlled chaos engineering and resilience testing.
-
Multiple Fault Types:
- Latency Injection
- Error Injection
- Exception (Panic) Injection
- Custom Fault Injection (BYOC - Bring Your Own Chaos)
-
HTTP Integration:
- Endpoint Registration
- Method-specific Fault Injection
- Automatic Discovery
-
Function-Level Control:
- Automatic Function Discovery
- Targeted Fault Injection
- Runtime Function Registration
-
Distributed Coordination:
- Emissary Service Integration
- Periodic State Synchronization
- Cross-Instance Fault Management
go get github.com/shovanmaity/fault-flag-go
package main
import (
"github.com/shovanmaity/fault-flag-go/lib"
)
func main() {
// Initialize the library
lib.Enable()
// Your application code...
doSomething()
}
func doSomething() error {
// Run will automatically register this function and check for active faults
return lib.Run()
}
// Inject latency, error, or exception faults
func processOrder() error {
return lib.Run()
}
// Custom fault injection
func processPayment() error {
customFault := func() bool {
// Your custom fault logic here
return true // Return true if fault was injected
}
return lib.Run(customFault)
}
func setupRouter() {
// Register endpoints for fault injection
lib.RegisterEndpoint("/api/orders", "GET")
lib.RegisterEndpoint("/api/orders", "POST")
}
func init() {
// Explicitly register functions (optional, Run() does this automatically)
lib.RegisterFunction("main.processOrder")
}
// List registered functions
funcs := lib.ListFunction()
// List registered endpoints
endpoints := lib.ListEndpoint()
// List active faults
faults := lib.ListFault()
The library requires two environment variables for emissary service integration:
APPLICATION_NAME
: Name of your applicationEMISSARY_URL
: URL of the emissary service
Adds artificial delay to function execution:
{
"name": "Latency",
"properties": {
"function": "main.processOrder",
"latency": "1000" // milliseconds
}
}
Returns a specified error:
{
"name": "Error",
"properties": {
"function": "main.processOrder",
"message": "simulated error"
}
}
Triggers a panic:
{
"name": "Exception",
"properties": {
"function": "main.processOrder",
"message": "simulated panic"
}
}
Execute custom fault logic:
{
"name": "BYOC",
"properties": {
"function": "main.processOrder"
}
}
Run the test suite:
go test -v ./...