Skip to content

Commit 5f640eb

Browse files
authored
fix: correct connection_median_latency_ms in query (#15086)
Closes #14805
1 parent c81fd1d commit 5f640eb

File tree

3 files changed

+16
-30
lines changed

3 files changed

+16
-30
lines changed

coderd/database/queries.sql.go

Lines changed: 8 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries/insights.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ WITH
661661
AND date_trunc('minute', was.created_at) = mb.minute_bucket
662662
AND was.template_id = mb.template_id
663663
AND was.user_id = mb.user_id
664-
AND was.connection_median_latency_ms >= 0
664+
AND was.connection_median_latency_ms > 0
665665
GROUP BY
666666
mb.start_time, mb.template_id, mb.user_id
667667
)

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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy