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

feat: only send critical alerts on endpoint #902

Merged
merged 1 commit into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/codegate/api/v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from uuid import UUID

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

try:
alerts = await dbreader.get_alerts_by_workspace(ws.id)
alerts = await dbreader.get_alerts_by_workspace(ws.id, AlertSeverity.CRITICAL.value)
prompts_outputs = await dbreader.get_prompts_with_output(ws.id)
return await v1_processing.parse_get_alert_conversation(alerts, prompts_outputs)
except Exception:
Expand Down
14 changes: 11 additions & 3 deletions src/codegate/db/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,9 @@ async def get_prompts_with_output(self, workpace_id: str) -> List[GetPromptWithO
)
return prompts

async def get_alerts_by_workspace(self, workspace_id: str) -> List[Alert]:
async def get_alerts_by_workspace(
self, workspace_id: str, trigger_category: Optional[str] = None
) -> List[Alert]:
sql = text(
"""
SELECT
Expand All @@ -594,10 +596,16 @@ async def get_alerts_by_workspace(self, workspace_id: str) -> List[Alert]:
FROM alerts a
INNER JOIN prompts p ON p.id = a.prompt_id
WHERE p.workspace_id = :workspace_id
ORDER BY a.timestamp DESC
"""
"""
)
conditions = {"workspace_id": workspace_id}

if trigger_category:
sql = text(sql.text + " AND a.trigger_category = :trigger_category")
conditions["trigger_category"] = trigger_category

sql = text(sql.text + " ORDER BY a.timestamp DESC")

prompts = await self._exec_select_conditions_to_pydantic(
Alert, sql, conditions, should_raise=True
)
Expand Down