faker

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	WeightHTTP        = 25
	WeightApplication = 25
	WeightDatabase    = 15
	WeightSecurity    = 10
	WeightSystem      = 10
	WeightBusiness    = 10
	WeightChaos       = 5
)

Category distribution weights (must sum to 100).

Variables

View Source
var SeverityWeightsChaos = map[string]int{
	"debug":    5,
	"info":     20,
	"success":  10,
	"warning":  25,
	"error":    30,
	"critical": 10,
}

Severity distribution weights for chaos mode (must sum to 100).

View Source
var SeverityWeightsNormal = map[string]int{
	"debug":    10,
	"info":     45,
	"success":  15,
	"warning":  15,
	"error":    12,
	"critical": 3,
}

Severity distribution weights for normal mode (must sum to 100).

Functions

This section is empty.

Types

type Config

type Config struct {
	// Connection
	Endpoint string

	// Realistic mode
	MinDelay time.Duration
	MaxDelay time.Duration

	// Limits
	Duration time.Duration
	Count    int

	// Modes
	Chaos   bool
	Stress  bool
	DryRun  bool
	Quiet   bool
	Verbose bool

	// Stress mode
	StressRate int

	// Reproducibility
	Seed int64

	// Filtering
	Categories []string
}

Config holds the configuration for the faker.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns a config with sensible defaults.

type Faker

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

Faker generates and sends fake logs.

func New

func New(cfg Config) *Faker

New creates a new Faker.

func (*Faker) Run

func (f *Faker) Run(ctx context.Context, onLog func(LogEntry, time.Duration, error)) error

Run executes the faker in realistic mode.

func (*Faker) RunStress

func (f *Faker) RunStress(ctx context.Context, onProgress func(sent, errors int64, rate float64, p95 time.Duration)) error

RunStress executes the faker in stress test mode.

func (*Faker) Stats

func (f *Faker) Stats() *Stats

Stats returns the current statistics.

type Generator

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

Generator creates random log entries.

func NewGenerator

func NewGenerator(seed int64, chaos bool) *Generator

NewGenerator creates a new log generator.

func (*Generator) Generate

func (g *Generator) Generate() LogEntry

Generate returns a random log based on category distribution.

func (*Generator) GenerateApplication

func (g *Generator) GenerateApplication() LogEntry

GenerateApplication creates an application log.

func (*Generator) GenerateBusiness

func (g *Generator) GenerateBusiness() LogEntry

GenerateBusiness creates a business log.

func (*Generator) GenerateCategory

func (g *Generator) GenerateCategory(category string) LogEntry

GenerateCategory returns a log from a specific category.

func (*Generator) GenerateChaos

func (g *Generator) GenerateChaos() LogEntry

GenerateChaos creates unstructured/messy logs.

func (*Generator) GenerateDatabase

func (g *Generator) GenerateDatabase() LogEntry

GenerateDatabase creates a database log.

func (*Generator) GenerateHTTP

func (g *Generator) GenerateHTTP() LogEntry

GenerateHTTP creates an HTTP access log.

func (*Generator) GenerateSecurity

func (g *Generator) GenerateSecurity() LogEntry

GenerateSecurity creates a security log.

func (*Generator) GenerateSystem

func (g *Generator) GenerateSystem() LogEntry

GenerateSystem creates a system log.

type LogEntry

type LogEntry struct {
	Header LogHeader `json:"header"`
	Body   any       `json:"body,omitempty"`
}

LogEntry represents a log to be sent to the API.

type LogHeader

type LogHeader struct {
	Title    string `json:"title"`
	Source   string `json:"source,omitempty"`
	Severity string `json:"severity,omitempty"`
}

LogHeader represents the header of a log entry.

type Stats

type Stats struct {
	Sent      atomic.Int64
	Errors    atomic.Int64
	StartTime time.Time
	// contains filtered or unexported fields
}

Stats tracks faker statistics.

func (*Stats) AddLatency

func (s *Stats) AddLatency(d time.Duration)

AddLatency records a request latency.

func (*Stats) Max

func (s *Stats) Max() time.Duration

Max returns the maximum latency.

func (*Stats) Percentile

func (s *Stats) Percentile(n int) time.Duration

Percentile returns the nth percentile latency.

func (*Stats) Rate

func (s *Stats) Rate() float64

Rate returns logs per second.

Jump to

Keyboard shortcuts

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