Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb1e5d1a

Browse files
committed
feat(coderd/database): rewriteGetUserLatencyInsights to usetemplate_usage_stats
1 parentdb6c026 commitb1e5d1a

File tree

6 files changed

+55
-38
lines changed

6 files changed

+55
-38
lines changed

‎coderd/database/dbmem/dbmem.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4056,7 +4056,8 @@ func (q *FakeQuerier) GetUserLatencyInsights(_ context.Context, arg database.Get
40564056
AvatarURL:user.AvatarURL,
40574057
TemplateIDs:templateIDs,
40584058
WorkspaceConnectionLatency50:tryPercentile(latencies,50),
4059-
WorkspaceConnectionLatency95:tryPercentile(latencies,95),
4059+
WorkspaceConnectionLatency90:tryPercentile(latencies,90),
4060+
WorkspaceConnectionLatency99:tryPercentile(latencies,99),
40604061
}
40614062
rows=append(rows,row)
40624063
}

‎coderd/database/queries.sql.go

Lines changed: 25 additions & 18 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/database/queries/insights.sql

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,27 @@
44
-- template_ids, meaning only user data from workspaces based on those templates
55
-- will be included.
66
SELECT
7-
workspace_agent_stats.user_id,
8-
users.username,
9-
users.avatar_url,
10-
array_agg(DISTINCT template_id)::uuid[]AS template_ids,
11-
coalesce((PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY connection_median_latency_ms)),-1)::FLOATAS workspace_connection_latency_50,
12-
coalesce((PERCENTILE_CONT(0.95) WITHIN GROUP (ORDER BY connection_median_latency_ms)),-1)::FLOATAS workspace_connection_latency_95
13-
FROM workspace_agent_stats
14-
JOIN usersON (users.id=workspace_agent_stats.user_id)
7+
tus.user_id,
8+
u.username,
9+
u.avatar_url,
10+
array_agg(DISTINCTtus.template_id)::uuid[]AS template_ids,
11+
COALESCE((PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BYtus.median_latency_ms)),-1)::floatAS workspace_connection_latency_50,
12+
COALESCE((PERCENTILE_CONT(0.90) WITHIN GROUP (ORDER BYtus.median_latency_ms)),-1)::floatAS workspace_connection_latency_90,
13+
COALESCE((PERCENTILE_CONT(0.99) WITHIN GROUP (ORDER BYtus.median_latency_ms)),-1)::floatAS workspace_connection_latency_99
14+
FROM
15+
template_usage_stats tus
16+
JOIN
17+
users u
18+
ON
19+
u.id=tus.user_id
1520
WHERE
16-
workspace_agent_stats.created_at>= @start_time
17-
ANDworkspace_agent_stats.created_at< @end_time
18-
ANDworkspace_agent_stats.connection_median_latency_ms>0
19-
ANDworkspace_agent_stats.connection_count>0
20-
AND CASE WHEN COALESCE(array_length(@template_ids::uuid[],1),0)>0 THEN template_id= ANY(@template_ids::uuid[]) ELSE TRUE END
21-
GROUP BYworkspace_agent_stats.user_id,users.username,users.avatar_url
22-
ORDER BYuser_idASC;
21+
tus.start_time>= @start_time::timestamptz
22+
ANDtus.end_time<= @end_time::timestamptz
23+
ANDCASE WHEN COALESCE(array_length(@template_ids::uuid[],1),0)>0 THENtus.template_id= ANY(@template_ids::uuid[]) ELSE TRUE END
24+
GROUP BY
25+
tus.user_id,u.username,u.avatar_url
26+
ORDER BY
27+
tus.user_idASC;
2328

2429
-- name: GetUserActivityInsights :many
2530
-- GetUserActivityInsights returns the ranking with top active users.

‎coderd/insights.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,8 @@ func (api *API) insightsUserLatency(rw http.ResponseWriter, r *http.Request) {
215215
AvatarURL:row.AvatarURL,
216216
LatencyMS: codersdk.ConnectionLatency{
217217
P50:row.WorkspaceConnectionLatency50,
218-
P95:row.WorkspaceConnectionLatency95,
218+
P90:row.WorkspaceConnectionLatency90,
219+
P99:row.WorkspaceConnectionLatency99,
219220
},
220221
})
221222
}

‎coderd/insights_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,8 @@ func TestUserLatencyInsights(t *testing.T) {
210210
logger:=slogtest.Make(t,nil)
211211
client:=coderdtest.New(t,&coderdtest.Options{
212212
IncludeProvisionerDaemon:true,
213-
AgentStatsRefreshInterval:time.Millisecond*100,
213+
AgentStatsRefreshInterval:time.Millisecond*50,
214+
DBRollupInterval:time.Millisecond*100,
214215
})
215216

216217
// Create two users, one that will appear in the report and another that
@@ -290,7 +291,8 @@ func TestUserLatencyInsights(t *testing.T) {
290291
require.Len(t,userLatencies.Report.Users,1,"want only 1 user")
291292
require.Equal(t,userLatencies.Report.Users[0].UserID,user.UserID,"want user id to match")
292293
assert.Greater(t,userLatencies.Report.Users[0].LatencyMS.P50,float64(0),"want p50 to be greater than 0")
293-
assert.Greater(t,userLatencies.Report.Users[0].LatencyMS.P95,float64(0),"want p95 to be greater than 0")
294+
assert.Greater(t,userLatencies.Report.Users[0].LatencyMS.P90,float64(0),"want p90 to be greater than 0")
295+
assert.Greater(t,userLatencies.Report.Users[0].LatencyMS.P99,float64(0),"want p99 to be greater than 0")
294296
}
295297

296298
funcTestUserLatencyInsights_BadRequest(t*testing.T) {

‎codersdk/insights.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ type UserActivity struct {
9898
// ConnectionLatency shows the latency for a connection.
9999
typeConnectionLatencystruct {
100100
P50float64`json:"p50" example:"31.312"`
101-
P95float64`json:"p95" example:"119.832"`
101+
P90float64`json:"p90" example:"119.832"`
102+
P99float64`json:"p99" example:"432.34"`
102103
}
103104

104105
typeUserLatencyInsightsRequeststruct {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp