File size: 12,300 Bytes
c30c59f
f456223
c30c59f
 
 
 
f456223
c30c59f
 
2ec94ec
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f456223
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2ec94ec
 
f456223
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2ec94ec
c30c59f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2ec94ec
c30c59f
 
 
 
 
 
2ec94ec
c30c59f
 
2ec94ec
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c30c59f
 
 
 
 
 
 
 
 
2ec94ec
c30c59f
 
2ec94ec
 
 
 
 
 
 
c30c59f
 
 
2ec94ec
c30c59f
 
 
 
2ec94ec
c30c59f
 
 
 
 
 
 
 
 
2ec94ec
 
c30c59f
 
 
 
 
 
 
 
 
 
 
 
 
 
2ec94ec
f456223
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
"""
Pythonic data models for ARF Demo - COMPLETE VERSION
"""

from dataclasses import dataclass, asdict
from enum import Enum
from typing import Dict, List, Optional, Any
import datetime

# Import from actual ARF OSS package
try:
    from agentic_reliability_framework.arf_core.models.healing_intent import (
        HealingIntent,
        create_scale_out_intent,
        create_rollback_intent,
        create_restart_intent
    )
    from agentic_reliability_framework.arf_core.engine.simple_mcp_client import OSSMCPClient
    ARF_OSS_AVAILABLE = True
except ImportError:
    ARF_OSS_AVAILABLE = False
    # Fallback mock classes for demo
    class HealingIntent:
        def __init__(self, **kwargs):
            self.intent_type = kwargs.get("intent_type", "scale_out")
            self.parameters = kwargs.get("parameters", {})
        
        def to_dict(self):
            return {
                "intent_type": self.intent_type,
                "parameters": self.parameters,
                "created_at": datetime.datetime.now().isoformat()
            }
    
    def create_scale_out_intent(resource_type: str, scale_factor: float = 2.0):
        return HealingIntent(
            intent_type="scale_out",
            parameters={
                "resource_type": resource_type,
                "scale_factor": scale_factor,
                "action": "Increase capacity"
            }
        )
    
    class OSSMCPClient:
        def __init__(self):
            self.mode = "advisory"
        
        def analyze_incident(self, metrics: Dict, pattern: str = "") -> Dict:
            return {
                "status": "analysis_complete",
                "recommendations": [
                    "Increase resource allocation",
                    "Implement monitoring",
                    "Add circuit breakers",
                    "Optimize configuration"
                ],
                "confidence": 0.92,
                "pattern_matched": pattern,
                "healing_intent": {
                    "type": "scale_out",
                    "requires_execution": True
                }
            }

class IncidentSeverity(Enum):
    """Enum for incident severity levels"""
    LOW = "LOW"
    MEDIUM = "MEDIUM" 
    HIGH = "HIGH"
    CRITICAL = "CRITICAL"

class DemoMode(Enum):
    """Enum for demo modes"""
    QUICK = "quick"
    COMPREHENSIVE = "comprehensive"
    INVESTOR = "investor"

@dataclass
class OSSAnalysis:
    """Structured OSS analysis results - using actual ARF"""
    status: str
    recommendations: List[str]
    estimated_time: str
    engineers_needed: str
    manual_effort: str
    confidence_score: float = 0.95
    healing_intent: Optional[Dict] = None
    
    def to_dict(self) -> Dict:
        """Convert to dictionary, including healing intent if available"""
        data = asdict(self)
        if self.healing_intent:
            data["healing_intent"] = {
                "type": "HealingIntent",
                "recommendations": self.recommendations,
                "requires_execution": True
            }
        return data
    
    @classmethod
    def from_arf_analysis(cls, arf_result: Dict, scenario_name: str) -> 'OSSAnalysis':
        """Create from actual ARF analysis result"""
        recommendations = arf_result.get("recommendations", [
            "Increase resource allocation",
            "Implement monitoring",
            "Add circuit breakers",
            "Optimize configuration"
        ])
        
        return cls(
            status="βœ… ARF OSS Analysis Complete",
            recommendations=recommendations,
            estimated_time="45-90 minutes",
            engineers_needed="2-3 engineers",
            manual_effort="High",
            confidence_score=0.92,
            healing_intent={
                "scenario": scenario_name,
                "actions": recommendations,
                "execution_required": True,
                "auto_execution": False  # OSS is advisory only
            }
        )

