AgentEvalTool/migrations/versions/c8f3e9a2b4d1_add_alert_history_table.py
sinohqb 2e7d419f05 feat(intelligent-eval): implement monitoring and alerting (ticket 07)
- Add metrics.py with pool utilization, task backlog, stuck rate, avg processing time, eval completion rate
- Add alerts.py with alert rules (pool utilization > 90%, task backlog > 50, stuck rate > 10%)
- Implement alert history and webhook notifications
- Add metrics and alerts APIs
- Add database migration for alert history table
- Add 11 unit tests for metrics, 10 unit tests for alerts, 8 integration tests
- Update migration tests to include new alert history table

All 853 tests passing.
2026-08-12 10:41:15 +08:00

49 lines
1.8 KiB
Python

"""add alert history table
Revision ID: c8f3e9a2b4d1
Revises: b72debf55c3b
Create Date: 2026-08-12 10:00:00.000000
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
import sqlmodel
# revision identifiers, used by Alembic.
revision: str = 'c8f3e9a2b4d1'
down_revision: Union[str, Sequence[str], None] = 'b72debf55c3b'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
"""Upgrade schema."""
op.create_table(
'cron_pool_alert_history',
sa.Column('id', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column('alert_type', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column('severity', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column('message', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column('metric_value', sa.Float(), nullable=False),
sa.Column('threshold', sa.Float(), nullable=False),
sa.Column('created_at', sa.DateTime(), nullable=False),
sa.Column('resolved_at', sa.DateTime(), nullable=True),
sa.Column('webhook_sent', sa.Boolean(), nullable=False, default=False),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('cron_pool_alert_history', schema=None) as batch_op:
batch_op.create_index('ix_cron_pool_alert_history_alert_type', ['alert_type'], unique=False)
batch_op.create_index('ix_cron_pool_alert_history_severity', ['severity'], unique=False)
def downgrade() -> None:
"""Downgrade schema."""
with op.batch_alter_table('cron_pool_alert_history', schema=None) as batch_op:
batch_op.drop_index('ix_cron_pool_alert_history_severity')
batch_op.drop_index('ix_cron_pool_alert_history_alert_type')
op.drop_table('cron_pool_alert_history')