Documentation
¶
Index ¶
- Constants
- func FormatJSON(w io.Writer, comp *ComparisonResult) error
- func FormatTable(w io.Writer, comp *ComparisonResult) error
- func IsProhibitedHost(hostname string) bool
- func IsProhibitedIP(ip net.IP) bool
- func ValidateTargetURL(targetURL string) error
- type ComparisonResult
- type Config
- type LatencyStats
- type MetricsCollector
- type RequestRecord
- type Result
- type Runner
Constants ¶
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 ¶
IsProhibitedHost checks whether a hostname matches known cloud provider metadata endpoints.
func IsProhibitedIP ¶
IsProhibitedIP checks whether an IP address is a link-local address or cloud metadata IP.
func ValidateTargetURL ¶
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 ¶
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.