@dataclass
class EnterpriseResults:
    """Structured enterprise execution results"""
    actions_completed: List[str]
    metrics_improvement: Dict[str, str]
    business_impact: Dict[str, Any]
    approval_required: bool = True
    execution_time: str = ""
    healing_intent_executed: bool = True
    
    def to_dict(self) -> Dict:
        data = asdict(self)
        data["arf_enterprise"] = {
            "execution_complete": True,
            "learning_applied": True,
            "audit_trail_created": True
        }
        return data

@dataclass
class IncidentScenario:
    """Pythonic incident scenario model with ARF integration"""
    name: str
    severity: IncidentSeverity
    metrics: Dict[str, str]
    impact: Dict[str, str]
    arf_pattern: str = ""  # ARF pattern name for RAG recall
    oss_analysis: Optional[OSSAnalysis] = None
    enterprise_results: Optional[EnterpriseResults] = None
    
    def to_dict(self) -> Dict:
        """Convert to dictionary for JSON serialization"""
        data = {
            "name": self.name,
            "severity": self.severity.value,
            "metrics": self.metrics,
            "impact": self.impact,
            "arf_oss_available": ARF_OSS_AVAILABLE
        }
        if self.oss_analysis:
            data["oss_analysis"] = self.oss_analysis.to_dict()
        if self.enterprise_results:
            data["enterprise_results"] = self.enterprise_results.to_dict()
        return data

@dataclass
class DemoStep:
    """Demo step for presenter guidance"""
    title: str
    scenario: Optional[str]
    action: str
    message: str
    icon: str = "🎯"
    arf_integration: bool = False

# ===========================================
# INCIDENT DATABASE - ADD THIS CLASS
# ===========================================

class IncidentDatabase:
    """Database of incident scenarios for the demo"""
    
    @staticmethod
    def get_scenarios() -> Dict[str, IncidentScenario]:
        """Get all incident scenarios"""
        cache_miss = IncidentScenario(
            name="Cache Miss Storm",
            severity=IncidentSeverity.CRITICAL,
            metrics={
                "Cache Hit Rate": "18.5% (Critical)",
                "Database Load": "92% (Overloaded)",
                "Response Time": "1850ms (Slow)",
                "Affected Users": "45,000",
                "Eviction Rate": "125/sec"
            },
            impact={
                "Revenue Loss": "$8,500/hour",
                "Page Load Time": "+300%",
                "Users Impacted": "45,000",
                "SLA Violation": "Yes",
                "Customer Satisfaction": "-40%"
            },
            arf_pattern="cache_miss_storm",
            oss_analysis=OSSAnalysis(
                status="βœ… Analysis Complete",
                recommendations=[
                    "Increase Redis cache memory allocation by 2x",
                    "Implement cache warming strategy with predictive loading",
                    "Optimize key patterns and implement TTL adjustments",
                    "Add circuit breaker for graceful database fallback",
                    "Deploy monitoring for cache hit rate trends"
                ],
                estimated_time="60-90 minutes",
                engineers_needed="2-3 SREs + 1 DBA",
                manual_effort="High",
                confidence_score=0.92,
                healing_intent={
                    "type": "scale_out",
                    "resource": "cache",
                    "scale_factor": 2.0
                }
            ),
            enterprise_results=EnterpriseResults(
                actions_completed=[
                    "βœ… Auto-scaled Redis cluster: 4GB β†’ 8GB",
                    "βœ… Deployed intelligent cache warming service",
                    "βœ… Optimized 12 key patterns with ML recommendations",
                    "βœ… Implemented circuit breaker with 95% success rate",
                    "βœ… Validated recovery with automated testing"
                ],
                metrics_improvement={
                    "Cache Hit Rate": "18.5% β†’ 72%",
                    "Response Time": "1850ms β†’ 450ms",
                    "Database Load": "92% β†’ 45%",
                    "Throughput": "1250 β†’ 2450 req/sec"
                },
                business_impact={
                    "Recovery Time": "60 min β†’ 12 min",
                    "Cost Saved": "$7,200",
                    "Users Impacted": "45,000 β†’ 0",
                    "Revenue Protected": "$1,700",
                    "MTTR Improvement": "80% reduction"
                },
                approval_required=True,
                execution_time="8 minutes"
            )
        )
        
        db_exhaustion = IncidentScenario(
            name="Database Connection Pool Exhaustion",
            severity=IncidentSeverity.HIGH,
            metrics={
                "Active Connections": "98/100 (Critical)",
                "API Latency": "2450ms",
                "Error Rate": "15.2%",
                "Queue Depth": "1250",
                "Connection Wait Time": "45s"
            },
            impact={
                "Revenue Loss": "$4,200/hour",
                "Affected Services": "API Gateway, User Service, Payment Service",
                "SLA Violation": "Yes",
                "Partner Impact": "3 external APIs"
            },
            arf_pattern="db_connection_exhaustion",
            oss_analysis=OSSAnalysis(
                status="βœ… Analysis Complete",
                recommendations=[
                    "Increase connection pool size from 100 to 200",
                    "Add connection timeout (30s)",
                    "Implement leak detection",
                    "Add connection health checks",
                    "Optimize query patterns"
                ],
                estimated_time="45-60 minutes",
                engineers_needed="1-2 DBAs",
                manual_effort="Medium-High",
                confidence_score=0.88
            )
        )
        
        memory_leak = IncidentScenario(
            name="Memory Leak in Production",
            severity=IncidentSeverity.HIGH,
            metrics={
                "Memory Usage": "96% (Critical)",
                "GC Pause Time": "4500ms",
                "Error Rate": "28.5%",
                "Restart Frequency": "12/hour",
                "Heap Fragmentation": "42%"
            },
            impact={
                "Revenue Loss": "$5,500/hour",
                "Session Loss": "8,500 users",
                "Customer Impact": "High",
                "Support Tickets": "+300%"
            },
            arf_pattern="memory_leak_java",
            oss_analysis=OSSAnalysis(
                status="βœ… Analysis Complete",
                recommendations=[
                    "Increase JVM heap size from 4GB to 8GB",
                    "Implement memory leak detection with profiling",
                    "Add proactive health checks",
                    "Schedule rolling restart with zero downtime",
                    "Deploy memory monitoring dashboard"
                ],
                estimated_time="75-90 minutes",
                engineers_needed="2 Java SREs",
                manual_effort="High",
                confidence_score=0.85
            )
        )
        
        api_rate_limit = IncidentScenario(
            name="API Rate Limit Exceeded",
            severity=IncidentSeverity.MEDIUM,
            metrics={
                "429 Error Rate": "42.5%",
                "Successful Requests": "58.3%",
                "API Latency": "120ms",
                "Queue Depth": "1250",
                "Client Satisfaction": "65/100"
            },
            impact={
                "Revenue Loss": "$1,800/hour",
                "Affected Partners": "8",
                "Partner SLA Violations": "3",
                "Business Impact": "Medium"
            },
            arf_pattern="api_rate_limit"
        )
        
        return {
            "Cache Miss Storm": cache_miss,
            "Database Connection Pool Exhaustion": db_exhaustion,
            "Memory Leak in Production": memory_leak,
            "API Rate Limit Exceeded": api_rate_limit
        }