File size: 2,115 Bytes
d416acc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
""" what it does :
 is that Stores different API failure scenarios. 
 When the agent starts a new episode, 
 this file picks a random failure for the agent to debug.
"""
import random 

INCIDENTS =[ # here we created mutiple incidents and in different episodes different incidents will be checked 
  {
  "type": "auth_error",
  "summary": "401 Unnathorized - API key expired",
  "logs": ["ERROR : there is inavlid API key", "HINT : your key expired already "],
  "fix_action": "refresh_token",
  "code":401
},

{
  "type": "missing_fields",
  "summary": "400 bad request - email field is missing please check",
  "logs": ["ERROR :Required field 'email' cannot be found" , "HINT : please add email to the request body "],
  "fix_action": "add_field",
  "code":400
},

{
  "type": "rate_limit",
  "summary": "429 too many requests - slow down ",
  "logs": ["ERROR : the rate limit is exceeded   " , "HINT : please wait for 1 minute before retrying "],
  "fix_action": "wait_retry",
  "code":429
},

{
  "type": "wrong_endpoint",
  "summary": "404 Not Found - API endpoint doesn't exist",
  "logs": ["ERROR: POST /api/v2/data returned 404", "Hint: Use /api/v3/data instead"],
  "fix_action": "change_endpoint",
  "code": 404
},

{
  "type": "server_error",
  "summary": "500 Internal Server Error",
  "logs": ["ERROR: Database connection failed", "Hint: Cannot fix automatically - escalate"],
  "fix_action": "escalate",
  "code": 500
},

{
  "type": "timeout",
  "summary": "request took too long",
  "logs": ["ERROR : request timed out after 45 seconds", "Hint: server may be overloaded , please try again with backoff"],
  "fix_action": "wait_retry",
  "code": 408 
},

]

def get_random_incident():
    # this function is  to  return a random choice 
    return random.choice(INCIDENTS)

def get_incident_by_type(incident_type):
    # Returns a specific incident - useful for grading system (score/marks/points)
    for incident in INCIDENTS: # here we are having a loop 
        if incident["type"] == incident_type: # we chechking here if type matches or not 
            return incident
    return None