Documentation
¶
Index ¶
- Constants
- func BreakingReason(s StageMetrics, t config.StressThresholds) string
- func Stages(r config.StressRamp) []int
- func WithDefaults(t config.StressThresholds) config.StressThresholds
- type Analysis
- type Engine
- type EnvironmentInfo
- type LatencyReport
- type Outcome
- type Plan
- type Point
- type PointReport
- type RampReport
- type Report
- type RunInfo
- type Runner
- type StageMetrics
- type StageReport
- type Target
- type TargetReport
- type ThresholdsReport
- type ToolInfo
Constants ¶
const ( // ReportSchemaVersion is bumped on any breaking change to the JSON report. ReportSchemaVersion = 1 // ModePipeline means gtool started the mocks and the app; ModeTargetURL // means the load hit an external --target-url. ModePipeline = "pipeline" ModeTargetURL = "target-url" )
const (
// DefaultReportsPath is used when stress-config.reports-path is empty.
DefaultReportsPath = "test/stress/reports"
)
Variables ¶
This section is empty.
Functions ¶
func BreakingReason ¶
func BreakingReason(s StageMetrics, t config.StressThresholds) string
BreakingReason reports why a stage is past the breaking point, or "" when it is not.
func Stages ¶
func Stages(r config.StressRamp) []int
Stages expands a ramp into the requested RPS of each stage. The last stage is always max-rps, even when the step does not land on it.
func WithDefaults ¶
func WithDefaults(t config.StressThresholds) config.StressThresholds
WithDefaults fills the zero-valued thresholds with the defaults.
Types ¶
type Analysis ¶
type Analysis struct {
Baseline *StageMetrics
Degradation *Point
Breaking *Point
// MaxSustainedRPS is the highest requested RPS completed without
// reaching the breaking point (0 when the first stage already broke).
MaxSustainedRPS int
Warnings []string
}
Analysis is the outcome of evaluating the stages against the thresholds.
func Detect ¶
func Detect(stages []StageMetrics, t config.StressThresholds) Analysis
Detect finds the degradation and breaking points. The first stage is the baseline. A run that breaks without degrading first reports the breaking stage as the degradation point too.
func (Analysis) MeetsMinimum ¶
MeetsMinimum reports whether the sustained load reaches min-acceptable-rps (always true when no minimum is configured).
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine generates HTTP load in-process with vegeta.
func NewEngine ¶
NewEngine creates an engine whose HTTP client (keep-alive, high idle connection limit) is shared by every stage, so connections survive between stages.
func (*Engine) Ramp ¶
func (e *Engine) Ramp(ctx context.Context, baseURL string, targets []Target, stages []int, stageDuration time.Duration, shouldStop func(StageMetrics) bool) ([]StageMetrics, error)
Ramp runs the stages in order and stops early once shouldStop reports the breaking point. It returns the stages that completed.
func (*Engine) RunStage ¶
func (e *Engine) RunStage(ctx context.Context, tr vegeta.Targeter, rps int, d time.Duration) (StageMetrics, error)
RunStage attacks at a constant rate for the given duration. A cancelled context stops the attack; the metrics collected so far are returned with the context error.
type EnvironmentInfo ¶
type EnvironmentInfo struct {
Hostname string `json:"hostname"`
OS string `json:"os"`
Arch string `json:"arch"`
CPUs int `json:"cpus"`
GoVersion string `json:"go-version"`
}
EnvironmentInfo describes the host that generated the load; results are relative to it.
type LatencyReport ¶
type LatencyReport struct {
Mean float64 `json:"mean"`
P50 float64 `json:"p50"`
P95 float64 `json:"p95"`
P99 float64 `json:"p99"`
Max float64 `json:"max"`
}
LatencyReport holds latencies in milliseconds.
type Plan ¶
Plan is the resolved list of targets plus resolution warnings.
func ResolveTargets ¶
func ResolveTargets(sc *config.StressConfig) (*Plan, error)
ResolveTargets builds the target plan from the OpenAPI contract and the explicit `targets` block. Explicit targets replace spec operations with the same method and full path.
type PointReport ¶
type PointReport struct {
RPS int `json:"rps"`
Stage int `json:"stage"`
Reason string `json:"reason"`
}
PointReport is a degradation or breaking point.
type RampReport ¶
type RampReport struct {
StartRPS int `json:"start-rps"`
StepRPS int `json:"step-rps"`
StepDuration string `json:"step-duration"`
MaxRPS int `json:"max-rps"`
}
RampReport mirrors the configured ramp.
type Report ¶
type Report struct {
SchemaVersion int `json:"schema-version"`
Generator ToolInfo `json:"generator"`
Environment EnvironmentInfo `json:"environment"`
Mode string `json:"mode"`
StartedAt time.Time `json:"started-at"`
GeneratedAt time.Time `json:"generated-at"`
DurationMs float64 `json:"duration-ms"`
TargetURL string `json:"target-url"`
Ramp RampReport `json:"ramp"`
Thresholds ThresholdsReport `json:"thresholds"`
MinAcceptableRPS int `json:"min-acceptable-rps"`
Targets []TargetReport `json:"targets"`
Stages []StageReport `json:"stages"`
Degradation *PointReport `json:"degradation-point"`
Breaking *PointReport `json:"breaking-point"`
MaxSustainedRPS int `json:"max-sustained-rps"`
Passed bool `json:"passed"`
Warnings []string `json:"warnings"`
}
Report is the stable, serialized outcome of a stress run.
func NewReport ¶
func NewReport(run RunInfo, sc *config.StressConfig, plan *Plan, stages []StageMetrics, a Analysis) *Report
NewReport assembles the report of a run.
func (*Report) WriteFiles ¶
WriteFiles writes stress-report.json and stress-report.html into dir and returns their paths.
type Runner ¶
type Runner struct {
// contains filtered or unexported fields
}
Runner resolves the targets, ramps the load, detects the points and writes the reports. It satisfies the orchestrator TestRunner, so the pipeline runs it in place of the Karate suite.
func NewRunner ¶
NewRunner creates a stress runner. targetURL overrides the app address (http://localhost:<app-config.port>) when set; tool identifies the gtool build in the reports.
type StageMetrics ¶
type StageMetrics struct {
RequestedRPS int
Duration time.Duration
Requests uint64
AchievedRPS float64
Throughput float64
P50 time.Duration
P95 time.Duration
P99 time.Duration
Max time.Duration
Mean time.Duration
ServerErrors int
NetworkErrors int
ClientErrors int
ErrorRate float64
ClientErrorRate float64
StatusCodes map[string]int
Errors []string
}
StageMetrics is the outcome of one ramp stage. Network errors (no HTTP response: timeouts, refused connections) and 5xx count towards ErrorRate; 4xx are tracked apart so badly resolved targets do not fake a breaking point.
type StageReport ¶
type StageReport struct {
RequestedRPS int `json:"requested-rps"`
DurationMs float64 `json:"duration-ms"`
Requests uint64 `json:"requests"`
AchievedRPS float64 `json:"achieved-rps"`
ThroughputRPS float64 `json:"throughput-rps"`
LatencyMs LatencyReport `json:"latency-ms"`
ErrorRate float64 `json:"error-rate"`
ClientErrorRate float64 `json:"client-error-rate"`
ServerErrors int `json:"server-errors"`
NetworkErrors int `json:"network-errors"`
ClientErrors int `json:"client-errors"`
StatusCodes map[string]int `json:"status-codes"`
Errors []string `json:"errors"`
}
StageReport is the serialized form of StageMetrics.
type Target ¶
type Target struct {
Name string
Method string
// Path is the full request path template, base path included.
Path string
// URLs are rendered path+query variants, rotated per request so every
// configured param value is exercised.
URLs []string
Header http.Header
Body []byte
Weight int
Source string
}
Target is one resolved endpoint the load is distributed across.
type TargetReport ¶
type TargetReport struct {
Name string `json:"name"`
Method string `json:"method"`
Path string `json:"path"`
Weight int `json:"weight"`
Source string `json:"source"`
}
TargetReport describes one target of the run.
type ThresholdsReport ¶
type ThresholdsReport struct {
DegradationLatencyFactor float64 `json:"degradation-latency-factor"`
DegradationP95Ms int `json:"degradation-p95-ms"`
BreakErrorRate float64 `json:"break-error-rate"`
}
ThresholdsReport holds the effective thresholds (defaults applied).