Documentation
¶
Index ¶
- Constants
- Variables
- func Chain(middlewares ...Middleware) func(Scenario) Scenario
- func SkipIfShort(t TB)
- func ToRunEvent(result Result, passed bool, startedAt time.Time) fabricmetrics.RunEvent
- func ToRunEventProto(result Result, passed bool, startedAt time.Time) *fabricv1.RunEvent
- type Config
- type FabricEmitHook
- type FabricRunEmit
- type LatencyStats
- type Middleware
- func WithBulkhead(maxConcurrent int) Middleware
- func WithCircuitBreaker(threshold float64, window, timeout time.Duration) Middleware
- func WithErrorRate(rate float64) Middleware
- func WithJitter(min, max time.Duration, rate float64) Middleware
- func WithLatency(d time.Duration, rate float64) Middleware
- func WithRetry(n int, backoff time.Duration) Middleware
- func WithStatusCode(code int, rate float64) Middleware
- func WithTimeout(d time.Duration) Middleware
- type Phase
- type PhaseType
- type Result
- type ResultHook
- type Scenario
- type TB
- type Test
- type ThresholdOutcome
- type ThresholdViolationError
- type Thresholds
Constants ¶
const ( // PhaseTypeConstant represents a constant arrival-rate phase. PhaseTypeConstant = model.PhaseTypeConstant // PhaseTypeRamp represents a linear ramp between two arrival rates. PhaseTypeRamp = model.PhaseTypeRamp // PhaseTypeStep represents discrete steps between two arrival rates. PhaseTypeStep = model.PhaseTypeStep // PhaseTypeSpike represents a temporary spike from a base rate to a peak rate. PhaseTypeSpike = model.PhaseTypeSpike )
Variables ¶
var ( ErrInjected = errors.New("pulse: injected fault") // ErrBulkheadFull is returned by WithBulkhead when the concurrency // limit is reached and the context expires before a slot opens. ErrBulkheadFull = errors.New("pulse: bulkhead full") )
ErrInjected is returned by WithErrorRate when a fault is injected.
var ErrCircuitOpen = errors.New("pulse: circuit open")
ErrCircuitOpen is returned when the circuit breaker is open and requests are being rejected to simulate cascading failures.
Functions ¶
func Chain ¶ added in v0.3.3
func Chain(middlewares ...Middleware) func(Scenario) Scenario
Chain applies middlewares to a Scenario in order. The first middleware is the outermost wrapper.
func SkipIfShort ¶ added in v0.3.2
func SkipIfShort(t TB)
SkipIfShort skips the test if -short flag is set.
func ToRunEvent ¶ added in v0.3.1
ToRunEvent converts a Pulse Result into a fabric metrics.RunEvent, making it compatible with other Algoryn ecosystem tools. The startedAt parameter should be the time the run began. If zero, time.Now() minus result.Duration is used as a best-effort approximation. Snapshot.Service is empty; use ToFabricRunEmit when you need a service name on the snapshot.
Types ¶
type Config ¶
type Config struct {
Phases []Phase
MaxConcurrency int
Thresholds Thresholds
// Service is optional metadata for Fabric MetricSnapshot.Service and RunCompleted payloads.
Service string
OnResult ResultHook // optional; nil means no-op
OnFabricEmit FabricEmitHook // optional; protobuf RunEvent + RunCompleted Event
}
Config holds execution configuration for a test.
type FabricEmitHook ¶ added in v0.3.7
FabricEmitHook is invoked after threshold evaluation with protobuf contracts for the Fabric stack. run carries fabric.v1.MetricSnapshot; completed is EVENT_TYPE_RUN_COMPLETED for tools like Beacon.
type FabricRunEmit ¶ added in v0.3.7
FabricRunEmit bundles the protobuf shapes Pulse emits for downstream Algoryn tools. RunEvent carries the full MetricSnapshot; RunCompleted is the fabric.v1.Event envelope (EVENT_TYPE_RUN_COMPLETED) for consumers such as Beacon.
func ToFabricRunEmit ¶ added in v0.3.7
ToFabricRunEmit builds a matched pair: full RunEvent proto and a RunCompleted fabric Event sharing the same run id. RunCompleted uses timestamppb.Now() for the envelope timestamp.
type LatencyStats ¶
type LatencyStats struct {
Min time.Duration
Mean time.Duration
P50 time.Duration
P90 time.Duration
P95 time.Duration
P99 time.Duration
Max time.Duration
}
LatencyStats contains aggregate latency data.
type Middleware ¶ added in v0.3.3
Middleware wraps a Scenario to add behavior before or after execution.
func WithBulkhead ¶ added in v0.3.5
func WithBulkhead(maxConcurrent int) Middleware
WithBulkhead returns a Middleware that limits the number of concurrent executions of a scenario.
func WithCircuitBreaker ¶ added in v0.3.6
func WithCircuitBreaker(threshold float64, window, timeout time.Duration) Middleware
WithCircuitBreaker returns a Middleware that simulates cascading failures by opening a circuit when the error rate within a time window exceeds the threshold.
func WithErrorRate ¶ added in v0.3.3
func WithErrorRate(rate float64) Middleware
WithErrorRate returns a Middleware that causes a percentage of requests to fail without calling the underlying Scenario.
func WithJitter ¶ added in v0.3.4
func WithJitter(min, max time.Duration, rate float64) Middleware
WithJitter returns a Middleware that adds random latency between min and max to a percentage of requests.
func WithLatency ¶ added in v0.3.3
func WithLatency(d time.Duration, rate float64) Middleware
WithLatency returns a Middleware that adds artificial latency to a percentage of requests.
func WithRetry ¶ added in v0.3.5
func WithRetry(n int, backoff time.Duration) Middleware
WithRetry returns a Middleware that retries a failed scenario up to n times with a fixed backoff between attempts.
func WithStatusCode ¶ added in v0.3.4
func WithStatusCode(code int, rate float64) Middleware
WithStatusCode returns a Middleware that forces a specific HTTP status code to be returned for a percentage of requests, without calling the underlying Scenario.
func WithTimeout ¶ added in v0.3.4
func WithTimeout(d time.Duration) Middleware
WithTimeout returns a Middleware that enforces a maximum duration for each scenario execution.
type Phase ¶
type Phase struct {
Type PhaseType
Duration time.Duration
ArrivalRate int
// From and To are the arrival rates (per second) at the start and end of a ramp or step phase.
From int
To int
// Steps is the number of discrete rate levels for PhaseTypeStep.
Steps int
// SpikeAt is when the spike starts; 0 means immediately.
SpikeAt time.Duration
// SpikeDuration is how long the spike lasts.
SpikeDuration time.Duration
}
Phase defines the minimal execution shape for the MVP.
func (Phase) IsConstant ¶
IsConstant reports whether p is a constant arrival-rate phase.
type Result ¶
type Result struct {
Total int64
Failed int64
Duration time.Duration
RPS float64
Latency LatencyStats
StatusCounts map[int]int64
ErrorCounts map[string]int64
ThresholdOutcomes []ThresholdOutcome `json:"-"`
}
Result contains the aggregated outcome of a test run.
type ResultHook ¶
ResultHook is an optional callback invoked after a test run completes. result contains the full aggregated metrics. passed is true when all configured thresholds were met.
type Scenario ¶
Scenario is the user-defined workload executed by Pulse. The int is an HTTP or application status code; use 0 when not applicable.
func Apply ¶ added in v0.3.3
func Apply(scenario Scenario, middlewares ...Middleware) Scenario
Apply wraps a Scenario with the given middlewares.
type TB ¶ added in v0.3.2
type TB interface {
Helper()
Fatalf(format string, args ...any)
Logf(format string, args ...any)
Skip(args ...any)
}
TB is the minimal testing interface required by Pulse helpers.
type ThresholdOutcome ¶
ThresholdOutcome records whether a configured threshold passed for a run.
type ThresholdViolationError ¶
ThresholdViolationError is returned when a configured threshold is exceeded. Description matches the corresponding ThresholdOutcome description (e.g. "mean_latency < 200ms").
func (*ThresholdViolationError) Error ¶
func (e *ThresholdViolationError) Error() string