@@ -188,8 +188,9 @@ WITH agent_stats AS (
188
188
coalesce((PERCENTILE_CONT(0 .5 ) WITHIN GROUP (ORDER BY connection_median_latency_ms)), - 1 )::FLOAT AS workspace_connection_latency_50,
189
189
coalesce((PERCENTILE_CONT(0 .95 ) WITHIN GROUP (ORDER BY connection_median_latency_ms)), - 1 )::FLOAT AS workspace_connection_latency_95
190
190
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
193
194
), latest_agent_stats AS (
194
195
SELECT
195
196
a .agent_id ,
@@ -332,9 +333,11 @@ WITH agent_stats AS (
332
333
agent_id,
333
334
workspace_id,
334
335
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
336
338
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
338
341
GROUP BY user_id, agent_id, workspace_id
339
342
), latest_agent_stats AS (
340
343
SELECT
@@ -349,12 +352,6 @@ WITH agent_stats AS (
349
352
-- spread across multiple rows.
350
353
WHERE usage = true AND created_at > now() - ' 1 minute' ::interval
351
354
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
358
355
)
359
356
SELECT
360
357
users .username , workspace_agents .name AS agent_name, workspaces .name AS workspace_name, rx_bytes, tx_bytes,
@@ -370,10 +367,6 @@ LEFT JOIN
370
367
latest_agent_stats
371
368
ON
372
369
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
377
370
JOIN
378
371
users
379
372
ON
0 commit comments