Skip to content

Commit a5f0272

Browse files
committed
sum session counts during usagestatsandlabels
1 parent ca8498b commit a5f0272

File tree

4 files changed

+9
-19
lines changed

4 files changed

+9
-19
lines changed

coderd/database/dbmem/dbmem.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5829,12 +5829,10 @@ func (q *FakeQuerier) GetWorkspaceAgentUsageStatsAndLabels(_ context.Context, cr
58295829
if !ok {
58305830
latestAgentStats[key] = agentStat
58315831
} else {
5832-
if agentStat.CreatedAt.After(val.CreatedAt) || agentStat.CreatedAt.Equal(val.CreatedAt) {
5833-
val.SessionCountVSCode = agentStat.SessionCountVSCode
5834-
val.SessionCountJetBrains = agentStat.SessionCountJetBrains
5835-
val.SessionCountReconnectingPTY = agentStat.SessionCountReconnectingPTY
5836-
val.SessionCountSSH = agentStat.SessionCountSSH
5837-
}
5832+
val.SessionCountVSCode += agentStat.SessionCountVSCode
5833+
val.SessionCountJetBrains += agentStat.SessionCountJetBrains
5834+
val.SessionCountReconnectingPTY += agentStat.SessionCountReconnectingPTY
5835+
val.SessionCountSSH += agentStat.SessionCountSSH
58385836
val.ConnectionCount += agentStat.ConnectionCount
58395837
latestAgentStats[key] = val
58405838
}

coderd/database/querier_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ func TestGetWorkspaceAgentUsageStatsAndLabels(t *testing.T) {
372372
WorkspaceName: workspace1.Name,
373373
RxBytes: 3,
374374
TxBytes: 3,
375-
SessionCountVSCode: 2,
375+
SessionCountVSCode: 3,
376376
ConnectionMedianLatencyMS: 1,
377377
})
378378

coderd/database/queries.sql.go

Lines changed: 2 additions & 6 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: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -329,12 +329,8 @@ WITH agent_stats AS (
329329
coalesce(SUM(session_count_jetbrains), 0)::bigint AS session_count_jetbrains,
330330
coalesce(SUM(session_count_reconnecting_pty), 0)::bigint AS session_count_reconnecting_pty,
331331
coalesce(SUM(connection_count), 0)::bigint AS connection_count
332-
FROM (
333-
SELECT *, ROW_NUMBER() OVER (PARTITION BY user_id, agent_id, workspace_id ORDER BY created_at DESC) AS rn
334-
FROM workspace_agent_stats
335-
WHERE usage = true
336-
) as a
337-
WHERE a.rn = 1
332+
FROM workspace_agent_stats
333+
WHERE usage = true
338334
GROUP BY user_id, agent_id, workspace_id
339335
), latest_agent_latencies AS (
340336
SELECT

0 commit comments

Comments
 (0)