DaCrow13 commited on
Commit
1caca0e
·
1 Parent(s): b22bd7a

Remove test endpoints and script after verifying alerts

Browse files
hopcroft_skill_classification_tool_competition/main.py CHANGED
@@ -13,8 +13,6 @@ Endpoints:
13
  GET /health - Health check
14
  POST /predict - Single issue classification
15
  POST /predict/batch - Batch classification
16
- GET /test/500 - Trigger 500 error (Testing only)
17
- GET /test/slow - Trigger slow response (Testing only)
18
  """
19
 
20
  from contextlib import asynccontextmanager
@@ -22,7 +20,6 @@ from datetime import datetime
22
  import json
23
  import os
24
  import time
25
- import asyncio
26
  from typing import List
27
 
28
  from fastapi import FastAPI, HTTPException, Request, Response, status
@@ -487,22 +484,6 @@ async def list_predictions(skip: int = 0, limit: int = 10) -> List[PredictionRec
487
  )
488
 
489
 
490
- @app.get("/test/500", include_in_schema=False)
491
- async def test_500_error():
492
- """Trigger a 500 error for testing alerts."""
493
- raise HTTPException(
494
- status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
495
- detail="Test 500 Error Triggered",
496
- )
497
-
498
-
499
- @app.get("/test/slow", include_in_schema=False)
500
- async def test_slow_request():
501
- """Trigger a slow response for testing alerts."""
502
- await asyncio.sleep(3) # Sleep for 3 seconds (alert threshold is 2s)
503
- return {"message": "Slow response completed"}
504
-
505
-
506
  @app.exception_handler(ValidationError)
507
  async def validation_exception_handler(request, exc: ValidationError):
508
  """Handle Pydantic validation errors."""
 
13
  GET /health - Health check
14
  POST /predict - Single issue classification
15
  POST /predict/batch - Batch classification
 
 
16
  """
17
 
18
  from contextlib import asynccontextmanager
 
20
  import json
21
  import os
22
  import time
 
23
  from typing import List
24
 
25
  from fastapi import FastAPI, HTTPException, Request, Response, status
 
484
  )
485
 
486
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
487
  @app.exception_handler(ValidationError)
488
  async def validation_exception_handler(request, exc: ValidationError):
489
  """Handle Pydantic validation errors."""
scripts/trigger_alerts.py DELETED
@@ -1,33 +0,0 @@
1
- import requests
2
- import time
3
- import sys
4
-
5
- SPACE_URL = "https://dacrow13-hopcroft-skill-classification.hf.space"
6
-
7
- def trigger_500_errors(count=20):
8
- print(f"Triggering {count} 500 errors...")
9
- for i in range(count):
10
- try:
11
- requests.get(f"{SPACE_URL}/test/500")
12
- print(f"Request {i+1}/{count} sent", end="\r")
13
- except Exception as e:
14
- print(f"Error sending request: {e}")
15
- time.sleep(0.5)
16
- print("\nDone triggering 500 errors.")
17
-
18
- def trigger_slow_requests(count=10):
19
- print(f"Triggering {count} slow requests...")
20
- for i in range(count):
21
- try:
22
- requests.get(f"{SPACE_URL}/test/slow")
23
- print(f"Request {i+1}/{count} sent", end="\r")
24
- except Exception as e:
25
- print(f"Error sending request: {e}")
26
- # No sleep needed here as the request itself takes 3s
27
- print("\nDone triggering slow requests.")
28
-
29
- if __name__ == "__main__":
30
- print("Starting alert trigger script...")
31
- trigger_500_errors()
32
- trigger_slow_requests()
33
- print("Check Prometheus Alerts tab: https://dacrow13-hopcroft-skill-classification.hf.space/prometheus/alerts")