- Fix config version inflation bug in main.go - Add dynamic subsystem checking to prevent false change detection - Implement migration detection and execution system - Add directory migration from /etc/aggregator to /etc/redflag - Update all path references across codebase to use new directories - Add configuration schema versioning and automatic migration - Implement backup and rollback capabilities - Add security feature detection and hardening - Update installation scripts and sudoers for new paths - Complete Phase 1 migration system
108 lines
3.8 KiB
Go
108 lines
3.8 KiB
Go
package config
|
|
|
|
import "time"
|
|
|
|
// SubsystemConfig holds configuration for individual subsystems
|
|
type SubsystemConfig struct {
|
|
// Execution settings
|
|
Enabled bool `json:"enabled"`
|
|
Timeout time.Duration `json:"timeout"` // Timeout for this subsystem
|
|
|
|
// Circuit breaker settings
|
|
CircuitBreaker CircuitBreakerConfig `json:"circuit_breaker"`
|
|
}
|
|
|
|
// CircuitBreakerConfig holds circuit breaker settings for subsystems
|
|
type CircuitBreakerConfig struct {
|
|
// Enabled controls whether circuit breaker is active
|
|
Enabled bool `json:"enabled"`
|
|
|
|
// FailureThreshold is the number of consecutive failures before opening the circuit
|
|
FailureThreshold int `json:"failure_threshold"`
|
|
|
|
// FailureWindow is the time window to track failures (e.g., 3 failures in 10 minutes)
|
|
FailureWindow time.Duration `json:"failure_window"`
|
|
|
|
// OpenDuration is how long the circuit stays open before attempting recovery
|
|
OpenDuration time.Duration `json:"open_duration"`
|
|
|
|
// HalfOpenAttempts is the number of test attempts in half-open state before fully closing
|
|
HalfOpenAttempts int `json:"half_open_attempts"`
|
|
}
|
|
|
|
// SubsystemsConfig holds all subsystem configurations
|
|
type SubsystemsConfig struct {
|
|
System SubsystemConfig `json:"system"` // System metrics scanner
|
|
Updates SubsystemConfig `json:"updates"` // Virtual subsystem for package update scheduling
|
|
APT SubsystemConfig `json:"apt"`
|
|
DNF SubsystemConfig `json:"dnf"`
|
|
Docker SubsystemConfig `json:"docker"`
|
|
Windows SubsystemConfig `json:"windows"`
|
|
Winget SubsystemConfig `json:"winget"`
|
|
Storage SubsystemConfig `json:"storage"`
|
|
}
|
|
|
|
// GetDefaultSubsystemsConfig returns default subsystem configurations
|
|
func GetDefaultSubsystemsConfig() SubsystemsConfig {
|
|
// Default circuit breaker config
|
|
defaultCB := CircuitBreakerConfig{
|
|
Enabled: true,
|
|
FailureThreshold: 3, // 3 consecutive failures
|
|
FailureWindow: 10 * time.Minute, // within 10 minutes
|
|
OpenDuration: 30 * time.Minute, // circuit open for 30 min
|
|
HalfOpenAttempts: 2, // 2 successful attempts to close circuit
|
|
}
|
|
|
|
// Aggressive circuit breaker for Windows Update (known to be slow/problematic)
|
|
windowsCB := CircuitBreakerConfig{
|
|
Enabled: true,
|
|
FailureThreshold: 2, // Only 2 failures
|
|
FailureWindow: 15 * time.Minute,
|
|
OpenDuration: 60 * time.Minute, // Open for 1 hour
|
|
HalfOpenAttempts: 3,
|
|
}
|
|
|
|
return SubsystemsConfig{
|
|
System: SubsystemConfig{
|
|
Enabled: true, // System scanner always available
|
|
Timeout: 10 * time.Second, // System info should be fast
|
|
CircuitBreaker: defaultCB,
|
|
},
|
|
Updates: SubsystemConfig{
|
|
Enabled: true, // Virtual subsystem for package update scheduling
|
|
Timeout: 0, // Not used - delegates to individual package scanners
|
|
CircuitBreaker: CircuitBreakerConfig{Enabled: false}, // No circuit breaker for virtual subsystem
|
|
},
|
|
APT: SubsystemConfig{
|
|
Enabled: true,
|
|
Timeout: 30 * time.Second,
|
|
CircuitBreaker: defaultCB,
|
|
},
|
|
DNF: SubsystemConfig{
|
|
Enabled: true,
|
|
Timeout: 15 * time.Minute, // TODO: Make scanner timeouts user-adjustable via settings. DNF operations can take a long time on large systems
|
|
CircuitBreaker: defaultCB,
|
|
},
|
|
Docker: SubsystemConfig{
|
|
Enabled: true,
|
|
Timeout: 60 * time.Second, // Registry queries can be slow
|
|
CircuitBreaker: defaultCB,
|
|
},
|
|
Windows: SubsystemConfig{
|
|
Enabled: true,
|
|
Timeout: 10 * time.Minute, // Windows Update can be VERY slow
|
|
CircuitBreaker: windowsCB,
|
|
},
|
|
Winget: SubsystemConfig{
|
|
Enabled: true,
|
|
Timeout: 2 * time.Minute, // Winget has multiple retry strategies
|
|
CircuitBreaker: defaultCB,
|
|
},
|
|
Storage: SubsystemConfig{
|
|
Enabled: true,
|
|
Timeout: 10 * time.Second, // Disk info should be fast
|
|
CircuitBreaker: defaultCB,
|
|
},
|
|
}
|
|
}
|