fix(metrics): seed the latest table in the background, not in the migration (#5208)
CI / lint (push) Successful in 3s
CI / integration (push) Successful in 1m7s
CI / unit (push) Successful in 1m23s
CI / publish (push) Successful in 1m0s

Migration 0030 seeded plugin_metric_latest from the whole history: two index
probes per distinct metric key. On the live instance that held the first
boot for 7+ minutes with Steward down. The migration now only creates the
table. Live sources fill it on their next sample, and backfill_latest runs
after startup for resources that have history but no latest rows. Per
resource it does one backward probe for the last sample, then takes the
newest value per metric within the hour before it. Resources that already
have rows are skipped, so later boots only walk the resource names.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-06 23:19:38 -04:00
co-authored by Claude Opus 5.5
parent 1845ba973c
commit 8941ed0372
4 changed files with 100 additions and 26 deletions
+9
View File
@@ -362,10 +362,19 @@ def create_app(
if not testing:
await _mark_interrupted_runs(app)
asyncio.create_task(_run_scheduler(app))
app._latest_backfill = asyncio.create_task(_backfill_latest(app))
return app
async def _backfill_latest(app: Quart) -> None:
from .core.metric_series import backfill_latest
try:
await backfill_latest(app.db_sessionmaker, app.logger)
except Exception:
app.logger.exception("latest metrics: backfill failed; quiet resources fill on their next sample")
def _register_core_tasks(app: Quart) -> None:
from .core.scheduler import ScheduledTask