engine

package
v1.12.3 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2026 License: GPL-3.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AnsiReset = "\x1b[0m"
	AnsiDim   = "\x1b[2m"
	AnsiBold  = "\x1b[1m"

	FgRed     = "\x1b[91m"
	FgGreen   = "\x1b[92m"
	FgYellow  = "\x1b[93m"
	FgBlue    = "\x1b[94m"
	FgMagenta = "\x1b[95m"
	FgCyan    = "\x1b[96m"
	FgWhite   = "\x1b[97m"
)

Variables

View Source
var (
	StyleBold, StyleFaint, StyleItalic                                    colorStyle
	StyleRed, StyleGreen, StyleYellow, StyleBlue, StyleMagenta, StyleCyan colorStyle
)

Module provides the fx module for the client engine.

Functions

func CalcErrorRatePct

func CalcErrorRatePct(s Stats) float64

func Clamp01

func Clamp01(x float64) float64

func GenerateCSV

func GenerateCSV(path string, total int, cidrProb float64, cidrPrefix int) error

func InitColorStyles

func InitColorStyles(enabled bool)

func IsTTY

func IsTTY() bool

func PrintLatencyHistogram

func PrintLatencyHistogram(stats Stats, buckets []atomic.Int64, overflow int64)

func SupportsUnicode

func SupportsUnicode() bool

func TermSize

func TermSize() (w, h int)

Types

type App

type App struct {
	Config         *Config
	Source         RowSource
	Collector      StatsCollector
	Client         *AuthClient
	Pacer          *Pacer
	AutoController *AutoController
	MetricsPoller  *MetricsPoller
	// contains filtered or unexported fields
}

func NewApp

func NewApp(cfg *Config, src RowSource, collector StatsCollector, client *AuthClient, pacer *Pacer) *App

func (*App) ReduceWorkers

func (a *App) ReduceWorkers(n int)

func (*App) Run

func (a *App) Run(ctx context.Context) error

func (*App) SpawnWorkers

func (a *App) SpawnWorkers(ctx context.Context, n int)

func (*App) Stop

func (a *App) Stop()

type AuthClient

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

func NewAuthClient

func NewAuthClient(cfg *Config) *AuthClient

func (*AuthClient) BaseHeader

func (c *AuthClient) BaseHeader() http.Header

func (*AuthClient) DoRequest

func (c *AuthClient) DoRequest(ctx context.Context, row Row) (ok bool, isMatch bool, isHttpErr bool, isTooManyRequests bool, isToleratedBF bool, isAborted bool, latency time.Duration, respBody []byte, statusCode int, err error)

func (*AuthClient) HTTPClient

func (c *AuthClient) HTTPClient() *http.Client

func (*AuthClient) Stop

func (c *AuthClient) Stop()

type AutoController

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

func NewAutoController

func NewAutoController(cfg *Config, collector StatsCollector, pacer *Pacer, app *App) *AutoController

func (*AutoController) Run

func (c *AutoController) Run(ctx context.Context)

type CSVSource

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

func NewCSVSource

func NewCSVSource(path string, delim rune, debug bool, maxRows int, shuffle bool) (*CSVSource, error)

func (*CSVSource) Next

func (s *CSVSource) Next() (Row, bool)

func (*CSVSource) Reset

func (s *CSVSource) Reset()

func (*CSVSource) Total

func (s *CSVSource) Total() int

type Config

type Config struct {
	CSVPath         string
	Endpoint        string
	Method          string
	Concurrency     int
	RPS             float64
	JitterMs        int
	DelayMs         int
	TimeoutMs       int
	MaxRows         int
	Shuffle         bool
	HeadersList     string
	BasicAuth       string
	OKStatus        int
	UseJSONFlag     bool
	Verbose         bool
	GenCSV          bool
	GenCount        int
	GenCIDRProb     float64
	GenCIDRPrefix   int
	CSVDelim        string
	CSVDebug        bool
	Loops           int
	RunFor          time.Duration
	MaxParallel     int
	ParallelProb    float64
	AbortProb       float64
	ProgressEvery   time.Duration
	CompareParallel bool
	UseIdemKey      bool
	ProgressBar     bool
	ColorMode       string

	// Thresholds for coloring
	WarnP95   int
	CritP95   int
	WarnErr   float64
	CritErr   float64
	WarnTrack float64
	CritTrack float64

	GraceSeconds int

	// Auto-mode flags
	AutoMode                  bool
	AutoTargetP95             int
	AutoMaxRPS                float64
	AutoMaxConc               int
	AutoStartRPS              float64
	AutoStartConc             int
	AutoStepRPS               float64
	AutoStepConc              int
	AutoBackoff               float64
	AutoMaxErr                float64
	AutoMinSample             int
	AutoFocus                 string
	AutoPlateau               bool
	AutoPlateauWindows        int
	AutoPlateauGain           float64
	AutoPlateauAction         string
	AutoPlateauCooldown       int
	AutoPlateauTrackThreshold float64
	AutoPlateauTrackWindows   int
	AutoPlateauTrackAction    string

	RandomNoAuth      bool
	RandomNoAuthProb  float64
	RandomBadPass     bool
	RandomBadPassProb float64

	Debug bool
}

