Skip to content

feat(coderd): support weekly aggregated insights #9684

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 16 commits into from
Sep 19, 2023

Conversation

mtojek
Copy link
Member

@mtojek mtojek commented Sep 14, 2023

Related: #9495

This PR exposes insights with interval=week aggregation via coderd API.

I think when the interval is set to week, a user should only be allowed to select increments of 7 days.

  1. I decided to allow for an incomplete week (= at least 6 days). This way we can handle /insights requests similarly to interval=day:

http://localhost:3000/api/v2/insights/templates?start_time=2023-09-09T00%3A00%3A00%2B02%3A00&end_time=2023-09-15T16%3A00%3A00%2B02%3A00&interval=week

(clock: 2023-09-15 16:34)
start_time: 2023-09-09 00:00
end_time: 2023-09-15 16:00

  1. It is allowed to fetch insights for every incomplete multiply of 7, so 6,.. , 13,..., 20,...
  2. Full 7-day request (2023-09-01 00:00 - 2023-09-08 00:00) will succeed too.

TODO:

  • codersdk supports interval=week
  • refactor: define insights interval #9693 DB queries are flexible and require argument for interval
    • GetTemplateDailyInsights
  • fix parsing request
  • adjust integration tests
  • extend agent logs window to 6 months (considering weekly intervals)

@mtojek mtojek self-assigned this Sep 14, 2023
@mtojek mtojek marked this pull request as ready for review September 15, 2023 15:42
@mtojek mtojek requested review from mafredri and johnstcn September 15, 2023 15:42
@@ -90,7 +90,7 @@ ORDER BY
date ASC;

-- name: DeleteOldWorkspaceAgentStats :exec
DELETE FROM workspace_agent_stats WHERE created_at < NOW() - INTERVAL '30 days';
DELETE FROM workspace_agent_stats WHERE created_at < NOW() - INTERVAL '6 months';
Copy link
Member

Choose a reason for hiding this comment

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

⚠️ Depending on the size of the deployment, this could be a big increase in database size. I'd recommend making this configurable.

Copy link
Member

Choose a reason for hiding this comment

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

I think it could be an acceptable new default value if we stopped writing "zero" data for agent stats, or if we deleted the "zero" data every 7 days and non-zero data every 6 months.

With "zero" data, I mean:

WHERE rx_bytes = 0
	AND rx_packets = 0
	AND tx_bytes = 0
	AND tx_packets = 0
	AND connections_by_proto = '{}'
	AND connection_count = 0
	AND connection_median_latency_ms = -0.001
	AND session_count_vscode = 0
	AND session_count_jetbrains = 0
	AND session_count_reconnecting_pty = 0
	AND session_count_ssh = 0

These rows don't tell us anything other than the agent is alive/sending data.

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 could extend the DELETE query to remove "zero" data, but then need to list all columns unless it is fine to mention only representatives like rx_bytes and tx_bytes? Otherwise, I'm afraid that somebody will and extra column and the DELETE query will stop working at all.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe a follow-up candidate.

Copy link
Member

@mafredri mafredri left a comment

Choose a reason for hiding this comment

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

Nice! Left a few comments but nothing major popped up 👍🏻

@@ -90,7 +90,7 @@ ORDER BY
date ASC;

-- name: DeleteOldWorkspaceAgentStats :exec
DELETE FROM workspace_agent_stats WHERE created_at < NOW() - INTERVAL '30 days';
DELETE FROM workspace_agent_stats WHERE created_at < NOW() - INTERVAL '6 months';
Copy link
Member

Choose a reason for hiding this comment

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

I think it could be an acceptable new default value if we stopped writing "zero" data for agent stats, or if we deleted the "zero" data every 7 days and non-zero data every 6 months.

With "zero" data, I mean:

WHERE rx_bytes = 0
	AND rx_packets = 0
	AND tx_bytes = 0
	AND tx_packets = 0
	AND connections_by_proto = '{}'
	AND connection_count = 0
	AND connection_median_latency_ms = -0.001
	AND session_count_vscode = 0
	AND session_count_jetbrains = 0
	AND session_count_reconnecting_pty = 0
	AND session_count_ssh = 0

These rows don't tell us anything other than the agent is alive/sending data.

@mtojek mtojek merged commit b0e3daa into main Sep 19, 2023
@mtojek mtojek deleted the 9495-support-interval-week branch September 19, 2023 11:06
@github-actions github-actions bot locked and limited conversation to collaborators Sep 19, 2023
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.

3 participants