1use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Serialize, Deserialize, Default)]
7pub struct ChaosConfig {
8 pub enabled: bool,
10 pub latency: Option<LatencyConfig>,
12 pub fault_injection: Option<FaultInjectionConfig>,
14 pub rate_limit: Option<RateLimitConfig>,
16 pub traffic_shaping: Option<TrafficShapingConfig>,
18 pub circuit_breaker: Option<CircuitBreakerConfig>,
20 pub bulkhead: Option<BulkheadConfig>,
22}
23
24#[derive(Debug, Clone, Serialize, Deserialize)]
26pub struct LatencyConfig {
27 pub enabled: bool,
29 pub fixed_delay_ms: Option<u64>,
31 pub random_delay_range_ms: Option<(u64, u64)>,
33 pub jitter_percent: f64,
35 pub probability: f64,
37}
38
39impl Default for LatencyConfig {
40 fn default() -> Self {
41 Self {
42 enabled: false,
43 fixed_delay_ms: None,
44 random_delay_range_ms: None,
45 jitter_percent: 0.0,
46 probability: 1.0,
47 }
48 }
49}
50
51#[derive(Debug, Clone, Serialize, Deserialize)]
53pub struct FaultInjectionConfig {
54 pub enabled: bool,
56 pub http_errors: Vec<u16>,
58 pub http_error_probability: f64,
60 pub connection_errors: bool,
62 pub connection_error_probability: f64,
64 pub timeout_errors: bool,
66 pub timeout_ms: u64,
68 pub timeout_probability: f64,
70 pub partial_responses: bool,
72 pub partial_response_probability: f64,
74}
75
76impl Default for FaultInjectionConfig {
77 fn default() -> Self {
78 Self {
79 enabled: false,
80 http_errors: vec![500, 502, 503, 504],
81 http_error_probability: 0.1,
82 connection_errors: false,
83 connection_error_probability: 0.05,
84 timeout_errors: false,
85 timeout_ms: 5000,
86 timeout_probability: 0.05,
87 partial_responses: false,
88 partial_response_probability: 0.05,
89 }
90 }
91}
92
93#[derive(Debug, Clone, Serialize, Deserialize)]
95pub struct RateLimitConfig {
96 pub enabled: bool,
98 pub requests_per_second: u32,
100 pub burst_size: u32,
102 pub per_ip: bool,
104 pub per_endpoint: bool,
106}
107
108impl Default for RateLimitConfig {
109 fn default() -> Self {
110 Self {
111 enabled: false,
112 requests_per_second: 100,
113 burst_size: 10,
114 per_ip: false,
115 per_endpoint: false,
116 }
117 }
118}
119
120#[derive(Debug, Clone, Serialize, Deserialize)]
122pub struct TrafficShapingConfig {
123 pub enabled: bool,
125 pub bandwidth_limit_bps: u64,
127 pub packet_loss_percent: f64,
129 pub max_connections: u32,
131 pub connection_timeout_ms: u64,
133}
134
135impl Default for TrafficShapingConfig {
136 fn default() -> Self {
137 Self {
138 enabled: false,
139 bandwidth_limit_bps: 0,
140 packet_loss_percent: 0.0,
141 max_connections: 0,
142 connection_timeout_ms: 30000,
143 }
144 }
145}
146
147#[derive(Debug, Clone, Serialize, Deserialize)]
149pub struct CircuitBreakerConfig {
150 pub enabled: bool,
152 pub failure_threshold: u64,
154 pub success_threshold: u64,
156 pub timeout_ms: u64,
158 pub half_open_max_requests: u32,
160 pub failure_rate_threshold: f64,
162 pub min_requests_for_rate: u64,
164 pub rolling_window_ms: u64,
166}
167
168impl Default for CircuitBreakerConfig {
169 fn default() -> Self {
170 Self {
171 enabled: false,
172 failure_threshold: 5,
173 success_threshold: 2,
174 timeout_ms: 60000,
175 half_open_max_requests: 3,
176 failure_rate_threshold: 50.0,
177 min_requests_for_rate: 10,
178 rolling_window_ms: 10000,
179 }
180 }
181}
182
183#[derive(Debug, Clone, Serialize, Deserialize)]
185pub struct BulkheadConfig {
186 pub enabled: bool,
188 pub max_concurrent_requests: u32,
190 pub max_queue_size: u32,
192 pub queue_timeout_ms: u64,
194}
195
196impl Default for BulkheadConfig {
197 fn default() -> Self {
198 Self {
199 enabled: false,
200 max_concurrent_requests: 100,
201 max_queue_size: 10,
202 queue_timeout_ms: 5000,
203 }
204 }
205}