safety

package
v0.9.0 Latest Latest
Warning

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

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

Documentation

Overview

Package safety implements FR-CLI-06: a target allowlist plus hard caps on RPS, duration, and concurrency, enforced by default on every run.

It knows nothing about the engine, protocols, or scripting — it only answers two questions a caller (cmd/vegaload's run command today, the MCP run_test tool tomorrow) must act on: is this target one the run is allowed to hit without extra confirmation, and does this run's shape exceed the hard caps.

Index

Constants

This section is empty.

Variables

View Source
var DefaultLimits = Limits{
	MaxVUs:      10000,
	MaxDuration: 24 * time.Hour,
	MaxRate:     100000,
}

DefaultLimits is deliberately generous for local development while still catching an obvious mistake (an extra zero on -vus, a -duration of "30h" instead of "30s").

Functions

func CheckLimits

func CheckLimits(vus int, dur time.Duration, rate float64, limits Limits) error

CheckLimits returns an error describing the first cap a run's shape exceeds, or nil if it stays within limits. rate may be 0 for executors that don't use a rate (fixed-vus, ramp, step).

func FormatLimits

func FormatLimits(l Limits) string

FormatLimits renders limits for a confirmation prompt or error message.

func HostRefusal added in v0.9.0

func HostRefusal(host string) error

HostRefusal refuses host. The caller records nothing for it.

func IsAllowed

func IsAllowed(host string, extra []string) bool

IsAllowed reports whether host may be hit without extra confirmation: a local hostname/loopback/link-local address, or a case-insensitive match against extra (the caller's -allow-target list).

func IsHostRefusal added in v0.9.0

func IsHostRefusal(err error) bool

IsHostRefusal reports whether err is a HostRefusal.

func ParseExtraPort

func ParseExtraPort(hostport string) (host string, port string)

ParseExtraPort is a small helper so cmd/vegaload can accept -allow-target entries with or without a port and still compare sensibly; kept here so the matching rule lives in one place.

func TargetHost

func TargetHost(raw string) (string, error)

TargetHost extracts the bare host (no port) a run's target string resolves to. raw may be a full URL (http://host:8080/path, grpcs://host:443) or a bare host:port (the form gRPC and WebSocket targets sometimes use). An empty raw (a scripted run with no protocol-direct target) returns "" and no error — callers should treat that as "nothing to check".

Types

type Limits

type Limits struct {
	MaxVUs      int
	MaxDuration time.Duration
	MaxRate     float64
}

Limits are the hard caps enforced on every run, regardless of target. They exist to stop a typo or a runaway agent-generated scenario from becoming a much larger run than anyone intended. The caller may raise them explicitly (see cmd/vegaload's -cap-* flags); they are never silently skipped.

Jump to

Keyboard shortcuts

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