File size: 8,574 Bytes
4bf781a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from __future__ import annotations

from tasks.base_task import BaseTask


class MediumTask(BaseTask):
    def __init__(self) -> None:
        self.task_id = "cascading-db-overload"
        self.difficulty = "medium"
        self.incident_summary = (
            "checkout-service and order-processor are degraded. Root signal suggests a "
            "Postgres connection pool exhaustion after config drift."
        )
        self.all_services = [
            "postgres",
            "checkout-service",
            "order-processor",
            "auth-service",
        ]
        self.root_cause_service = "postgres"
        self.affected_services = ["postgres", "checkout-service", "order-processor"]
        self.dependency_graph = {
            "postgres": [],
            "checkout-service": ["postgres"],
            "order-processor": ["postgres", "checkout-service"],
            "auth-service": ["postgres"],
        }
        self.resolution_actions = [
            {
                "action_type": "update_config",
                "params": {
                    "service": "postgres",
                    "key": "max_connections",
                    "value": 50,
                },
                "allow_string_number": True,
                "resolves_fault": True,
                "state_updates": {
                    "postgres": {
                        "fault_active": False,
                        "fault_type": None,
                        "config": {"max_connections": 50},
                        "metrics": {
                            "status": "healthy",
                            "error_rate": 0.03,
                            "latency_p99_ms": 35.0,
                            "cpu_percent": 55.0,
                        },
                    }
                },
            },
            {
                "action_type": "restart_service",
                "params": {"service": "checkout-service"},
                "resolves_fault": True,
                "state_updates": {
                    "checkout-service": {
                        "fault_active": False,
                        "fault_type": None,
                        "metrics": {
                            "status": "healthy",
                            "error_rate": 0.04,
                            "latency_p99_ms": 300.0,
                            "cpu_percent": 45.0,
                        },
                    }
                },
            },
            {
                "action_type": "mark_resolved",
                "params": {},
            },
        ]
        self.red_herring_services = ["auth-service"]
        self.strict_sequence = True

    def initial_state(self) -> dict:
        return {
            "postgres": {
                "metrics": {
                    "service": "postgres",
                    "cpu_percent": 95.0,
                    "memory_mb": 3800.0,
                    "error_rate": 0.80,
                    "latency_p99_ms": 8000.0,
                    "status": "degraded",
                },
                "logs": [
                    {
                        "timestamp": "2026-04-11T10:03:00Z",
                        "service": "postgres",
                        "level": "FATAL",
                        "message": "FATAL: remaining connection slots are reserved",
                    },
                    {
                        "timestamp": "2026-04-11T10:03:05Z",
                        "service": "postgres",
                        "level": "ERROR",
                        "message": "connection pool exhausted: max_connections=5",
                    },
                ],
                "deployments": [
                    {
                        "service": "postgres",
                        "version": "14.11",
                        "deployed_at": "2026-03-28T03:00:00Z",
                        "deployed_by": "db-admin",
                        "config_hash": "cfg-db-overload",
                    }
                ],
                "config": {"max_connections": 5},
                "fault_active": True,
                "fault_type": "exhausted_pool",
                "current_version": "14.11",
                "secondary_fault": False,
                "replicas": 1,
            },
            "checkout-service": {
                "metrics": {
                    "service": "checkout-service",
                    "cpu_percent": 70.0,
                    "memory_mb": 900.0,
                    "error_rate": 0.60,
                    "latency_p99_ms": 5000.0,
                    "status": "degraded",
                },
                "logs": [
                    {
                        "timestamp": "2026-04-11T10:03:10Z",
                        "service": "checkout-service",
                        "level": "ERROR",
                        "message": "could not connect to database: too many clients",
                    }
                ],
                "deployments": [
                    {
                        "service": "checkout-service",
                        "version": "v3.7.0",
                        "deployed_at": "2026-04-11T08:20:00Z",
                        "deployed_by": "ci",
                        "config_hash": "cfg-checkout-370",
                    }
                ],
                "config": {},
                "fault_active": True,
                "fault_type": "secondary_db_pressure",
                "current_version": "v3.7.0",
                "secondary_fault": True,
                "requires_restart_after_upstream_fix": True,
                "replicas": 4,
            },
            "order-processor": {
                "metrics": {
                    "service": "order-processor",
                    "cpu_percent": 65.0,
                    "memory_mb": 850.0,
                    "error_rate": 0.55,
                    "latency_p99_ms": 6200.0,
                    "status": "degraded",
                },
                "logs": [
                    {
                        "timestamp": "2026-04-11T10:03:12Z",
                        "service": "order-processor",
                        "level": "ERROR",
                        "message": "downstream checkout timeout while acquiring DB session",
                    }
                ],
                "deployments": [
                    {
                        "service": "order-processor",
                        "version": "v2.9.3",
                        "deployed_at": "2026-04-11T08:30:00Z",
                        "deployed_by": "ci",
                        "config_hash": "cfg-order-293",
                    }
                ],
                "config": {},
                "fault_active": True,
                "fault_type": "secondary_cascade",
                "current_version": "v2.9.3",
                "secondary_fault": True,
                "replicas": 3,
            },
            "auth-service": {
                "metrics": {
                    "service": "auth-service",
                    "cpu_percent": 25.0,
                    "memory_mb": 400.0,
                    "error_rate": 0.05,
                    "latency_p99_ms": 200.0,
                    "status": "healthy",
                },
                "logs": [
                    {
                        "timestamp": "2026-04-11T09:58:00Z",
                        "service": "auth-service",
                        "level": "WARN",
                        "message": "deploy event: v1.4.2 rolled out",
                    }
                ],
                "deployments": [
                    {
                        "service": "auth-service",
                        "version": "v1.4.2",
                        "deployed_at": "2026-04-11T09:56:00Z",
                        "deployed_by": "release-bot",
                        "config_hash": "cfg-auth-142",
                    }
                ],
                "config": {},
                "fault_active": False,
                "fault_type": None,
                "current_version": "v1.4.2",
                "secondary_fault": False,
                "replicas": 2,
            },
        }

    def is_resolved(self, state: dict) -> bool:
        postgres = state.get("postgres", {})
        checkout = state.get("checkout-service", {})
        order_proc = state.get("order-processor", {})
        return (
            postgres.get("fault_active") is False
            and checkout.get("fault_active") is False
            and order_proc.get("fault_active") is False
        )