Update core/data_models.py
Browse files- core/data_models.py +206 -7
core/data_models.py
CHANGED
|
@@ -1,10 +1,10 @@
|
|
| 1 |
"""
|
| 2 |
-
Pythonic data models
|
| 3 |
"""
|
| 4 |
|
| 5 |
from dataclasses import dataclass, asdict
|
| 6 |
from enum import Enum
|
| 7 |
-
from typing import Dict, List, Optional, Any
|
| 8 |
import datetime
|
| 9 |
|
| 10 |
# Import from actual ARF OSS package
|
|
@@ -22,11 +22,46 @@ except ImportError:
|
|
| 22 |
# Fallback mock classes for demo
|
| 23 |
class HealingIntent:
|
| 24 |
def __init__(self, **kwargs):
|
| 25 |
-
self.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
class OSSMCPClient:
|
| 28 |
-
def
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
class IncidentSeverity(Enum):
|
| 32 |
"""Enum for incident severity levels"""
|
|
@@ -66,7 +101,6 @@ class OSSAnalysis:
|
|
| 66 |
@classmethod
|
| 67 |
def from_arf_analysis(cls, arf_result: Dict, scenario_name: str) -> 'OSSAnalysis':
|
| 68 |
"""Create from actual ARF analysis result"""
|
| 69 |
-
# This would be connected to actual ARF OSS analysis
|
| 70 |
recommendations = arf_result.get("recommendations", [
|
| 71 |
"Increase resource allocation",
|
| 72 |
"Implement monitoring",
|
|
@@ -142,4 +176,169 @@ class DemoStep:
|
|
| 142 |
action: str
|
| 143 |
message: str
|
| 144 |
icon: str = "π―"
|
| 145 |
-
arf_integration: bool = False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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 7 |
+
from typing import Dict, List, Optional, Any
|
| 8 |
import datetime
|
| 9 |
|
| 10 |
# Import from actual ARF OSS package
|
|
|
|
| 22 |
# Fallback mock classes for demo
|
| 23 |
class HealingIntent:
|
| 24 |
def __init__(self, **kwargs):
|
| 25 |
+
self.intent_type = kwargs.get("intent_type", "scale_out")
|
| 26 |
+
self.parameters = kwargs.get("parameters", {})
|
| 27 |
+
|
| 28 |
+
def to_dict(self):
|
| 29 |
+
return {
|
| 30 |
+
"intent_type": self.intent_type,
|
| 31 |
+
"parameters": self.parameters,
|
| 32 |
+
"created_at": datetime.datetime.now().isoformat()
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
def create_scale_out_intent(resource_type: str, scale_factor: float = 2.0):
|
| 36 |
+
return HealingIntent(
|
| 37 |
+
intent_type="scale_out",
|
| 38 |
+
parameters={
|
| 39 |
+
"resource_type": resource_type,
|
| 40 |
+
"scale_factor": scale_factor,
|
| 41 |
+
"action": "Increase capacity"
|
| 42 |
+
}
|
| 43 |
+
)
|
| 44 |
|
| 45 |
class OSSMCPClient:
|
| 46 |
+
def __init__(self):
|
| 47 |
+
self.mode = "advisory"
|
| 48 |
+
|
| 49 |
+
def analyze_incident(self, metrics: Dict, pattern: str = "") -> Dict:
|
| 50 |
+
return {
|
| 51 |
+
"status": "analysis_complete",
|
| 52 |
+
"recommendations": [
|
| 53 |
+
"Increase resource allocation",
|
| 54 |
+
"Implement monitoring",
|
| 55 |
+
"Add circuit breakers",
|
| 56 |
+
"Optimize configuration"
|
| 57 |
+
],
|
| 58 |
+
"confidence": 0.92,
|
| 59 |
+
"pattern_matched": pattern,
|
| 60 |
+
"healing_intent": {
|
| 61 |
+
"type": "scale_out",
|
| 62 |
+
"requires_execution": True
|
| 63 |
+
}
|
| 64 |
+
}
|
| 65 |
|
| 66 |
class IncidentSeverity(Enum):
|
| 67 |
"""Enum for incident severity levels"""
|
|
|
|
| 101 |
@classmethod
|
| 102 |
def from_arf_analysis(cls, arf_result: Dict, scenario_name: str) -> 'OSSAnalysis':
|
| 103 |
"""Create from actual ARF analysis result"""
|
|
|
|
| 104 |
recommendations = arf_result.get("recommendations", [
|
| 105 |
"Increase resource allocation",
|
| 106 |
"Implement monitoring",
|
|
|
|
| 176 |
action: str
|
| 177 |
message: str
|
| 178 |
icon: str = "π―"
|
| 179 |
+
arf_integration: bool = False
|
| 180 |
+
|
| 181 |
+
# ===========================================
|
| 182 |
+
# INCIDENT DATABASE - ADD THIS CLASS
|
| 183 |
+
# ===========================================
|
| 184 |
+
|
| 185 |
+
class IncidentDatabase:
|
| 186 |
+
"""Database of incident scenarios for the demo"""
|
| 187 |
+
|
| 188 |
+
@staticmethod
|
| 189 |
+
def get_scenarios() -> Dict[str, IncidentScenario]:
|
| 190 |
+
"""Get all incident scenarios"""
|
| 191 |
+
cache_miss = IncidentScenario(
|
| 192 |
+
name="Cache Miss Storm",
|
| 193 |
+
severity=IncidentSeverity.CRITICAL,
|
| 194 |
+
metrics={
|
| 195 |
+
"Cache Hit Rate": "18.5% (Critical)",
|
| 196 |
+
"Database Load": "92% (Overloaded)",
|
| 197 |
+
"Response Time": "1850ms (Slow)",
|
| 198 |
+
"Affected Users": "45,000",
|
| 199 |
+
"Eviction Rate": "125/sec"
|
| 200 |
+
},
|
| 201 |
+
impact={
|
| 202 |
+
"Revenue Loss": "$8,500/hour",
|
| 203 |
+
"Page Load Time": "+300%",
|
| 204 |
+
"Users Impacted": "45,000",
|
| 205 |
+
"SLA Violation": "Yes",
|
| 206 |
+
"Customer Satisfaction": "-40%"
|
| 207 |
+
},
|
| 208 |
+
arf_pattern="cache_miss_storm",
|
| 209 |
+
oss_analysis=OSSAnalysis(
|
| 210 |
+
status="β
Analysis Complete",
|
| 211 |
+
recommendations=[
|
| 212 |
+
"Increase Redis cache memory allocation by 2x",
|
| 213 |
+
"Implement cache warming strategy with predictive loading",
|
| 214 |
+
"Optimize key patterns and implement TTL adjustments",
|
| 215 |
+
"Add circuit breaker for graceful database fallback",
|
| 216 |
+
"Deploy monitoring for cache hit rate trends"
|
| 217 |
+
],
|
| 218 |
+
estimated_time="60-90 minutes",
|
| 219 |
+
engineers_needed="2-3 SREs + 1 DBA",
|
| 220 |
+
manual_effort="High",
|
| 221 |
+
confidence_score=0.92,
|
| 222 |
+
healing_intent={
|
| 223 |
+
"type": "scale_out",
|
| 224 |
+
"resource": "cache",
|
| 225 |
+
"scale_factor": 2.0
|
| 226 |
+
}
|
| 227 |
+
),
|
| 228 |
+
enterprise_results=EnterpriseResults(
|
| 229 |
+
actions_completed=[
|
| 230 |
+
"β
Auto-scaled Redis cluster: 4GB β 8GB",
|
| 231 |
+
"β
Deployed intelligent cache warming service",
|
| 232 |
+
"β
Optimized 12 key patterns with ML recommendations",
|
| 233 |
+
"β
Implemented circuit breaker with 95% success rate",
|
| 234 |
+
"β
Validated recovery with automated testing"
|
| 235 |
+
],
|
| 236 |
+
metrics_improvement={
|
| 237 |
+
"Cache Hit Rate": "18.5% β 72%",
|
| 238 |
+
"Response Time": "1850ms β 450ms",
|
| 239 |
+
"Database Load": "92% β 45%",
|
| 240 |
+
"Throughput": "1250 β 2450 req/sec"
|
| 241 |
+
},
|
| 242 |
+
business_impact={
|
| 243 |
+
"Recovery Time": "60 min β 12 min",
|
| 244 |
+
"Cost Saved": "$7,200",
|
| 245 |
+
"Users Impacted": "45,000 β 0",
|
| 246 |
+
"Revenue Protected": "$1,700",
|
| 247 |
+
"MTTR Improvement": "80% reduction"
|
| 248 |
+
},
|
| 249 |
+
approval_required=True,
|
| 250 |
+
execution_time="8 minutes"
|
| 251 |
+
)
|
| 252 |
+
)
|
| 253 |
+
|
| 254 |
+
db_exhaustion = IncidentScenario(
|
| 255 |
+
name="Database Connection Pool Exhaustion",
|
| 256 |
+
severity=IncidentSeverity.HIGH,
|
| 257 |
+
metrics={
|
| 258 |
+
"Active Connections": "98/100 (Critical)",
|
| 259 |
+
"API Latency": "2450ms",
|
| 260 |
+
"Error Rate": "15.2%",
|
| 261 |
+
"Queue Depth": "1250",
|
| 262 |
+
"Connection Wait Time": "45s"
|
| 263 |
+
},
|
| 264 |
+
impact={
|
| 265 |
+
"Revenue Loss": "$4,200/hour",
|
| 266 |
+
"Affected Services": "API Gateway, User Service, Payment Service",
|
| 267 |
+
"SLA Violation": "Yes",
|
| 268 |
+
"Partner Impact": "3 external APIs"
|
| 269 |
+
},
|
| 270 |
+
arf_pattern="db_connection_exhaustion",
|
| 271 |
+
oss_analysis=OSSAnalysis(
|
| 272 |
+
status="β
Analysis Complete",
|
| 273 |
+
recommendations=[
|
| 274 |
+
"Increase connection pool size from 100 to 200",
|
| 275 |
+
"Add connection timeout (30s)",
|
| 276 |
+
"Implement leak detection",
|
| 277 |
+
"Add connection health checks",
|
| 278 |
+
"Optimize query patterns"
|
| 279 |
+
],
|
| 280 |
+
estimated_time="45-60 minutes",
|
| 281 |
+
engineers_needed="1-2 DBAs",
|
| 282 |
+
manual_effort="Medium-High",
|
| 283 |
+
confidence_score=0.88
|
| 284 |
+
)
|
| 285 |
+
)
|
| 286 |
+
|
| 287 |
+
memory_leak = IncidentScenario(
|
| 288 |
+
name="Memory Leak in Production",
|
| 289 |
+
severity=IncidentSeverity.HIGH,
|
| 290 |
+
metrics={
|
| 291 |
+
"Memory Usage": "96% (Critical)",
|
| 292 |
+
"GC Pause Time": "4500ms",
|
| 293 |
+
"Error Rate": "28.5%",
|
| 294 |
+
"Restart Frequency": "12/hour",
|
| 295 |
+
"Heap Fragmentation": "42%"
|
| 296 |
+
},
|
| 297 |
+
impact={
|
| 298 |
+
"Revenue Loss": "$5,500/hour",
|
| 299 |
+
"Session Loss": "8,500 users",
|
| 300 |
+
"Customer Impact": "High",
|
| 301 |
+
"Support Tickets": "+300%"
|
| 302 |
+
},
|
| 303 |
+
arf_pattern="memory_leak_java",
|
| 304 |
+
oss_analysis=OSSAnalysis(
|
| 305 |
+
status="β
Analysis Complete",
|
| 306 |
+
recommendations=[
|
| 307 |
+
"Increase JVM heap size from 4GB to 8GB",
|
| 308 |
+
"Implement memory leak detection with profiling",
|
| 309 |
+
"Add proactive health checks",
|
| 310 |
+
"Schedule rolling restart with zero downtime",
|
| 311 |
+
"Deploy memory monitoring dashboard"
|
| 312 |
+
],
|
| 313 |
+
estimated_time="75-90 minutes",
|
| 314 |
+
engineers_needed="2 Java SREs",
|
| 315 |
+
manual_effort="High",
|
| 316 |
+
confidence_score=0.85
|
| 317 |
+
)
|
| 318 |
+
)
|
| 319 |
+
|
| 320 |
+
api_rate_limit = IncidentScenario(
|
| 321 |
+
name="API Rate Limit Exceeded",
|
| 322 |
+
severity=IncidentSeverity.MEDIUM,
|
| 323 |
+
metrics={
|
| 324 |
+
"429 Error Rate": "42.5%",
|
| 325 |
+
"Successful Requests": "58.3%",
|
| 326 |
+
"API Latency": "120ms",
|
| 327 |
+
"Queue Depth": "1250",
|
| 328 |
+
"Client Satisfaction": "65/100"
|
| 329 |
+
},
|
| 330 |
+
impact={
|
| 331 |
+
"Revenue Loss": "$1,800/hour",
|
| 332 |
+
"Affected Partners": "8",
|
| 333 |
+
"Partner SLA Violations": "3",
|
| 334 |
+
"Business Impact": "Medium"
|
| 335 |
+
},
|
| 336 |
+
arf_pattern="api_rate_limit"
|
| 337 |
+
)
|
| 338 |
+
|
| 339 |
+
return {
|
| 340 |
+
"Cache Miss Storm": cache_miss,
|
| 341 |
+
"Database Connection Pool Exhaustion": db_exhaustion,
|
| 342 |
+
"Memory Leak in Production": memory_leak,
|
| 343 |
+
"API Rate Limit Exceeded": api_rate_limit
|
| 344 |
+
}
|