fix(metrics): seed the latest table in the background, not in the migration (#5208)
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:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user