stress

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: Apache-2.0 Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
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"
)
View Source
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

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

func (a Analysis) MeetsMinimum(minRPS int) bool

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

func NewEngine(logger *zap.Logger) *Engine

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 Outcome

type Outcome struct {
	Report   *Report
	JSONPath string
	HTMLPath string
}

Outcome is the result of the last stress run.

type Plan

type Plan struct {
	Targets  []Target
	Warnings []string
}

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 Point

type Point struct {
	RPS    int
	Stage  int
	Reason string
}

Point marks the first stage where a condition was observed.

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

func (r *Report) WriteFiles(dir string) (string, string, error)

WriteFiles writes stress-report.json and stress-report.html into dir and returns their paths.

func (*Report) WriteHTML

func (r *Report) WriteHTML(w io.Writer) error

WriteHTML renders the self-contained HTML report.

func (*Report) WriteJSON

func (r *Report) WriteJSON(w io.Writer) error

WriteJSON writes the report as indented JSON.

func (*Report) WriteSummary

func (r *Report) WriteSummary(w io.Writer) error

WriteSummary prints the per-stage table, both points and the gate verdict.

type RunInfo

type RunInfo struct {
	TargetURL string
	Mode      string
	StartedAt time.Time
	Tool      ToolInfo
}

RunInfo is the run context recorded in the report.

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

func NewRunner(targetURL string, tool ToolInfo, logger *zap.Logger) *Runner

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.

func (*Runner) Outcome

func (r *Runner) Outcome() *Outcome

Outcome returns the result of the last completed run, or nil.

func (*Runner) Run

func (r *Runner) Run(ctx context.Context, cfg *config.Config) (*plugin.TestResult, error)

Run executes the stress test. The returned result has one check, the min-acceptable-rps gate.

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).

type ToolInfo

type ToolInfo struct {
	Name       string `json:"name"`
	Version    string `json:"version"`
	Commit     string `json:"commit"`
	BuildDate  string `json:"build-date"`
	Repository string `json:"repository"`
}

ToolInfo identifies the gtool build that produced a report.

Jump to

Keyboard shortcuts

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