mirror of
https://github.com/coder/coder.git
synced 2025-07-06 15:41:45 +00:00
refactor(coderd): add avatar URL to the users' latency endpoint (#8701)
This commit is contained in:
4
coderd/apidoc/docs.go
generated
4
coderd/apidoc/docs.go
generated
@ -9916,6 +9916,10 @@ const docTemplate = `{
|
||||
"codersdk.UserLatency": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"avatar_url": {
|
||||
"type": "string",
|
||||
"format": "uri"
|
||||
},
|
||||
"latency_ms": {
|
||||
"$ref": "#/definitions/codersdk.ConnectionLatency"
|
||||
},
|
||||
|
4
coderd/apidoc/swagger.json
generated
4
coderd/apidoc/swagger.json
generated
@ -8966,6 +8966,10 @@
|
||||
"codersdk.UserLatency": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"avatar_url": {
|
||||
"type": "string",
|
||||
"format": "uri"
|
||||
},
|
||||
"latency_ms": {
|
||||
"$ref": "#/definitions/codersdk.ConnectionLatency"
|
||||
},
|
||||
|
@ -2369,6 +2369,7 @@ func (q *FakeQuerier) GetUserLatencyInsights(_ context.Context, arg database.Get
|
||||
row := database.GetUserLatencyInsightsRow{
|
||||
UserID: userID,
|
||||
Username: user.Username,
|
||||
AvatarURL: user.AvatarURL,
|
||||
TemplateIDs: templateIDs,
|
||||
WorkspaceConnectionLatency50: tryPercentile(latencies, 50),
|
||||
WorkspaceConnectionLatency95: tryPercentile(latencies, 95),
|
||||
|
@ -1545,6 +1545,7 @@ const getUserLatencyInsights = `-- name: GetUserLatencyInsights :many
|
||||
SELECT
|
||||
workspace_agent_stats.user_id,
|
||||
users.username,
|
||||
users.avatar_url,
|
||||
array_agg(DISTINCT template_id)::uuid[] AS template_ids,
|
||||
coalesce((PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY connection_median_latency_ms)), -1)::FLOAT AS workspace_connection_latency_50,
|
||||
coalesce((PERCENTILE_CONT(0.95) WITHIN GROUP (ORDER BY connection_median_latency_ms)), -1)::FLOAT AS workspace_connection_latency_95
|
||||
@ -1556,7 +1557,7 @@ WHERE
|
||||
AND workspace_agent_stats.connection_median_latency_ms > 0
|
||||
AND workspace_agent_stats.connection_count > 0
|
||||
AND CASE WHEN COALESCE(array_length($3::uuid[], 1), 0) > 0 THEN template_id = ANY($3::uuid[]) ELSE TRUE END
|
||||
GROUP BY workspace_agent_stats.user_id, users.username
|
||||
GROUP BY workspace_agent_stats.user_id, users.username, users.avatar_url
|
||||
ORDER BY user_id ASC
|
||||
`
|
||||
|
||||
@ -1567,11 +1568,12 @@ type GetUserLatencyInsightsParams struct {
|
||||
}
|
||||
|
||||
type GetUserLatencyInsightsRow struct {
|
||||
UserID uuid.UUID `db:"user_id" json:"user_id"`
|
||||
Username string `db:"username" json:"username"`
|
||||
TemplateIDs []uuid.UUID `db:"template_ids" json:"template_ids"`
|
||||
WorkspaceConnectionLatency50 float64 `db:"workspace_connection_latency_50" json:"workspace_connection_latency_50"`
|
||||
WorkspaceConnectionLatency95 float64 `db:"workspace_connection_latency_95" json:"workspace_connection_latency_95"`
|
||||
UserID uuid.UUID `db:"user_id" json:"user_id"`
|
||||
Username string `db:"username" json:"username"`
|
||||
AvatarURL sql.NullString `db:"avatar_url" json:"avatar_url"`
|
||||
TemplateIDs []uuid.UUID `db:"template_ids" json:"template_ids"`
|
||||
WorkspaceConnectionLatency50 float64 `db:"workspace_connection_latency_50" json:"workspace_connection_latency_50"`
|
||||
WorkspaceConnectionLatency95 float64 `db:"workspace_connection_latency_95" json:"workspace_connection_latency_95"`
|
||||
}
|
||||
|
||||
// GetUserLatencyInsights returns the median and 95th percentile connection
|
||||
@ -1590,6 +1592,7 @@ func (q *sqlQuerier) GetUserLatencyInsights(ctx context.Context, arg GetUserLate
|
||||
if err := rows.Scan(
|
||||
&i.UserID,
|
||||
&i.Username,
|
||||
&i.AvatarURL,
|
||||
pq.Array(&i.TemplateIDs),
|
||||
&i.WorkspaceConnectionLatency50,
|
||||
&i.WorkspaceConnectionLatency95,
|
||||
|
@ -6,6 +6,7 @@
|
||||
SELECT
|
||||
workspace_agent_stats.user_id,
|
||||
users.username,
|
||||
users.avatar_url,
|
||||
array_agg(DISTINCT template_id)::uuid[] AS template_ids,
|
||||
coalesce((PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY connection_median_latency_ms)), -1)::FLOAT AS workspace_connection_latency_50,
|
||||
coalesce((PERCENTILE_CONT(0.95) WITHIN GROUP (ORDER BY connection_median_latency_ms)), -1)::FLOAT AS workspace_connection_latency_95
|
||||
@ -17,7 +18,7 @@ WHERE
|
||||
AND workspace_agent_stats.connection_median_latency_ms > 0
|
||||
AND workspace_agent_stats.connection_count > 0
|
||||
AND CASE WHEN COALESCE(array_length(@template_ids::uuid[], 1), 0) > 0 THEN template_id = ANY(@template_ids::uuid[]) ELSE TRUE END
|
||||
GROUP BY workspace_agent_stats.user_id, users.username
|
||||
GROUP BY workspace_agent_stats.user_id, users.username, users.avatar_url
|
||||
ORDER BY user_id ASC;
|
||||
|
||||
-- name: GetTemplateInsights :one
|
||||
|
@ -117,6 +117,7 @@ func (api *API) insightsUserLatency(rw http.ResponseWriter, r *http.Request) {
|
||||
TemplateIDs: row.TemplateIDs,
|
||||
UserID: row.UserID,
|
||||
Username: row.Username,
|
||||
AvatarURL: row.AvatarURL.String,
|
||||
LatencyMS: codersdk.ConnectionLatency{
|
||||
P50: row.WorkspaceConnectionLatency50,
|
||||
P95: row.WorkspaceConnectionLatency95,
|
||||
|
Reference in New Issue
Block a user