refactor(docker): container CPU and memory live in the one metric store (#5752)
CI / lint (push) Successful in 3s
CI / integration (push) Failing after 1m18s
CI / unit (push) Successful in 1m24s
CI / publish (push) Skipped

#5752 "Container CPU and memory history lives in the one metric store;
docker_metrics and docker_metrics_hourly are retired". Container cpu_pct and
mem_pct already went to plugin_metrics for alerting; now mem_usage_bytes does
too, and every snapshot in an ingest (backlog included) is recorded at its
own time. The container history chart, Busiest Containers, a service's
history and the MCP container tools read plugin_metrics under resource
"<host>/<container>", rolled up and pruned by the shared metric retention.

docker_012_drop_metrics drops both tables. Their history is not copied
(lesson #5221 "A data migration's cost is set by the live table"); the
store already holds 7 days of container CPU and memory %. Docker retention
now prunes only lifecycle events, and Settings -> Thresholds has one
"Metric retention" card for every source.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-14 14:39:56 -04:00
co-authored by Claude Opus 5.5
parent b889584906
commit 5a0e150789
19 changed files with 242 additions and 430 deletions
@@ -36,6 +36,7 @@ def _docker(sub):
def test_a_service_page_reads_every_task(app):
from steward.models.hosts import Host
from steward.models.metrics import PluginMetric
from steward.models.users import User, UserRole
m = _docker("models")
@@ -57,8 +58,10 @@ def test_a_service_page_reads_every_task(app):
"exit_code": 1, "at": iso(now - timedelta(minutes=10))}]
def sample(cname, mins, cpu, mem):
return m.DockerMetric(host_id=hid, container_name=cname, scraped_at=now - timedelta(minutes=mins),
cpu_pct=cpu, mem_pct=0.0, mem_usage_bytes=mem)
when = now - timedelta(minutes=mins)
return [PluginMetric(source_module="docker", resource_name=f"dock-{tag}/{cname}",
metric_name=metric, value=value, recorded_at=when)
for metric, value in (("cpu_pct", cpu), ("mem_usage_bytes", mem))]
async def go():
async with app.db_sessionmaker() as s:
@@ -86,9 +89,9 @@ def test_a_service_page_reads_every_task(app):
ts=now - timedelta(minutes=5)),
m.DockerLog(host_id=hid, container_name=dead, stream="stderr", line=f"panic {tag}",
ts=now - timedelta(minutes=10)),
sample(dead, 40, 200.0, 300 << 20), sample(live, 30, 40.0, 90 << 20),
sample(live, 20, 60.0, 100 << 20), sample(live, 1, 50.0, 100 << 20),
])
s.add_all(sample(dead, 40, 200.0, 300 << 20) + sample(live, 30, 40.0, 90 << 20)
+ sample(live, 20, 60.0, 100 << 20) + sample(live, 1, 50.0, 100 << 20))
client = app.test_client()
async with client.session_transaction() as sess: