Documentation
¶
Overview ¶
Package chaos lets tests deliberately fail or slow down CloudEmu services in controlled, time-bounded ways — so app code that handles cloud failure can be exercised without waiting for real cloud to misbehave.
Typical usage:
engine := chaos.New(config.RealClock{})
defer engine.Stop()
// Wrap a driver before handing it to the portable API or HTTP server
chaosS3 := chaos.WrapBucket(aws.S3, engine)
srv := awsserver.New(awsserver.Drivers{S3: chaosS3})
// Inject a failure scenario
engine.Apply(chaos.ServiceOutage("storage", 5*time.Second))
// SDK calls now fail for 5s, then recover automatically
Index ¶
- Variables
- func WrapBucket(inner storagedriver.Bucket, engine *Engine) storagedriver.Bucket
- func WrapCache(inner cachedriver.Cache, engine *Engine) cachedriver.Cache
- func WrapCompute(inner computedriver.Compute, engine *Engine) computedriver.Compute
- func WrapContainerRegistry(inner regdriver.ContainerRegistry, engine *Engine) regdriver.ContainerRegistry
- func WrapDNS(inner dnsdriver.DNS, engine *Engine) dnsdriver.DNS
- func WrapDatabase(inner dbdriver.Database, engine *Engine) dbdriver.Database
- func WrapEventBus(inner ebdriver.EventBus, engine *Engine) ebdriver.EventBus
- func WrapIAM(inner iamdriver.IAM, engine *Engine) iamdriver.IAM
- func WrapLoadBalancer(inner lbdriver.LoadBalancer, engine *Engine) lbdriver.LoadBalancer
- func WrapLogging(inner logdriver.Logging, engine *Engine) logdriver.Logging
- func WrapMessageQueue(inner mqdriver.MessageQueue, engine *Engine) mqdriver.MessageQueue
- func WrapMonitoring(inner mondriver.Monitoring, engine *Engine) mondriver.Monitoring
- func WrapNetworking(inner netdriver.Networking, engine *Engine) netdriver.Networking
- func WrapNotification(inner notifdriver.Notification, engine *Engine) notifdriver.Notification
- func WrapSecrets(inner secretsdriver.Secrets, engine *Engine) secretsdriver.Secrets
- func WrapServerless(inner serverlessdriver.Serverless, engine *Engine) serverlessdriver.Serverless
- type Active
- type Effect
- type Engine
- type Recorded
- type Scenario
- func Composite(scenarios ...Scenario) Scenario
- func LatencySpike(svc string, extra, duration time.Duration) Scenario
- func ProbabilisticFailure(svc, op string, err error, p float64, duration time.Duration) Scenario
- func ServiceOutage(svc string, duration time.Duration) Scenario
- func Throttle(svc, op string, qps int, duration time.Duration) Scenario
Constants ¶
This section is empty.
Variables ¶
var ErrChaosInjected = errors.New("chaos: injected failure")
ErrChaosInjected is the sentinel-style error type the engine wraps when a scenario provides no specific error. Callers can errors.Is against it.
Functions ¶
func WrapBucket ¶
func WrapBucket(inner storagedriver.Bucket, engine *Engine) storagedriver.Bucket
WrapBucket returns a storage driver that consults engine on the most-used data-plane operations. Less-used ops (lifecycle, multipart, tagging, versioning, CORS, encryption, policies, presigned URLs) delegate through without chaos for now — Phase 2 can broaden coverage.
func WrapCache ¶
func WrapCache(inner cachedriver.Cache, engine *Engine) cachedriver.Cache
WrapCache returns a cache driver that consults engine on data-plane calls.
func WrapCompute ¶
func WrapCompute(inner computedriver.Compute, engine *Engine) computedriver.Compute
WrapCompute returns a compute driver that consults engine on instance ops.
func WrapContainerRegistry ¶
func WrapContainerRegistry(inner regdriver.ContainerRegistry, engine *Engine) regdriver.ContainerRegistry
WrapContainerRegistry returns a container registry driver that consults engine on repository and image data-plane calls.
func WrapDatabase ¶
WrapDatabase returns a database driver that consults engine on item ops.
func WrapEventBus ¶
WrapEventBus returns an event bus driver that consults engine on bus, rule, and event publishing calls.
func WrapIAM ¶
WrapIAM returns an IAM driver that consults engine on principal/policy management and permission checks.
func WrapLoadBalancer ¶
func WrapLoadBalancer(inner lbdriver.LoadBalancer, engine *Engine) lbdriver.LoadBalancer
WrapLoadBalancer returns a load balancer driver that consults engine on LB / target-group / target operations.
func WrapLogging ¶
WrapLogging returns a logging driver that consults engine on log-group and event-ingest/query calls.
func WrapMessageQueue ¶
func WrapMessageQueue(inner mqdriver.MessageQueue, engine *Engine) mqdriver.MessageQueue
WrapMessageQueue returns a message queue driver that consults engine on queue and message data-plane calls.
func WrapMonitoring ¶
func WrapMonitoring(inner mondriver.Monitoring, engine *Engine) mondriver.Monitoring
WrapMonitoring returns a monitoring driver that consults engine on metric and alarm calls.
func WrapNetworking ¶
func WrapNetworking(inner netdriver.Networking, engine *Engine) netdriver.Networking
WrapNetworking returns a networking driver that consults engine on VPC/ Subnet/SecurityGroup data-plane and rule-mutation calls.
func WrapNotification ¶
func WrapNotification(inner notifdriver.Notification, engine *Engine) notifdriver.Notification
WrapNotification returns a notification driver that consults engine on every call.
func WrapSecrets ¶
func WrapSecrets(inner secretsdriver.Secrets, engine *Engine) secretsdriver.Secrets
WrapSecrets returns a secrets driver that consults engine on every call.
func WrapServerless ¶
func WrapServerless(inner serverlessdriver.Serverless, engine *Engine) serverlessdriver.Serverless
WrapServerless returns a serverless driver that consults engine on function lifecycle and invocation calls.
Types ¶
type Active ¶
type Active struct {
// contains filtered or unexported fields
}
Active is a handle returned by Apply that lets a caller cancel a scenario before its natural expiry.
type Effect ¶
Effect is what a chaos scenario produces for a given call. Either field may be the zero value (no latency / no error). When both are zero, the call proceeds normally.
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine is the registry and dispatcher of active scenarios. It's safe for concurrent use.
func New ¶
New returns an engine that uses clock for time-based scenario activation. Pass a config.FakeClock for deterministic tests.
func (*Engine) Apply ¶
Apply registers a scenario. The returned Active can be used to stop it before it expires.
func (*Engine) Check ¶
Check is what driver wrappers call on every operation. It returns the merged effect from every active scenario:
- latencies sum (worst case)
- the first non-nil error wins
Expired scenarios are dropped lazily here.
func (*Engine) Recorded ¶
Recorded returns a snapshot of every chaos event the engine has seen since the last Reset. Useful for post-test assertions.
type Scenario ¶
type Scenario interface {
// EffectOn returns the effect to apply to a given service+operation call
// at this moment, or a zero Effect if the scenario doesn't apply.
EffectOn(now time.Time, service, operation string) Effect
// Active returns true while the scenario is in its effective window.
// Once Active returns false, the engine drops it.
Active(now time.Time) bool
}
Scenario describes a chaos pattern. It's queried by the engine on every driver call to decide what (if anything) should happen to it.
func Composite ¶
Composite combines several scenarios into one. The merged Effect adds latencies and uses the first non-nil error.
func LatencySpike ¶
LatencySpike makes every call to service svc take an extra extra duration for the next duration window. Useful for testing client-side timeouts.
func ProbabilisticFailure ¶
ProbabilisticFailure injects err on a fraction p (0.0–1.0) of calls to service.operation, for the next duration window. If op is empty, applies to every operation on the service.
func ServiceOutage ¶
ServiceOutage simulates service svc being completely down for duration. Every call to it returns a ServiceUnavailable error during the window; after the window, calls succeed normally again.
Source Files
¶
- chaos.go
- random.go
- scenarios.go
- wrappers.go
- wrappers_cache.go
- wrappers_containerregistry.go
- wrappers_dns.go
- wrappers_eventbus.go
- wrappers_iam.go
- wrappers_loadbalancer.go
- wrappers_logging.go
- wrappers_messagequeue.go
- wrappers_monitoring.go
- wrappers_networking.go
- wrappers_notification.go
- wrappers_secrets.go
- wrappers_serverless.go