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

Commitda749ae

Browse files
committed
feat(coderd/database): rewriteGetUserLatencyInsights to usetemplate_usage_stats
1 parenta6a8055 commitda749ae

File tree

11 files changed

+79
-47
lines changed

11 files changed

+79
-47
lines changed

‎coderd/apidoc/docs.go

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/apidoc/swagger.json

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/database/dbmem/dbmem.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4318,7 +4318,8 @@ func (q *FakeQuerier) GetUserLatencyInsights(_ context.Context, arg database.Get
43184318
AvatarURL:user.AvatarURL,
43194319
TemplateIDs:templateIDs,
43204320
WorkspaceConnectionLatency50:tryPercentile(latencies,50),
4321-
WorkspaceConnectionLatency95:tryPercentile(latencies,95),
4321+
WorkspaceConnectionLatency90:tryPercentile(latencies,90),
4322+
WorkspaceConnectionLatency99:tryPercentile(latencies,99),
43224323
}
43234324
rows=append(rows,row)
43244325
}

‎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
@@ -211,7 +211,8 @@ func TestUserLatencyInsights(t *testing.T) {
211211
logger:=slogtest.Make(t,nil)
212212
client:=coderdtest.New(t,&coderdtest.Options{
213213
IncludeProvisionerDaemon:true,
214-
AgentStatsRefreshInterval:time.Millisecond*100,
214+
AgentStatsRefreshInterval:time.Millisecond*50,
215+
DBRollupInterval:time.Millisecond*100,
215216
})
216217

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

297299
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 {

‎docs/api/insights.md

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎docs/api/schemas.md

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

‎site/src/api/typesGenerated.ts

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp