petter2025 commited on
Commit
4a3065f
·
verified ·
1 Parent(s): e2044c9

Create models.py

Browse files
Files changed (1) hide show
  1. models.py +71 -0
models.py ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from pydantic import BaseModel, Field
2
+ from typing import Optional, Dict, List, Any
3
+ from enum import Enum
4
+ import datetime
5
+ import hashlib
6
+
7
+ class EventSeverity(Enum):
8
+ LOW = "low"
9
+ MEDIUM = "medium"
10
+ HIGH = "high"
11
+ CRITICAL = "critical"
12
+
13
+ class HealingAction(Enum):
14
+ RESTART_CONTAINER = "restart_container"
15
+ SCALE_OUT = "scale_out"
16
+ TRAFFIC_SHIFT = "traffic_shift"
17
+ CIRCUIT_BREAKER = "circuit_breaker"
18
+ ROLLBACK = "rollback"
19
+ ALERT_TEAM = "alert_team"
20
+ NO_ACTION = "no_action"
21
+
22
+ class ReliabilityEvent(BaseModel):
23
+ timestamp: str = Field(default_factory=lambda: datetime.datetime.now().isoformat())
24
+ component: str
25
+ service_mesh: str = "default"
26
+
27
+ # Core metrics
28
+ latency_p99: float = Field(ge=0)
29
+ error_rate: float = Field(ge=0, le=1)
30
+ throughput: float = Field(ge=0)
31
+
32
+ # Resource metrics
33
+ cpu_util: Optional[float] = Field(default=None, ge=0, le=1)
34
+ memory_util: Optional[float] = Field(default=None, ge=0, le=1)
35
+
36
+ # Business metrics
37
+ revenue_impact: Optional[float] = Field(default=None, ge=0)
38
+ user_impact: Optional[int] = Field(default=None, ge=0)
39
+
40
+ # Topology context
41
+ upstream_deps: List[str] = Field(default_factory=list)
42
+ downstream_deps: List[str] = Field(default_factory=list)
43
+
44
+ severity: EventSeverity = EventSeverity.LOW
45
+ fingerprint: str = Field(default="")
46
+
47
+ def __init__(self, **data):
48
+ super().__init__(**data)
49
+ # Generate fingerprint for deduplication
50
+ if not self.fingerprint:
51
+ fingerprint_str = f"{self.component}_{self.latency_p99}_{self.error_rate}_{self.timestamp}"
52
+ self.fingerprint = hashlib.md5(fingerprint_str.encode()).hexdigest()
53
+
54
+ class Config:
55
+ use_enum_values = True
56
+
57
+ class HealingPolicy(BaseModel):
58
+ name: str
59
+ conditions: Dict[str, Any]
60
+ actions: List[HealingAction]
61
+ priority: int = Field(ge=1, le=5)
62
+ cool_down_seconds: int = 300
63
+ enabled: bool = True
64
+
65
+ class AnomalyResult(BaseModel):
66
+ is_anomaly: bool
67
+ confidence: float
68
+ predicted_cause: str
69
+ recommended_actions: List[HealingAction]
70
+ similar_incidents: List[str] = Field(default_factory=list)
71
+ business_impact: Optional[Dict[str, Any]] = None