chaos

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// ErrorProbability is the probability of injecting an error (0.0 - 1.0).
	ErrorProbability float64
	// InjectedError is the error to be returned when an error is injected.
	InjectedError error
	// LatencyProbability is the probability of injecting latency (0.0 - 1.0).
	LatencyProbability float64
	// LatencyDuration is the duration of the latency to be injected.
	LatencyDuration time.Duration
}

Config represents the configuration for the chaos injector.

type Injector

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

Injector is the chaos injector that can inject synthetic faults and latency.

func NewInjector

func NewInjector(cfg Config) *Injector

NewInjector creates a new chaos injector with the provided configuration.

func NewInjectorWithRNG

func NewInjectorWithRNG(cfg Config, rng RNG) *Injector

NewInjectorWithRNG creates a new chaos injector with the provided configuration and RNG.

func (*Injector) Execute

func (i *Injector) Execute(ctx context.Context, action func() error) error

Execute wraps an action and injects synthetic faults and latency based on the configuration.

type RNG

type RNG interface {
	// Float64 returns a random float64 in the range [0.0, 1.0).
	Float64() float64
}

RNG defines the interface for randomization, allowing for mock implementations in tests.

Jump to

Keyboard shortcuts

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