File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change 3
3
ref. https://github.com/tadata-org/fastapi_mcp/blob/v0.3.4/examples/shared/apps/items.py
4
4
"""
5
5
6
+ import random
6
7
from os import getenv
7
8
8
9
from azure .monitor .opentelemetry import configure_azure_monitor
@@ -136,3 +137,28 @@ async def search_items(
136
137
]
137
138
for item in sample_items :
138
139
items_db [item .id ] = item
140
+
141
+
142
+ # Add flaky API which receives percentage of failure
143
+ @app .get ("/flaky/{failure_rate}" , tags = ["flaky" ], operation_id = "flaky" )
144
+ async def flaky (failure_rate : int ):
145
+ """
146
+ A flaky endpoint that simulates a failure based on the provided failure rate.
147
+
148
+ The failure rate is a percentage (0-100) that determines the likelihood of failure.
149
+ """
150
+ if not (0 <= failure_rate <= 100 ):
151
+ raise HTTPException (
152
+ status_code = 400 ,
153
+ detail = "Failure rate must be between 0 and 100" ,
154
+ )
155
+
156
+ if random .randint (0 , 100 ) < failure_rate :
157
+ raise HTTPException (
158
+ status_code = 500 ,
159
+ detail = "Simulated failure" ,
160
+ )
161
+
162
+ return {
163
+ "message" : "Request succeeded" ,
164
+ }
You can’t perform that action at this time.
0 commit comments