Spaces:
Build error
Build error
| """ | |
| Seed RAG graph with historical healing action success rates. | |
| Run once before starting the API server. | |
| """ | |
| import sys | |
| import os | |
| sys.path.append(os.path.dirname(__file__)) | |
| from app.core.deps import get_rag_graph | |
| from agentic_reliability_framework.core.models.event import HealingAction | |
| def seed_historical_data(): | |
| rag = get_rag_graph() | |
| # Define seed incidents (each with an outcome) | |
| seed_data = [ | |
| # restart_container successes | |
| {"incident_id": "seed_restart_1", "component": "test", "action": HealingAction.RESTART_CONTAINER.value, "success": True, "resolution_time_minutes": 2}, | |
| {"incident_id": "seed_restart_2", "component": "test", "action": HealingAction.RESTART_CONTAINER.value, "success": True, "resolution_time_minutes": 3}, | |
| {"incident_id": "seed_restart_3", "component": "test", "action": HealingAction.RESTART_CONTAINER.value, "success": False, "resolution_time_minutes": 10}, | |
| # rollback successes | |
| {"incident_id": "seed_rollback_1", "component": "test", "action": HealingAction.ROLLBACK.value, "success": True, "resolution_time_minutes": 1}, | |
| {"incident_id": "seed_rollback_2", "component": "test", "action": HealingAction.ROLLBACK.value, "success": True, "resolution_time_minutes": 2}, | |
| {"incident_id": "seed_rollback_3", "component": "test", "action": HealingAction.ROLLBACK.value, "success": False, "resolution_time_minutes": 5}, | |
| # scale_out successes | |
| {"incident_id": "seed_scale_1", "component": "test", "action": HealingAction.SCALE_OUT.value, "success": True, "resolution_time_minutes": 5}, | |
| {"incident_id": "seed_scale_2", "component": "test", "action": HealingAction.SCALE_OUT.value, "success": False, "resolution_time_minutes": 15}, | |
| # circuit_breaker successes | |
| {"incident_id": "seed_cb_1", "component": "test", "action": HealingAction.CIRCUIT_BREAKER.value, "success": True, "resolution_time_minutes": 1}, | |
| {"incident_id": "seed_cb_2", "component": "test", "action": HealingAction.CIRCUIT_BREAKER.value, "success": True, "resolution_time_minutes": 2}, | |
| # traffic_shift successes | |
| {"incident_id": "seed_ts_1", "component": "test", "action": HealingAction.TRAFFIC_SHIFT.value, "success": True, "resolution_time_minutes": 4}, | |
| {"incident_id": "seed_ts_2", "component": "test", "action": HealingAction.TRAFFIC_SHIFT.value, "success": False, "resolution_time_minutes": 8}, | |
| ] | |
| # Add each outcome to the RAG graph | |
| for item in seed_data: | |
| # Create a dummy reliability event (simplified) | |
| from agentic_reliability_framework.core.models.event import ReliabilityEvent | |
| event = ReliabilityEvent( | |
| component=item["component"], | |
| latency_p99=500, # placeholder | |
| error_rate=0.1, | |
| service_mesh="default" | |
| ) | |
| # Record the outcome | |
| rag.record_outcome( | |
| incident_id=item["incident_id"], | |
| event=event, | |
| action_taken=item["action"], | |
| success=item["success"], | |
| resolution_time_minutes=item["resolution_time_minutes"] | |
| ) | |
| print(f"Seeded: {item['action']} -> success={item['success']}") | |
| print(f"Seeded {len(seed_data)} historical outcomes.") | |
| print(f"Stats per action:") | |
| for action in HealingAction: | |
| stats = rag.get_historical_effectiveness(action.value, component_filter="test") | |
| print(f" {action.value}: uses={stats['total_uses']}, success_rate={stats['success_rate']:.2f}, avg_time={stats['avg_resolution_time_minutes']:.1f} min") | |
| if __name__ == "__main__": | |
| seed_historical_data() | |