Documentation
¶
Index ¶
- Constants
- func Middleware(store *FaultStore) func(echo.HandlerFunc) echo.HandlerFunc
- func RegisterRoutes(group *echo.Group, store *FaultStore, registry *service.Registry)
- type ActivityEvent
- type FaultError
- type FaultRule
- type FaultStore
- func (s *FaultStore) AppendRules(rules []FaultRule)
- func (s *FaultStore) DeleteRuleByIndex(index int)
- func (s *FaultStore) DeleteRules(rules []FaultRule)
- func (s *FaultStore) GetActivity() []ActivityEvent
- func (s *FaultStore) GetEffects() NetworkEffects
- func (s *FaultStore) GetRules() []FaultRule
- func (s *FaultStore) Match(svc, op, region string) (FaultRule, bool)
- func (s *FaultStore) RecordActivity(event ActivityEvent)
- func (s *FaultStore) SetEffects(effects NetworkEffects)
- func (s *FaultStore) SetRules(rules []FaultRule)
- type LatencyRange
- type NetworkEffects
Constants ¶
const HeaderDashboard = "X-Gopherstack-Dashboard"
HeaderDashboard is the HTTP request header that dashboard clients set to bypass chaos fault injection and network effects. When this header is present with the value "true", the chaos middleware passes the request through unchanged.
Variables ¶
This section is empty.
Functions ¶
func Middleware ¶
func Middleware(store *FaultStore) func(echo.HandlerFunc) echo.HandlerFunc
Middleware returns an Echo middleware that evaluates fault rules and network effects from the provided FaultStore against each incoming AWS API request.
The middleware is intended to be registered via Registry.Use() so that it runs as an outer wrapper around the telemetry+handler chain. It extracts the AWS service, operation, and region directly from the HTTP request headers — specifically the SigV4 Authorization header (for service and region) and the X-Amz-Target header (for JSON-protocol service operations) — so that it does not depend on any context values that are set only after the handler is called.
Request lifecycle when a fault fires:
- Middleware extracts service / operation / region from request headers.
- FaultStore.Match selects the first matching rule.
- FaultRule.ShouldTrigger applies the probability check.
- If triggered, an error response is written and the chain is short-circuited.
Network effects (latency) are applied regardless of fault injection and run before the rest of the handler chain.
func RegisterRoutes ¶
func RegisterRoutes(group *echo.Group, store *FaultStore, registry *service.Registry)
RegisterRoutes mounts the chaos REST API under the /_gopherstack/chaos prefix.
- GET /_gopherstack/chaos/query — return combined state (faults + effects + activity)
- GET /_gopherstack/chaos/faults — return current fault rules
- POST /_gopherstack/chaos/faults — replace entire fault configuration
- PATCH /_gopherstack/chaos/faults — append rules to existing configuration
- DELETE /_gopherstack/chaos/faults — remove matching rules
- POST /_gopherstack/chaos/faults/clear — clear all fault rules
- DELETE /_gopherstack/chaos/faults/by-index — remove a fault rule by index
- GET /_gopherstack/chaos/effects — return current network effect settings
- POST /_gopherstack/chaos/effects — update network effect configuration
- POST /_gopherstack/chaos/effects/reset — reset network effects to defaults
- GET /_gopherstack/chaos/targets — return auto-discovered injectable targets
- GET /_gopherstack/chaos/activity — return recent fault injection events
Types ¶
type ActivityEvent ¶
type ActivityEvent struct {
Timestamp time.Time `json:"timestamp"`
Service string `json:"service"`
Operation string `json:"operation"`
Region string `json:"region"`
FaultApplied string `json:"faultApplied"`
Probability float64 `json:"probability"`
Triggered bool `json:"triggered"`
}
ActivityEvent records a single fault injection event emitted by the middleware.
type FaultError ¶
FaultError defines a custom HTTP error response returned when a fault is triggered.
type FaultRule ¶
type FaultRule struct {
Error *FaultError `json:"error,omitempty"`
Service string `json:"service,omitempty"`
Region string `json:"region,omitempty"`
Operation string `json:"operation,omitempty"`
Probability float64 `json:"probability,omitempty"`
}
FaultRule defines a single fault injection rule. All fields are optional; omitting a field means "match any". Rules are evaluated sequentially; the first match wins.
func (FaultRule) EffectiveError ¶
func (r FaultRule) EffectiveError() FaultError
EffectiveError returns the FaultError to use, falling back to the default.
func (FaultRule) ShouldTrigger ¶
ShouldTrigger reports whether this fault should fire based on its probability. A probability of 0 is treated as 1.0 (always fire).
type FaultStore ¶
type FaultStore struct {
// contains filtered or unexported fields
}
FaultStore is a thread-safe store for fault rules and network effects.
func (*FaultStore) AppendRules ¶
func (s *FaultStore) AppendRules(rules []FaultRule)
AppendRules appends rules to the existing rule list.
func (*FaultStore) DeleteRuleByIndex ¶
func (s *FaultStore) DeleteRuleByIndex(index int)
DeleteRuleByIndex removes the fault rule at the given index. If the index is out of range, the call is a no-op.
func (*FaultStore) DeleteRules ¶
func (s *FaultStore) DeleteRules(rules []FaultRule)
DeleteRules removes rules that match any rule in the provided list. Two rules match when all non-empty fields are equal.
func (*FaultStore) GetActivity ¶
func (s *FaultStore) GetActivity() []ActivityEvent
GetActivity returns a copy of the activity log in reverse-chronological order (newest first).
func (*FaultStore) GetEffects ¶
func (s *FaultStore) GetEffects() NetworkEffects
GetEffects returns a copy of the current network effects.
func (*FaultStore) GetRules ¶
func (s *FaultStore) GetRules() []FaultRule
GetRules returns a copy of the current fault rules.
func (*FaultStore) Match ¶
func (s *FaultStore) Match(svc, op, region string) (FaultRule, bool)
Match finds the first fault rule that matches the given service, operation, and region. Returns the matched rule and true, or a zero FaultRule and false if no rule matches.
func (*FaultStore) RecordActivity ¶
func (s *FaultStore) RecordActivity(event ActivityEvent)
RecordActivity appends an activity event to the ring buffer. When the buffer exceeds activityLogMaxSize, the oldest entries are discarded. A fresh backing slice is allocated to allow the GC to reclaim old entries.
func (*FaultStore) SetEffects ¶
func (s *FaultStore) SetEffects(effects NetworkEffects)
SetEffects replaces the current network effects.
func (*FaultStore) SetRules ¶
func (s *FaultStore) SetRules(rules []FaultRule)
SetRules replaces the entire fault rule list.
type LatencyRange ¶
LatencyRange defines a min/max range for randomized latency.
type NetworkEffects ¶
type NetworkEffects struct {
LatencyRange *LatencyRange `json:"latencyRange,omitempty"`
Latency int `json:"latency,omitempty"`
Jitter int `json:"jitter,omitempty"`
}
NetworkEffects defines dynamic network simulation parameters. This supersedes the static LATENCY_MS configuration at runtime when any field is non-zero.
func (NetworkEffects) TotalDelayMs ¶
func (n NetworkEffects) TotalDelayMs() int
TotalDelayMs computes the total simulated delay in milliseconds from the network effects configuration. Returns 0 when no delay is configured.