Fault Flag Go

A powerful fault injection library for Go applications, enabling controlled chaos engineering and resilience testing.

Features

  • 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

Installation

go get github.com/shovanmaity/fault-flag-go

Quick Start

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()
}

Usage

Basic Fault Injection

// 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)
}

HTTP Endpoint Registration

func setupRouter() {
    // Register endpoints for fault injection
    lib.RegisterEndpoint("/api/orders", "GET")
    lib.RegisterEndpoint("/api/orders", "POST")
}

Function Registration

func init() {
    // Explicitly register functions (optional, Run() does this automatically)
    lib.RegisterFunction("main.processOrder")
}

List Registered Components

// List registered functions
funcs := lib.ListFunction()

// List registered endpoints
endpoints := lib.ListEndpoint()

// List active faults
faults := lib.ListFault()

Configuration

The library requires two environment variables for emissary service integration:

  • APPLICATION_NAME: Name of your application
  • EMISSARY_URL: URL of the emissary service

Fault Types

Latency Fault

Adds artificial delay to function execution:

{
    "name": "Latency",
    "properties": {
        "function": "main.processOrder",
        "latency": "1000" // milliseconds
    }
}

Error Fault

Returns a specified error:

{
    "name": "Error",
    "properties": {
        "function": "main.processOrder",
        "message": "simulated error"
    }
}

Exception Fault

Triggers a panic:

{
    "name": "Exception",
    "properties": {
        "function": "main.processOrder",
        "message": "simulated panic"
    }
}

Custom Fault (BYOC)

Execute custom fault logic:

{
    "name": "BYOC",
    "properties": {
        "function": "main.processOrder"
    }
}

Testing

Run the test suite:

go test -v ./...