refactor web pagination and add partitioned events, flap/timeout showcase agents
This commit is contained in:
@@ -50,10 +50,12 @@ def upgrade() -> None:
|
||||
)
|
||||
op.execute("CREATE INDEX checks_status_idx ON checks (status);")
|
||||
|
||||
# events: partitioned by RANGE(received_at). Partition key is part of PK per Postgres.
|
||||
# Global idempotency by event_id is enforced via event_ingest_dedup, not this table.
|
||||
op.execute(
|
||||
"""
|
||||
CREATE TABLE events (
|
||||
event_id UUID PRIMARY KEY,
|
||||
event_id UUID NOT NULL,
|
||||
agent_id TEXT NOT NULL,
|
||||
check_id TEXT NOT NULL,
|
||||
observed_at TIMESTAMPTZ NOT NULL,
|
||||
@@ -64,14 +66,30 @@ def upgrade() -> None:
|
||||
output TEXT,
|
||||
output_truncated BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
notifications_enabled BOOLEAN NOT NULL DEFAULT TRUE,
|
||||
incident_key TEXT NOT NULL
|
||||
);
|
||||
incident_key TEXT NOT NULL,
|
||||
PRIMARY KEY (event_id, received_at)
|
||||
) PARTITION BY RANGE (received_at);
|
||||
"""
|
||||
)
|
||||
op.execute(
|
||||
"CREATE INDEX events_agent_check_observed_idx ON events (agent_id, check_id, observed_at DESC);"
|
||||
)
|
||||
op.execute("CREATE INDEX events_observed_at_idx ON events (observed_at DESC);")
|
||||
op.execute("CREATE INDEX events_received_at_idx ON events (received_at DESC);")
|
||||
|
||||
# Global idempotency table: server enforces event_id uniqueness here, not on the
|
||||
# partitioned events table. Pruned by retention TTL (event_dedup_retention_days).
|
||||
op.execute(
|
||||
"""
|
||||
CREATE TABLE event_ingest_dedup (
|
||||
event_id UUID PRIMARY KEY,
|
||||
received_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
||||
);
|
||||
"""
|
||||
)
|
||||
op.execute(
|
||||
"CREATE INDEX event_ingest_dedup_received_at_idx ON event_ingest_dedup (received_at);"
|
||||
)
|
||||
|
||||
op.execute(
|
||||
"""
|
||||
@@ -119,6 +137,7 @@ def upgrade() -> None:
|
||||
def downgrade() -> None:
|
||||
op.execute("DROP TABLE IF EXISTS notification_outbox CASCADE;")
|
||||
op.execute("DROP TABLE IF EXISTS incidents CASCADE;")
|
||||
op.execute("DROP TABLE IF EXISTS event_ingest_dedup CASCADE;")
|
||||
op.execute("DROP TABLE IF EXISTS events CASCADE;")
|
||||
op.execute("DROP TABLE IF EXISTS checks CASCADE;")
|
||||
op.execute("DROP TABLE IF EXISTS agents CASCADE;")
|
||||
|
||||
Reference in New Issue
Block a user