Skip to content

Commit f91b3ac

Browse files
authored
fix: group routine workspace agent stats by id (#6601)
Before this was creating separate rows for distinct stat entries, which resulted in significantly more data being sent to telemetry.
1 parent 17bc579 commit f91b3ac

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

coderd/database/queries.sql.go

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries/workspaceagentstats.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ WITH agent_stats AS (
9292
WHERE workspace_agent_stats.created_at > $1 AND connection_median_latency_ms > 0 GROUP BY user_id, agent_id, workspace_id, template_id
9393
), latest_agent_stats AS (
9494
SELECT
95+
a.agent_id,
9596
coalesce(SUM(session_count_vscode), 0)::bigint AS session_count_vscode,
9697
coalesce(SUM(session_count_ssh), 0)::bigint AS session_count_ssh,
9798
coalesce(SUM(session_count_jetbrains), 0)::bigint AS session_count_jetbrains,
@@ -101,4 +102,4 @@ WITH agent_stats AS (
101102
FROM workspace_agent_stats WHERE created_at > $1
102103
) AS a WHERE a.rn = 1 GROUP BY a.user_id, a.agent_id, a.workspace_id, a.template_id
103104
)
104-
SELECT * FROM agent_stats, latest_agent_stats;
105+
SELECT * FROM agent_stats JOIN latest_agent_stats ON agent_stats.agent_id = latest_agent_stats.agent_id;

0 commit comments

Comments
 (0)