Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1cc10f2

Browse files
authored
fix: only sum connection latencies when they are set (#6524)
This was producing a median that didn't make sense.
1 parent 1199a93 commit 1cc10f2

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

coderd/database/dbfake/databasefake.go

+3
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,9 @@ func (q *fakeQuerier) GetDeploymentWorkspaceAgentStats(_ context.Context, create
340340

341341
latencies := make([]float64, 0)
342342
for _, agentStat := range agentStatsCreatedAfter {
343+
if agentStat.ConnectionMedianLatencyMS <= 0 {
344+
continue
345+
}
343346
stat.WorkspaceRxBytes += agentStat.RxBytes
344347
stat.WorkspaceTxBytes += agentStat.TxBytes
345348
latencies = append(latencies, agentStat.ConnectionMedianLatencyMS)

coderd/database/queries.sql.go

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries/workspaceagentstats.sql

+2-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ WITH agent_stats AS (
6060
coalesce((PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY connection_median_latency_ms)), -1)::FLOAT AS workspace_connection_latency_50,
6161
coalesce((PERCENTILE_CONT(0.95) WITHIN GROUP (ORDER BY connection_median_latency_ms)), -1)::FLOAT AS workspace_connection_latency_95
6262
FROM workspace_agent_stats
63-
WHERE workspace_agent_stats.created_at > $1
63+
-- The greater than 0 is to support legacy agents that don't report connection_median_latency_ms.
64+
WHERE workspace_agent_stats.created_at > $1 AND connection_median_latency_ms > 0
6465
), latest_agent_stats AS (
6566
SELECT
6667
coalesce(SUM(session_count_vscode), 0)::bigint AS session_count_vscode,

0 commit comments

Comments
 (0)