feat(timeline): one record of what happened to the infrastructure, newest first (#6348)
CI / lint (push) Successful in 2s
CI / unit (push) Failing after 1m31s
CI / integration (push) Successful in 1m41s
CI / publish (push) Skipped

A stored log, timeline_entries, with one row per thing that happened. Each
source writes its row in the same transaction as its own record, so the
history outlives the 30/90/365-day retention of the tables it points to:

- alert events (core/alerts._add_event): fired, resolved, acknowledged,
  went silent, readings back;
- finished Ansible runs (executor, and the startup sweep of interrupted
  runs): changed something, changed nothing, failed, dry run;
- audit rows (core/audit.log_audit): Steward's settings, users and access,
  sign-ins, backups. Actions another writer records are left to it.

Entries carry a kind (fixed) and an area (Service, Host OS, Hardware,
Storage, Network, Security, Monitoring). Settings → Timeline edits the
areas and each type's area and visibility; both are applied when the
timeline is read, so a change re-sorts past entries and a hidden type
comes back when shown. Kept forever unless a retention is set.

The first start fills the timeline from the last 90 days of records once,
skipping any already covered. A host rename carries its entries.

UI: Timeline in the sidebar (filter by host, area, kind; scrolls on), a
History card on each host page. MCP: get_timeline.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-24 17:03:05 -04:00
co-authored by Claude Opus 5.5
parent 8e2f17d198
commit 4ea735d87c
36 changed files with 1882 additions and 25 deletions
+24 -2
View File
@@ -233,6 +233,7 @@ def create_app(
from .audit.routes import audit_bp
from .ai_access.routes import ai_access_bp
from .account.routes import account_bp
from .timeline.routes import timeline_bp
app.register_blueprint(auth_bp)
app.register_blueprint(dashboard_bp)
@@ -247,6 +248,7 @@ def create_app(
app.register_blueprint(audit_bp)
app.register_blueprint(ai_access_bp)
app.register_blueprint(account_bp)
app.register_blueprint(timeline_bp)
# Register the unified Monitor status source for the Status page. Plugins
# may register additional sources from setup(). Idempotent.
@@ -580,15 +582,32 @@ def _register_core_tasks(app: Quart) -> None:
)
)
# The timeline's first fill from the records that predate it, after the
# first boot that has it; once done, each later turn is one settings read.
async def run_timeline_backfill():
from .timeline.service import backfill
await backfill(app)
app._task_registry.append(
ScheduledTask(
name="timeline_backfill",
coro_factory=run_timeline_backfill,
interval_seconds=86400,
run_on_startup=True,
)
)
async def _mark_interrupted_runs(app: Quart) -> None:
from sqlalchemy import update
from .models.ansible import AnsibleRun, AnsibleRunStatus
from datetime import datetime, timezone
from .timeline.record import run_finished
async with app.db_sessionmaker() as session:
async with session.begin():
await session.execute(
stopped = (await session.execute(
update(AnsibleRun)
.where(AnsibleRun.status.in_(
[AnsibleRunStatus.running, AnsibleRunStatus.queued]))
@@ -596,7 +615,10 @@ async def _mark_interrupted_runs(app: Quart) -> None:
status=AnsibleRunStatus.interrupted,
finished_at=datetime.now(timezone.utc),
)
)
.returning(AnsibleRun.id)
)).scalars().all()
for run_id in stopped:
await run_finished(session, run_id)
async def _run_scheduler(app: Quart) -> None: