feat(server): retention GenServer prunes samples older than 48h hourly
This commit is contained in:
parent
751e035579
commit
f09a77996b
3 changed files with 58 additions and 0 deletions
21
server/test/server/retention_test.exs
Normal file
21
server/test/server/retention_test.exs
Normal 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue