Skip to content

Commit e0464a9

Browse files
committed
fix: correct connection_median_latency_ms in query
1 parent 208ed1e commit e0464a9

File tree

2 files changed

+14
-28
lines changed

2 files changed

+14
-28
lines changed

coderd/database/queries.sql.go

Lines changed: 7 additions & 14 deletions
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: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,9 @@ WITH agent_stats AS (
188188
coalesce((PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY connection_median_latency_ms)), -1)::FLOAT AS workspace_connection_latency_50,
189189
coalesce((PERCENTILE_CONT(0.95) WITHIN GROUP (ORDER BY connection_median_latency_ms)), -1)::FLOAT AS workspace_connection_latency_95
190190
FROM workspace_agent_stats
191-
-- The greater than 0 is to support legacy agents that don't report connection_median_latency_ms.
192-
WHERE workspace_agent_stats.created_at > $1 AND connection_median_latency_ms > 0 GROUP BY user_id, agent_id, workspace_id, template_id
191+
-- The greater than 0 is to support legacy agents that don't report connection_median_latency_ms.
192+
WHERE workspace_agent_stats.created_at > $1 AND connection_median_latency_ms > 0
193+
GROUP BY user_id, agent_id, workspace_id, template_id
193194
), latest_agent_stats AS (
194195
SELECT
195196
a.agent_id,
@@ -332,9 +333,11 @@ WITH agent_stats AS (
332333
agent_id,
333334
workspace_id,
334335
coalesce(SUM(rx_bytes), 0)::bigint AS rx_bytes,
335-
coalesce(SUM(tx_bytes), 0)::bigint AS tx_bytes
336+
coalesce(SUM(tx_bytes), 0)::bigint AS tx_bytes,
337+
coalesce(MAX(connection_median_latency_ms), 0)::float AS connection_median_latency_ms
336338
FROM workspace_agent_stats
337-
WHERE workspace_agent_stats.created_at > $1
339+
-- The greater than 0 is to support legacy agents that don't report connection_median_latency_ms.
340+
WHERE workspace_agent_stats.created_at > $1 AND connection_median_latency_ms > 0
338341
GROUP BY user_id, agent_id, workspace_id
339342
), latest_agent_stats AS (
340343
SELECT
@@ -349,12 +352,6 @@ WITH agent_stats AS (
349352
-- spread across multiple rows.
350353
WHERE usage = true AND created_at > now() - '1 minute'::interval
351354
GROUP BY user_id, agent_id, workspace_id
352-
), latest_agent_latencies AS (
353-
SELECT
354-
agent_id,
355-
coalesce(MAX(connection_median_latency_ms), 0)::float AS connection_median_latency_ms
356-
FROM workspace_agent_stats
357-
GROUP BY user_id, agent_id, workspace_id
358355
)
359356
SELECT
360357
users.username, workspace_agents.name AS agent_name, workspaces.name AS workspace_name, rx_bytes, tx_bytes,
@@ -370,10 +367,6 @@ LEFT JOIN
370367
latest_agent_stats
371368
ON
372369
agent_stats.agent_id = latest_agent_stats.agent_id
373-
JOIN
374-
latest_agent_latencies
375-
ON
376-
agent_stats.agent_id = latest_agent_latencies.agent_id
377370
JOIN
378371
users
379372
ON

0 commit comments

Comments
 (0)