Skip to content
This repository was archived by the owner on Jun 5, 2025. It is now read-only.

Commit ed75a0b

Browse files
authored
feat: only send critical alerts on endpoint (#902)
To avoid noise and be more performant, only send alerts with category critical Closes: #842
1 parent 78a1e2c commit ed75a0b

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

src/codegate/api/v1.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from uuid import UUID
33

44
import requests
5+
from codegate.pipeline.base import AlertSeverity
56
import structlog
67
from fastapi import APIRouter, Depends, HTTPException, Response
78
from fastapi.responses import StreamingResponse
@@ -379,7 +380,7 @@ async def get_workspace_alerts(workspace_name: str) -> List[Optional[v1_models.A
379380
raise HTTPException(status_code=500, detail="Internal server error")
380381

381382
try:
382-
alerts = await dbreader.get_alerts_by_workspace(ws.id)
383+
alerts = await dbreader.get_alerts_by_workspace(ws.id, AlertSeverity.CRITICAL.value)
383384
prompts_outputs = await dbreader.get_prompts_with_output(ws.id)
384385
return await v1_processing.parse_get_alert_conversation(alerts, prompts_outputs)
385386
except Exception:

src/codegate/db/connection.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,9 @@ async def get_prompts_with_output(self, workpace_id: str) -> List[GetPromptWithO
580580
)
581581
return prompts
582582

583-
async def get_alerts_by_workspace(self, workspace_id: str) -> List[Alert]:
583+
async def get_alerts_by_workspace(
584+
self, workspace_id: str, trigger_category: Optional[str] = None
585+
) -> List[Alert]:
584586
sql = text(
585587
"""
586588
SELECT
@@ -594,10 +596,16 @@ async def get_alerts_by_workspace(self, workspace_id: str) -> List[Alert]:
594596
FROM alerts a
595597
INNER JOIN prompts p ON p.id = a.prompt_id
596598
WHERE p.workspace_id = :workspace_id
597-
ORDER BY a.timestamp DESC
598-
"""
599+
"""
599600
)
600601
conditions = {"workspace_id": workspace_id}
602+
603+
if trigger_category:
604+
sql = text(sql.text + " AND a.trigger_category = :trigger_category")
605+
conditions["trigger_category"] = trigger_category
606+
607+
sql = text(sql.text + " ORDER BY a.timestamp DESC")
608+
601609
prompts = await self._exec_select_conditions_to_pydantic(
602610
Alert, sql, conditions, should_raise=True
603611
)

0 commit comments

Comments
 (0)