Config holds all parameters for the test client.

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns a Config with default values.

type DefaultStatsCollector

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

func NewDefaultStatsCollector

func NewDefaultStatsCollector() *DefaultStatsCollector

func (*DefaultStatsCollector) AddSample

func (s *DefaultStatsCollector) AddSample(latency time.Duration, ok bool, isMatch bool, isHttpErr bool, isAborted bool, isSkipped bool, isToleratedBF bool, isTooManyRequests bool, statusCode int)

func (*DefaultStatsCollector) Buckets

func (s *DefaultStatsCollector) Buckets() []atomic.Int64

func (*DefaultStatsCollector) IncParallelMatched

func (s *DefaultStatsCollector) IncParallelMatched()

func (*DefaultStatsCollector) IncParallelMismatched

func (s *DefaultStatsCollector) IncParallelMismatched()

func (*DefaultStatsCollector) Overflow

func (s *DefaultStatsCollector) Overflow() int64

func (*DefaultStatsCollector) Reset

func (s *DefaultStatsCollector) Reset()

func (*DefaultStatsCollector) SetConcurrency

func (s *DefaultStatsCollector) SetConcurrency(c int64)

func (*DefaultStatsCollector) SetPlateauActive

func (s *DefaultStatsCollector) SetPlateauActive(active bool)

func (*DefaultStatsCollector) SetTargetRPS

func (s *DefaultStatsCollector) SetTargetRPS(rps float64)

func (*DefaultStatsCollector) Snapshot

func (s *DefaultStatsCollector) Snapshot() Stats

type MetricsPoller

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

MetricsPoller periodically fetches Prometheus metrics from the server.

func NewMetricsPoller

func NewMetricsPoller(client *http.Client, endpoint string, header http.Header, interval time.Duration) *MetricsPoller

func (*MetricsPoller) GetLine

func (p *MetricsPoller) GetLine() string

func (*MetricsPoller) Run

func (p *MetricsPoller) Run(ctx context.Context)

type Pacer

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

Pacer generates ticks at a configurable RPS and allows live reconfiguration.

func NewPacer

func NewPacer(rps float64) *Pacer

NewPacer creates a new Pacer.

func NewPacerFromConfig

func NewPacerFromConfig(cfg *Config, collector StatsCollector) *Pacer

NewPacerFromConfig provides an optional Pacer based on the configuration.

func (*Pacer) SetRPS

func (p *Pacer) SetRPS(rps float64)

SetRPS updates the pacing rate.

func (*Pacer) Stop

func (p *Pacer) Stop()

Stop terminates the internal goroutine.

func (*Pacer) Tick

func (p *Pacer) Tick() <-chan time.Time

Tick returns a stable receive-only channel delivering pacing ticks.

type Row

type Row struct {
	Username  string
	Password  string
	IP        string
	ExpectOK  bool
	RawFields map[string]string

	BadPass bool
	NoAuth  bool
}

Row represents a single data entry for a request.

type RowSource

type RowSource interface {
	Next() (Row, bool)
	Reset()
	Total() int
}

RowSource is an interface for providing rows of data.

func NewCSVSourceFromConfig

func NewCSVSourceFromConfig(cfg *Config) (RowSource, error)

NewCSVSourceFromConfig provides a RowSource based on the configuration.

type Stats

type Stats struct {
	Total, Matched, Mismatched, HttpErrs, Aborted, Skipped, ToleratedBF, TooManyRequests int64
	ParallelMatched, ParallelMismatched                                                  int64
	Avg, P50, P90, P95, P99                                                              time.Duration
	Min, Max                                                                             time.Duration
	Elapsed                                                                              time.Duration
	TargetRPS                                                                            float64
	Concurrency                                                                          int64
	PlateauActive                                                                        bool
	StatusCounts                                                                         map[int]int64
}

Stats is a read-only snapshot of key counters and latency percentiles.

type StatsCollector

type StatsCollector interface {
	AddSample(latency time.Duration, ok bool, isMatch bool, isHttpErr bool, isAborted bool, isSkipped bool, isToleratedBF bool, isTooManyRequests bool, statusCode int)
	IncParallelMatched()
	IncParallelMismatched()
	Snapshot() Stats
	Reset()
	Buckets() []atomic.Int64
	Overflow() int64
	SetTargetRPS(rps float64)
	SetConcurrency(c int64)
	SetPlateauActive(active bool)
}

StatsCollector handles atomic updates to counters and latency tracking.

func NewStatsCollector

func NewStatsCollector() StatsCollector

NewStatsCollector provides a StatsCollector implementation.

Jump to

Keyboard shortcuts

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