4a7f24348c
- Add instance_events and health_checks tables with Alembic migration - InstanceEventBus: typed pub/sub singleton with wildcard support - HealthMonitor: async background loop polling containers every 15s - SSE endpoint GET /events/stream with auth and connection limits - Lifecycle hooks in tool_instances.py (create/start/stop/restart/delete) - Structured JSON logging with correlation IDs - 15 new unit tests (EventBus, HealthMonitor, MonitoringModels) Quality gates: pytest 15 new passed, ruff clean
40 lines
1.2 KiB
Python
40 lines
1.2 KiB
Python
"""SQLAlchemy model for instance lifecycle event audit rows."""
|
|
|
|
import uuid
|
|
from datetime import datetime
|
|
from typing import Any
|
|
|
|
from sqlalchemy import DateTime, ForeignKey, JSON, String, Text, Uuid, func
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
|
|
|
from src.models.base import Base, UUIDPrimaryKeyMixin
|
|
|
|
|
|
class InstanceEvent(UUIDPrimaryKeyMixin, Base):
|
|
__tablename__ = "instance_events"
|
|
|
|
instance_id: Mapped[uuid.UUID] = mapped_column(
|
|
Uuid(as_uuid=True),
|
|
ForeignKey("tool_instances.id", ondelete="CASCADE"),
|
|
nullable=False,
|
|
)
|
|
event_type: Mapped[str] = mapped_column(String(50), nullable=False)
|
|
status: Mapped[str | None] = mapped_column(String(50), nullable=True)
|
|
message: Mapped[str | None] = mapped_column(Text, nullable=True)
|
|
created_by: Mapped[uuid.UUID | None] = mapped_column(
|
|
Uuid(as_uuid=True),
|
|
ForeignKey("users.id", ondelete="SET NULL"),
|
|
nullable=True,
|
|
)
|
|
event_metadata: Mapped[dict[str, Any]] = mapped_column(
|
|
"metadata",
|
|
JSON,
|
|
nullable=False,
|
|
default=dict,
|
|
)
|
|
created_at: Mapped[datetime] = mapped_column(
|
|
DateTime(timezone=True),
|
|
server_default=func.now(),
|
|
nullable=False,
|
|
)
|