82 lines
2.7 KiB
Go
82 lines
2.7 KiB
Go
package config
|
|
|
|
import "time"
|
|
|
|
// Config represents the complete configuration for a stress test
|
|
type Config struct {
|
|
Target Target `yaml:"target" json:"target"`
|
|
Load Load `yaml:"load" json:"load"`
|
|
RateLimiting RateLimiting `yaml:"rate_limiting" json:"rate_limiting"`
|
|
FailureInjection FailureInjection `yaml:"failure_injection" json:"failure_injection"`
|
|
Reporting Reporting `yaml:"reporting" json:"reporting"`
|
|
}
|
|
|
|
// Target configuration for the endpoint being tested
|
|
type Target struct {
|
|
URL string `yaml:"url" json:"url"`
|
|
Method string `yaml:"method" json:"method"`
|
|
Headers map[string]string `yaml:"headers" json:"headers"`
|
|
Body string `yaml:"body" json:"body"`
|
|
Timeout int `yaml:"timeout" json:"timeout"` // seconds
|
|
}
|
|
|
|
// Load configuration for the test pattern
|
|
type Load struct {
|
|
Requests int `yaml:"requests" json:"requests"`
|
|
Concurrency int `yaml:"concurrency" json:"concurrency"`
|
|
Duration time.Duration `yaml:"duration" json:"duration"`
|
|
RampUp time.Duration `yaml:"ramp_up" json:"ramp_up"`
|
|
Pattern string `yaml:"pattern" json:"pattern"` // constant, ramp, spike
|
|
RequestsPerSecond int `yaml:"requests_per_second" json:"requests_per_second"`
|
|
}
|
|
|
|
// RateLimiting configuration
|
|
type RateLimiting struct {
|
|
Enabled bool `yaml:"enabled" json:"enabled"`
|
|
RequestsPerSecond int `yaml:"requests_per_second" json:"requests_per_second"`
|
|
}
|
|
|
|
// FailureInjection configuration for chaos testing
|
|
type FailureInjection struct {
|
|
Enabled bool `yaml:"enabled" json:"enabled"`
|
|
NetworkDelay time.Duration `yaml:"network_delay" json:"network_delay"`
|
|
DropRate float64 `yaml:"drop_rate" json:"drop_rate"` // 0.0 to 1.0
|
|
ErrorRate float64 `yaml:"error_rate" json:"error_rate"` // 0.0 to 1.0
|
|
}
|
|
|
|
// Reporting configuration
|
|
type Reporting struct {
|
|
Format []string `yaml:"format" json:"format"` // console, json, html, csv
|
|
OutputDir string `yaml:"output_dir" json:"output_dir"`
|
|
Percentiles []int `yaml:"percentiles" json:"percentiles"`
|
|
}
|
|
|
|
// DefaultConfig returns a sensible default configuration
|
|
func DefaultConfig() *Config {
|
|
return &Config{
|
|
Target: Target{
|
|
Method: "GET",
|
|
Headers: make(map[string]string),
|
|
Timeout: 30,
|
|
},
|
|
Load: Load{
|
|
Requests: 1000,
|
|
Concurrency: 10,
|
|
Duration: 5 * time.Minute,
|
|
Pattern: "constant",
|
|
},
|
|
RateLimiting: RateLimiting{
|
|
Enabled: false,
|
|
RequestsPerSecond: 100,
|
|
},
|
|
FailureInjection: FailureInjection{
|
|
Enabled: false,
|
|
},
|
|
Reporting: Reporting{
|
|
Format: []string{"console"},
|
|
OutputDir: "./results",
|
|
Percentiles: []int{50, 90, 95, 99},
|
|
},
|
|
}
|
|
}
|