Skip to content

Commit ad2b3e7

Browse files
committed
feat(coderd/database): keep only 1 day of workspace_agent_stats after rollup
1 parent d982c5b commit ad2b3e7

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

coderd/database/queries.sql.go

+20-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries/workspaceagentstats.sql

+20-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,26 @@ ORDER BY
9090
date ASC;
9191

9292
-- name: DeleteOldWorkspaceAgentStats :exec
93-
DELETE FROM workspace_agent_stats WHERE created_at < NOW() - INTERVAL '180 days';
93+
DELETE FROM
94+
workspace_agent_stats
95+
WHERE
96+
created_at < (
97+
SELECT
98+
COALESCE(
99+
-- When generating initial template usage stats, all the
100+
-- raw agent stats are needed, after that only ~30 mins
101+
-- from last rollup is needed. Deployment stats seem to
102+
-- use between 15 mins and 1 hour of data. We keep a
103+
-- little bit more (1 day) just in case.
104+
MAX(start_time) - '1 days'::interval,
105+
-- Fall back to 180 days ago if there are no template
106+
-- usage stats so that we don't delete the data before
107+
-- it's rolled up.
108+
NOW() - '180 days'::interval
109+
)
110+
FROM
111+
template_usage_stats
112+
);
94113

95114
-- name: GetDeploymentWorkspaceAgentStats :one
96115
WITH agent_stats AS (

0 commit comments

Comments
 (0)