fix(agent): persist signal incidents with tenant context
Some checks failed
CD Pipeline / workflow-shape (push) Successful in 0s
CD Pipeline / cancel-stale-cd (push) Has been skipped
CD Pipeline / build-and-deploy (push) Has been cancelled
CD Pipeline / post-deploy-checks (push) Has been cancelled
CD Pipeline / tests (push) Has been cancelled
Some checks failed
CD Pipeline / workflow-shape (push) Successful in 0s
CD Pipeline / cancel-stale-cd (push) Has been skipped
CD Pipeline / build-and-deploy (push) Has been cancelled
CD Pipeline / post-deploy-checks (push) Has been cancelled
CD Pipeline / tests (push) Has been cancelled
This commit is contained in:
@@ -1120,11 +1120,12 @@ class TimelineDBService:
|
||||
risk_level: str | None = None,
|
||||
approval_id: str | None = None,
|
||||
incident_id: str | None = None,
|
||||
project_id: str | None = None,
|
||||
) -> dict[str, Any]:
|
||||
"""
|
||||
新增時間軸事件
|
||||
"""
|
||||
async with get_db_context() as db:
|
||||
async with get_db_context(project_id) as db:
|
||||
event = TimelineEvent(
|
||||
event_type=event_type,
|
||||
status=status,
|
||||
|
||||
@@ -97,6 +97,8 @@ def _derive_incident_alert_metadata(incident: Incident) -> dict[str, Any]:
|
||||
async def _add_signal_timeline_event(
|
||||
incident: Incident,
|
||||
metadata: dict[str, Any],
|
||||
*,
|
||||
project_id: str,
|
||||
) -> None:
|
||||
"""Best-effort timeline seed for incidents created outside Alertmanager."""
|
||||
alertname = metadata.get("alertname")
|
||||
@@ -115,6 +117,7 @@ async def _add_signal_timeline_event(
|
||||
actor_role="signal_worker",
|
||||
risk_level=getattr(incident.severity, "value", incident.severity),
|
||||
incident_id=incident.incident_id,
|
||||
project_id=project_id,
|
||||
)
|
||||
except Exception as exc:
|
||||
logger.warning(
|
||||
@@ -137,10 +140,13 @@ class IncidentDbAdapter:
|
||||
注入到 lewooogo-brain 的 DualIncidentMemory
|
||||
"""
|
||||
|
||||
def __init__(self, project_id: str = "awoooi") -> None:
|
||||
self._project_id = project_id
|
||||
|
||||
async def load(self, incident_id: str) -> Incident | None:
|
||||
"""從 PostgreSQL 載入 Incident"""
|
||||
try:
|
||||
async with get_db_context() as db:
|
||||
async with get_db_context(self._project_id) as db:
|
||||
from sqlalchemy import select
|
||||
stmt = select(IncidentRecord).where(
|
||||
IncidentRecord.incident_id == incident_id
|
||||
@@ -161,7 +167,7 @@ class IncidentDbAdapter:
|
||||
metadata = _derive_incident_alert_metadata(incident)
|
||||
created = False
|
||||
try:
|
||||
async with get_db_context() as db:
|
||||
async with get_db_context(self._project_id) as db:
|
||||
from sqlalchemy import select
|
||||
|
||||
stmt = select(IncidentRecord).where(
|
||||
@@ -191,6 +197,7 @@ class IncidentDbAdapter:
|
||||
else:
|
||||
record = IncidentRecord(
|
||||
incident_id=incident.incident_id,
|
||||
project_id=self._project_id,
|
||||
status=incident.status.value,
|
||||
severity=incident.severity.value,
|
||||
signals=[
|
||||
@@ -222,7 +229,11 @@ class IncidentDbAdapter:
|
||||
created = True
|
||||
|
||||
if created:
|
||||
await _add_signal_timeline_event(incident, metadata)
|
||||
await _add_signal_timeline_event(
|
||||
incident,
|
||||
metadata,
|
||||
project_id=self._project_id,
|
||||
)
|
||||
logger.debug("db_adapter_save_success", incident_id=incident.incident_id)
|
||||
return True
|
||||
|
||||
|
||||
@@ -436,6 +436,7 @@ async def _add_observation_timeline(
|
||||
actor_role="signal_worker",
|
||||
risk_level=_severity_value(getattr(incident, "severity", None)),
|
||||
incident_id=_incident_id(incident),
|
||||
project_id=PROJECT_ID,
|
||||
)
|
||||
except Exception as exc:
|
||||
logger.warning(
|
||||
@@ -477,7 +478,10 @@ async def _ensure_signal_observation_mcp_runtime() -> None:
|
||||
try:
|
||||
from src.plugins.mcp.providers import register_all_providers
|
||||
from src.plugins.mcp.registry import get_provider_registry
|
||||
from src.services.mcp_tool_registry import get_mcp_tool_registry, init_mcp_tool_registry
|
||||
from src.services.mcp_tool_registry import (
|
||||
get_mcp_tool_registry,
|
||||
init_mcp_tool_registry,
|
||||
)
|
||||
|
||||
provider_registry = get_provider_registry()
|
||||
if len(provider_registry) == 0:
|
||||
|
||||
Reference in New Issue
Block a user