engine

package
v3.1.0-rc.3 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2026 License: GPL-3.0 Imports: 30 Imported by: 0

Documentation

Overview

Package engine provides engine functionality.

Index

Constants

This section is empty.

Variables

View Source
var (
	// StyleFaint is an exported package value.
	StyleFaint colorStyle
	// StyleItalic is an exported package value.
	StyleItalic colorStyle
	// StyleBold is an exported package value.
	StyleBold colorStyle
	// StyleGreen is an exported package value.
	StyleGreen colorStyle
	// StyleYellow is an exported package value.
	StyleYellow colorStyle
	// StyleBlue is an exported package value.
	StyleBlue colorStyle
	// StyleMagenta is an exported package value.
	StyleMagenta colorStyle
	// StyleCyan is an exported package value.
	StyleCyan colorStyle
	// StyleRed is an exported package value.
	StyleRed colorStyle
)

Module provides the fx module for the client engine.

Functions

func CalcErrorRatePct

func CalcErrorRatePct(s Stats) float64

CalcErrorRatePct provides the exported CalcErrorRatePct function.

func Clamp01

func Clamp01(x float64) float64

Clamp01 provides the exported Clamp01 function.

func GenerateCSV

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

GenerateCSV provides the exported GenerateCSV function.

func InitColorStyles

func InitColorStyles(enabled bool)

InitColorStyles provides the exported InitColorStyles function.

func IsTTY

func IsTTY() bool

IsTTY provides the exported IsTTY function.

func PrintLatencyHistogram

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

PrintLatencyHistogram provides the exported PrintLatencyHistogram function.

func SupportsUnicode

func SupportsUnicode() bool

SupportsUnicode provides the exported SupportsUnicode function.

func TermSize

func TermSize() (w, h int)

TermSize provides the exported TermSize function.

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
}

App describes the exported App type.

func NewApp

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

NewApp provides the exported NewApp function.

func (*App) ReduceWorkers

func (a *App) ReduceWorkers(n int)

ReduceWorkers provides the exported ReduceWorkers method.

func (*App) Run

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

Run provides the exported Run method.

func (*App) SpawnWorkers

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

SpawnWorkers provides the exported SpawnWorkers method.

func (*App) Stop

func (a *App) Stop()

Stop provides the exported Stop method.

type AuthClient

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

AuthClient describes the exported AuthClient type.

func NewAuthClient

func NewAuthClient(cfg *Config) *AuthClient

NewAuthClient provides the exported NewAuthClient function.

func (*AuthClient) BaseHeader

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

BaseHeader provides the exported BaseHeader method.

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)

DoRequest provides the exported DoRequest method.

func (*AuthClient) HTTPClient

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

HTTPClient provides the exported HTTPClient method.

func (*AuthClient) Stop

func (c *AuthClient) Stop()

Stop provides the exported Stop method.

type AutoController

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

AutoController describes the exported AutoController type.

func NewAutoController

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

NewAutoController provides the exported NewAutoController function.

func (*AutoController) Run

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

Run provides the exported Run method.

type CSVSource

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

CSVSource describes the exported CSVSource type.

func NewCSVSource

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

NewCSVSource provides the exported NewCSVSource function.

func (*CSVSource) Next

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

Next provides the exported Next method.

func (*CSVSource) Reset

func (s *CSVSource) Reset()

Reset provides the exported Reset method.

func (*CSVSource) Total

func (s *CSVSource) Total() int

Total provides the exported Total method.

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
	InsecureTLS     bool
	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
}

DefaultStatsCollector describes the exported DefaultStatsCollector type.

func NewDefaultStatsCollector

func NewDefaultStatsCollector() *DefaultStatsCollector

NewDefaultStatsCollector provides the exported NewDefaultStatsCollector function.

func (*DefaultStatsCollector) AddSample

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

AddSample provides the exported AddSample method.

func (*DefaultStatsCollector) Buckets

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

Buckets provides the exported Buckets method.

func (*DefaultStatsCollector) IncParallelMatched

func (s *DefaultStatsCollector) IncParallelMatched()

IncParallelMatched provides the exported IncParallelMatched method.

func (*DefaultStatsCollector) IncParallelMismatched

func (s *DefaultStatsCollector) IncParallelMismatched()

IncParallelMismatched provides the exported IncParallelMismatched method.

func (*DefaultStatsCollector) Overflow

func (s *DefaultStatsCollector) Overflow() int64

Overflow provides the exported Overflow method.

func (*DefaultStatsCollector) Reset

func (s *DefaultStatsCollector) Reset()

Reset provides the exported Reset method.

func (*DefaultStatsCollector) SetConcurrency

func (s *DefaultStatsCollector) SetConcurrency(c int64)

SetConcurrency provides the exported SetConcurrency method.

func (*DefaultStatsCollector) SetPlateauActive

func (s *DefaultStatsCollector) SetPlateauActive(active bool)

SetPlateauActive provides the exported SetPlateauActive method.

func (*DefaultStatsCollector) SetTargetRPS

func (s *DefaultStatsCollector) SetTargetRPS(rps float64)

SetTargetRPS provides the exported SetTargetRPS method.

func (*DefaultStatsCollector) Snapshot

func (s *DefaultStatsCollector) Snapshot() Stats

Snapshot provides the exported Snapshot method.

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

NewMetricsPoller provides the exported NewMetricsPoller function.

func (*MetricsPoller) GetLine

func (p *MetricsPoller) GetLine() string

GetLine provides the exported GetLine method.

func (*MetricsPoller) Run

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

Run provides the exported Run method.

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