Skip to content

feat(coderd/database): keep only 1 day of workspace_agent_stats after rollup #12674

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 22, 2024

Conversation

mafredri
Copy link
Member

@mafredri mafredri commented Mar 19, 2024

This will free up many gigabytes of data for many customers, more for those that have a lot of workspaces running daily.

Refs #12122

@mafredri mafredri force-pushed the mafredri/fix-insights-tests-after-refactor branch from 77ba7dc to 754fdd5 Compare March 19, 2024 16:25
@mafredri mafredri force-pushed the mafredri/keep-only-1-day-of-agent-stats branch from 5024af0 to 9286a28 Compare March 19, 2024 16:25
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a maximum number of rows that could be deleted here?
Would it make sense to add a limit on the number of rows deleted?
My thinking is that we could choose a reasonably large upper limit and hopefully converge after a few iterations.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a bad idea. Limiting would only be relevant for the first time(s) this query runs, after that there's no point but if we want to avoid the initial performance penalty of doing a huge delete, that would be sensible. There's no limit for deletes though so we could rely on selecting the min(created_at) and only delete 1 (or N days) of data.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thinking deleting the oldest day of data every interval will probably work fine here. The magnitude of that data should scale with the size of the deployment. We'll have to assume that the database is correctly sized to handle that level of deletes, but if not that is likely a sizing issue with the database itself in relation to the rest of the deployment.

@mafredri mafredri force-pushed the mafredri/fix-insights-tests-after-refactor branch from 754fdd5 to 7128953 Compare March 20, 2024 10:25
@mafredri mafredri force-pushed the mafredri/keep-only-1-day-of-agent-stats branch from 9286a28 to 95cdaca Compare March 20, 2024 10:25
created_at < (
SELECT
COALESCE(
-- When generating initial template usage stats, all the
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change may be little too soon to drop. If customers identify problems with the release, they will decide to roll back to the previous version. Boom! No workspace_agent_stats anymore.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, I made this a separate PR so we can defer it for later.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rollbacks require db backups at present. We just do not support downgrades at present.

And not supported like, you can't even really do it. You have to run the migration downgrade with the latest version, then rollback. We have 0 documentation for this, so no customer should do it.

@mafredri mafredri changed the title feat(coderd/database): keep only 1 day of workspace_agent_stats after rollup feat(coderd/database): DO NOT MERGE: keep only 1 day of workspace_agent_stats after rollup Mar 20, 2024
@mafredri mafredri force-pushed the mafredri/fix-insights-tests-after-refactor branch from 7128953 to b915c4c Compare March 20, 2024 12:37
@mafredri mafredri changed the base branch from mafredri/fix-insights-tests-after-refactor to mafredri/add-sftp-to-insights-apps March 20, 2024 12:37
@mafredri mafredri force-pushed the mafredri/keep-only-1-day-of-agent-stats branch from 95cdaca to 8a2d9f8 Compare March 20, 2024 12:37
@mafredri mafredri force-pushed the mafredri/add-sftp-to-insights-apps branch from 1477d70 to d982c5b Compare March 20, 2024 14:53
@mafredri mafredri force-pushed the mafredri/keep-only-1-day-of-agent-stats branch from 8a2d9f8 to ad2b3e7 Compare March 20, 2024 14:53
@mafredri mafredri force-pushed the mafredri/add-sftp-to-insights-apps branch from d982c5b to 71cd6ff Compare March 20, 2024 16:03
@mafredri mafredri force-pushed the mafredri/keep-only-1-day-of-agent-stats branch from ad2b3e7 to 8442baa Compare March 20, 2024 16:03
@mafredri mafredri force-pushed the mafredri/add-sftp-to-insights-apps branch from 71cd6ff to fb7f72c Compare March 20, 2024 19:04
@mafredri mafredri force-pushed the mafredri/keep-only-1-day-of-agent-stats branch from 8442baa to 563ad78 Compare March 20, 2024 19:04
@mafredri mafredri force-pushed the mafredri/keep-only-1-day-of-agent-stats branch from 6c31bbb to 364b21e Compare March 25, 2024 12:53
@mafredri mafredri force-pushed the mafredri/add-sftp-to-insights-apps branch from 140017a to eb01ba5 Compare March 25, 2024 12:56
@mafredri mafredri force-pushed the mafredri/keep-only-1-day-of-agent-stats branch from 364b21e to 3e356f2 Compare March 25, 2024 12:56
@mafredri mafredri force-pushed the mafredri/add-sftp-to-insights-apps branch from eb01ba5 to 1ef1513 Compare March 25, 2024 13:18
@mafredri mafredri force-pushed the mafredri/keep-only-1-day-of-agent-stats branch from 3e356f2 to ccb914c Compare March 25, 2024 13:18
@mafredri mafredri force-pushed the mafredri/add-sftp-to-insights-apps branch from 1ef1513 to e720b91 Compare March 27, 2024 12:01
@mafredri mafredri force-pushed the mafredri/keep-only-1-day-of-agent-stats branch from ccb914c to 1489cd6 Compare March 27, 2024 12:01
Base automatically changed from mafredri/add-sftp-to-insights-apps to main March 27, 2024 12:09
@mafredri mafredri force-pushed the mafredri/keep-only-1-day-of-agent-stats branch from 1489cd6 to 859f9d4 Compare March 28, 2024 11:02
@github-actions github-actions bot added the stale This issue is like stale bread. label Apr 5, 2024
@github-actions github-actions bot closed this Apr 8, 2024
@mafredri mafredri reopened this Apr 8, 2024
@github-actions github-actions bot removed the stale This issue is like stale bread. label Apr 9, 2024
@mafredri mafredri force-pushed the mafredri/keep-only-1-day-of-agent-stats branch from 859f9d4 to 89ecbf2 Compare April 9, 2024 12:20
@mafredri mafredri marked this pull request as ready for review April 9, 2024 12:21
@mafredri
Copy link
Member Author

mafredri commented Apr 9, 2024

@johnstcn I've added the batch deleting in case you want to take a look.

@mafredri mafredri force-pushed the mafredri/keep-only-1-day-of-agent-stats branch from 89ecbf2 to b5b95d2 Compare April 9, 2024 12:22
@mafredri mafredri changed the title feat(coderd/database): DO NOT MERGE: keep only 1 day of workspace_agent_stats after rollup feat(coderd/database): keep only 1 day of workspace_agent_stats after rollup Apr 9, 2024
Copy link
Member

@johnstcn johnstcn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just needs a make gen

@mafredri mafredri force-pushed the mafredri/keep-only-1-day-of-agent-stats branch from b5b95d2 to 18b45c2 Compare April 9, 2024 13:27
@github-actions github-actions bot added the stale This issue is like stale bread. label Apr 17, 2024
@github-actions github-actions bot closed this Apr 21, 2024
@mafredri mafredri reopened this Apr 22, 2024
@mafredri mafredri removed the stale This issue is like stale bread. label Apr 22, 2024
Copy link
Member

@mtojek mtojek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@mafredri mafredri merged commit e17e8aa into main Apr 22, 2024
55 checks passed
@mafredri mafredri deleted the mafredri/keep-only-1-day-of-agent-stats branch April 22, 2024 10:11
@github-actions github-actions bot locked and limited conversation to collaborators Apr 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants