chaos

package
v1.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 2, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package chaos provides chaos engineering capabilities for TokMan

Package chaos provides additional chaos experiments

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BlastRadius

func BlastRadius(experiment *Experiment, services []string) map[string]float64

BlastRadius calculates blast radius

func CascadingFailure

func CascadingFailure(ctx context.Context, config CascadeConfig) error

CascadingFailure simulates cascading failures

func DNSChaos

func DNSChaos(ctx context.Context, config DNSConfig) error

DNSChaos creates DNS resolution failures

func DependencyFailure

func DependencyFailure(ctx context.Context, config DependencyConfig) error

DependencyFailure simulates external dependency failures

func DiskFailure

func DiskFailure(ctx context.Context, config DiskConfig) error

DiskFailure simulates disk failures

func NetworkPartition

func NetworkPartition(ctx context.Context, config PartitionConfig) error

NetworkPartition creates network partition between services

func StandardFaultHandlers

func StandardFaultHandlers() map[ExperimentType]FaultHandler

StandardFaultHandlers returns default fault handlers

func TimeDrift

func TimeDrift(ctx context.Context, config TimeConfig) error

TimeDrift simulates clock skew

Types

type CascadeConfig

type CascadeConfig struct {
	Services     []string
	DelayBetween time.Duration
	FailureType  string
}

CascadeConfig holds cascading failure configuration

type ChaosTemplate

type ChaosTemplate struct {
	Name          string
	Description   string
	Type          ExperimentType
	DefaultConfig map[string]interface{}
	Setup         func() error
	Execute       func(ctx context.Context, config map[string]interface{}) error
	Teardown      func() error
}

ChaosTemplate represents reusable chaos experiment templates

func StandardTemplates

func StandardTemplates() []ChaosTemplate

StandardTemplates returns standard chaos templates

type DNSConfig

type DNSConfig struct {
	Domains     []string
	FailureRate float64
	Duration    time.Duration
}

DNSConfig holds DNS chaos configuration

type DependencyConfig

type DependencyConfig struct {
	Dependencies []string
	Duration     time.Duration
	FailureType  string // timeout, error, slow
}

DependencyConfig holds dependency failure configuration

type DiskConfig

type DiskConfig struct {
	Path        string
	FailureRate float64
	Duration    time.Duration
}

DiskConfig holds disk failure configuration

type Engine

type Engine struct {
	// contains filtered or unexported fields
}

Engine manages chaos experiments

func NewEngine

func NewEngine() *Engine

NewEngine creates a chaos engineering engine

func (*Engine) GetExperiment

func (e *Engine) GetExperiment(id string) (*Experiment, error)

GetExperiment returns experiment details

func (*Engine) GetStatus

func (e *Engine) GetStatus(id string) (Status, error)

GetStatus returns experiment status

func (*Engine) ListExperiments

func (e *Engine) ListExperiments() []*Experiment

ListExperiments returns all experiments

func (*Engine) RegisterExperiment

func (e *Engine) RegisterExperiment(ex *Experiment) error

RegisterExperiment adds an experiment

func (*Engine) RegisterHandler

func (e *Engine) RegisterHandler(t ExperimentType, h FaultHandler)

RegisterHandler registers a fault handler

func (*Engine) StartExperiment

func (e *Engine) StartExperiment(ctx context.Context, id string) error

StartExperiment begins a chaos experiment

func (*Engine) StopExperiment

func (e *Engine) StopExperiment(id string) error

StopExperiment stops a running experiment

type Experiment

type Experiment struct {
	ID          string
	Name        string
	Description string
	Type        ExperimentType
	Config      FaultConfig
	Scope       ScopeConfig
	Schedule    ScheduleConfig
	Safety      SafetyConfig
	// contains filtered or unexported fields
}

Experiment defines a chaos experiment

func NewExperiment

func NewExperiment(name string, t ExperimentType) *Experiment

NewExperiment creates a new experiment with sensible defaults

type ExperimentSchedule

type ExperimentSchedule struct {
	Experiments []ScheduledExperiment
}

ExperimentSchedule schedules chaos experiments

func Schedule

func Schedule(experiments []*Experiment, interval time.Duration) *ExperimentSchedule

Schedule creates a schedule

type ExperimentType

type ExperimentType string

ExperimentType defines the type of chaos experiment

const (
	TypeLatency    ExperimentType = "latency"
	TypeError      ExperimentType = "error"
	TypeMemory     ExperimentType = "memory"
	TypeCPU        ExperimentType = "cpu"
	TypeNetwork    ExperimentType = "network"
	TypeDisk       ExperimentType = "disk"
	TypeKill       ExperimentType = "kill"
	TypeTimeDrift  ExperimentType = "time_drift"
	TypeDependency ExperimentType = "dependency"
)

type FaultConfig

type FaultConfig struct {
	Probability float64 // 0.0 to 1.0
	Duration    time.Duration
	Intensity   float64 // 0.0 to 1.0
	Target      string  // specific target identifier
	Attributes  map[string]interface{}
}

FaultConfig holds fault injection configuration

type FaultHandler

type FaultHandler func(ctx context.Context, config FaultConfig) error

FaultHandler is a function that injects a specific type of fault

type GameDayConfig

type GameDayConfig struct {
	Name      string
	Scenarios []GameDayScenario
	Duration  time.Duration
}

GameDayConfig holds game day configuration

type GameDayResult

type GameDayResult struct {
	StartTime time.Time
	EndTime   time.Time
	Scenarios []ScenarioResult
}

GameDayResult holds game day results

func GameDay

func GameDay(ctx context.Context, config GameDayConfig) (*GameDayResult, error)

GameDay runs a chaos game day

type GameDayScenario

type GameDayScenario struct {
	Name         string
	Experiment   *Experiment
	ExpectedMTTR time.Duration
}

GameDayScenario represents a game day scenario

type PartitionConfig

type PartitionConfig struct {
	Source      string
	Destination string
	Duration    time.Duration
	Direction   string // one-way or two-way
}

PartitionConfig holds partition configuration

type SafetyConfig

type SafetyConfig struct {
	AutoRollback bool
	MaxDuration  time.Duration
	AbortOnError bool
	HealthCheck  func() bool
	KillSwitch   chan struct{}
}

SafetyConfig defines safety mechanisms

type ScenarioResult

type ScenarioResult struct {
	Name      string
	StartTime time.Time
	EndTime   time.Time
	Success   bool
	Error     string
	MTTR      time.Duration
}

ScenarioResult represents scenario results

type ScheduleConfig

type ScheduleConfig struct {
	StartTime  time.Time
	EndTime    time.Time
	Cron       string
	Duration   time.Duration
	Continuous bool
}

ScheduleConfig defines when to run the experiment

type ScheduledExperiment

type ScheduledExperiment struct {
	Experiment *Experiment
	Schedule   time.Time
	Repeat     bool
	Interval   time.Duration
}

ScheduledExperiment represents a scheduled experiment

type ScopeConfig

type ScopeConfig struct {
	Services   []string
	Instances  []string
	Percentage float64 // percentage of targets affected
	Tags       map[string]string
}

ScopeConfig defines the blast radius

type State

type State string

State represents experiment state

const (
	StatePending   State = "pending"
	StateRunning   State = "running"
	StatePaused    State = "paused"
	StateCompleted State = "completed"
	StateFailed    State = "failed"
	StateAborted   State = "aborted"
)

type Status

type Status struct {
	State     State
	StartTime time.Time
	EndTime   time.Time
	Runs      int
	Successes int
	Failures  int
	LastError error
}

Status represents experiment status

type TimeConfig

type TimeConfig struct {
	Offset   time.Duration
	Duration time.Duration
}

TimeConfig holds time drift configuration

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL