feat(server): retention GenServer prunes samples older than 48h hourly

This commit is contained in:
Carsten 2026-04-21 22:29:24 +02:00
parent 751e035579
commit f09a77996b
3 changed files with 58 additions and 0 deletions

View file

@ -0,0 +1,21 @@
defmodule Server.RetentionTest do
use Server.DataCase, async: false
alias Server.{Hosts, Metrics, Retention}
test "prune_now/1 deletes samples older than the retention window" do
{:ok, {host, _}} = Hosts.create_host("pve-01")
stale_at = DateTime.add(DateTime.utc_now(), -49 * 3600, :second)
fresh_at = DateTime.add(DateTime.utc_now(), -60, :second)
{:ok, _} = Metrics.record_sample(host.id, "fast", stale_at, %{"x" => 1})
{:ok, fresh} = Metrics.record_sample(host.id, "fast", fresh_at, %{"x" => 2})
{deleted, _} = Retention.prune_now(48 * 3600)
assert deleted == 1
remaining = Server.Repo.all(Server.Schema.Metric)
assert length(remaining) == 1
assert hd(remaining).id == fresh.id
end
end