Documentation
¶
Overview ¶
Package engine provides engine functionality.
Index ¶
- Variables
- func CalcErrorRatePct(s Stats) float64
- func Clamp01(x float64) float64
- func GenerateCSV(path string, total int, cidrProb float64, cidrPrefix int) error
- func InitColorStyles(enabled bool)
- func IsTTY() bool
- func PrintLatencyHistogram(stats Stats, buckets []atomic.Int64)
- func SupportsUnicode() bool
- func TermSize() (w, h int)
- type App
- type AuthClient
- type AutoController
- type CSVSource
- type Config
- type DefaultStatsCollector
- func (s *DefaultStatsCollector) AddSample(latency time.Duration, _ bool, isMatch bool, isHTTPErr bool, isAborted bool, ...)
- func (s *DefaultStatsCollector) Buckets() []atomic.Int64
- func (s *DefaultStatsCollector) IncParallelMatched()
- func (s *DefaultStatsCollector) IncParallelMismatched()
- func (s *DefaultStatsCollector) Overflow() int64
- func (s *DefaultStatsCollector) Reset()
- func (s *DefaultStatsCollector) SetConcurrency(c int64)
- func (s *DefaultStatsCollector) SetPlateauActive(active bool)
- func (s *DefaultStatsCollector) SetTargetRPS(rps float64)
- func (s *DefaultStatsCollector) Snapshot() Stats
- type MetricsPoller
- type Pacer
- type Row
- type RowSource
- type Stats
- type StatsCollector
Constants ¶
This section is empty.
Variables ¶
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 )
var Module = fx.Module("engine", fx.Provide( NewStatsCollector, NewAuthClient, NewCSVSourceFromConfig, NewPacerFromConfig, NewApp, ), )
Module provides the fx module for the client engine.
Functions ¶
func CalcErrorRatePct ¶
CalcErrorRatePct provides the exported CalcErrorRatePct function.
func GenerateCSV ¶
GenerateCSV provides the exported GenerateCSV function.
func InitColorStyles ¶
func InitColorStyles(enabled bool)
InitColorStyles provides the exported InitColorStyles function.
func PrintLatencyHistogram ¶
PrintLatencyHistogram provides the exported PrintLatencyHistogram function.
func SupportsUnicode ¶
func SupportsUnicode() bool
SupportsUnicode provides the exported SupportsUnicode 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 ¶
ReduceWorkers provides the exported ReduceWorkers method.
func (*App) SpawnWorkers ¶
SpawnWorkers provides the exported SpawnWorkers 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.
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 ¶
NewCSVSource provides the exported NewCSVSource function.
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 NewPacerFromConfig ¶
func NewPacerFromConfig(cfg *Config, collector StatsCollector) *Pacer
NewPacerFromConfig provides an optional Pacer based on the configuration.
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 ¶
RowSource is an interface for providing rows of data.
func NewCSVSourceFromConfig ¶
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.