Help us shape the future of Go! Take the 2026 Go Developer Survey

loadtest

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HeaderDivergeRoutingKey = "x-diverge-routing-key"
	DefaultConcurrency      = 10
	DefaultTimeout          = 5 * time.Second
	DefaultDuration         = 10 * time.Second
)

Variables

This section is empty.

Functions

func FormatJSON

func FormatJSON(w io.Writer, comp *ComparisonResult) error

FormatJSON outputs the comparison result as indented JSON.

func FormatTable

func FormatTable(w io.Writer, comp *ComparisonResult) error

FormatTable outputs the load test results in human-readable tabular form.

func IsProhibitedHost

func IsProhibitedHost(hostname string) bool

IsProhibitedHost checks whether a hostname matches known cloud provider metadata endpoints.

func IsProhibitedIP

func IsProhibitedIP(ip net.IP) bool

IsProhibitedIP checks whether an IP address is a link-local address or cloud metadata IP.

func ValidateTargetURL

func ValidateTargetURL(targetURL string) error

ValidateTargetURL validates that targetURL has an http or https scheme, a non-empty host, does not target cloud metadata or link-local endpoints, and conforms to DIVERGE_ALLOWED_HOSTS if configured.

Types

type ComparisonResult

type ComparisonResult struct {
	Candidate           *Result       `json:"candidate"`
	Baseline            *Result       `json:"baseline,omitempty"`
	P99Delta            time.Duration `json:"p99_delta,omitempty"`
	P99IncreasePercent  float64       `json:"p99_increase_percent,omitempty"`
	MeanDelta           time.Duration `json:"mean_delta,omitempty"`
	MeanIncreasePercent float64       `json:"mean_increase_percent,omitempty"`
	Passed              bool          `json:"passed"`
	FailureReason       string        `json:"failure_reason,omitempty"`
}

ComparisonResult represents the outcome of a load test, optionally comparing candidate preview results against baseline production/staging results.

type Config

type Config struct {
	TargetURL                 string            `json:"target_url"`
	RoutingKey                string            `json:"routing_key"`
	Duration                  time.Duration     `json:"duration"`
	RPS                       int               `json:"rps"` // 0 = unthrottled
	Concurrency               int               `json:"concurrency"`
	Timeout                   time.Duration     `json:"timeout"`
	Method                    string            `json:"method"`
	Headers                   map[string]string `json:"headers"`
	Body                      []byte            `json:"body,omitempty"`
	BaselineCompare           bool              `json:"baseline_compare"`
	MaxP99                    time.Duration     `json:"max_p99,omitempty"`
	MaxLatencyIncreasePercent float64           `json:"max_latency_increase_percent,omitempty"`
	MaxErrorRate              float64           `json:"max_error_rate,omitempty"`
}

Config configures a load test execution.

type LatencyStats

type LatencyStats struct {
	Min  time.Duration `json:"min"`
	Mean time.Duration `json:"mean"`
	P50  time.Duration `json:"p50"`
	P90  time.Duration `json:"p90"`
	P95  time.Duration `json:"p95"`
	P99  time.Duration `json:"p99"`
	Max  time.Duration `json:"max"`
}

LatencyStats contains statistical latency percentiles.

type MetricsCollector

type MetricsCollector struct {
	// contains filtered or unexported fields
}

MetricsCollector accumulates request measurements thread-safely.

func NewMetricsCollector

func NewMetricsCollector(targetURL, routingKey string) *MetricsCollector

NewMetricsCollector initializes a fresh collector.

func (*MetricsCollector) Finalize

func (c *MetricsCollector) Finalize() *Result

Finalize calculates summary statistics and percentiles.

func (*MetricsCollector) Record

func (c *MetricsCollector) Record(rec RequestRecord)

Record records a batch of request measurements.

func (*MetricsCollector) Start

func (c *MetricsCollector) Start()

Start marks the beginning of the test.

type RequestRecord

type RequestRecord struct {
	Duration   time.Duration
	StatusCode int
	Error      error
}

RequestRecord captures the result of a single load test request.

type Result

type Result struct {
	TargetURL      string        `json:"target_url"`
	RoutingKey     string        `json:"routing_key,omitempty"`
	Duration       time.Duration `json:"duration"`
	TotalRequests  int64         `json:"total_requests"`
	SuccessCount   int64         `json:"success_count"`    // 2xx
	RedirectCount  int64         `json:"redirect_count"`   // 3xx
	ClientErrCount int64         `json:"client_err_count"` // 4xx
	ServerErrCount int64         `json:"server_err_count"` // 5xx
	NetworkErrors  int64         `json:"network_errors"`
	RPS            float64       `json:"rps"`
	StatusCodes    map[int]int64 `json:"status_codes"`
	Latencies      LatencyStats  `json:"latencies"`
	ErrorSample    []string      `json:"error_sample,omitempty"`
}

Result summarizes the execution metrics of a load test run.

type Runner

type Runner struct {
	// contains filtered or unexported fields
}

Runner executes concurrent HTTP load tests.

func NewRunner

func NewRunner() *Runner

NewRunner creates a new Runner with an optimized HTTP transport, dial-time SSRF filtering, and bounded redirects.

func (*Runner) Run

func (r *Runner) Run(ctx context.Context, cfg Config) (*ComparisonResult, error)

Run executes the load test according to the supplied configuration.

Jump to

Keyboard shortcuts

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