refactor(coderd): add avatar URL to the users' latency endpoint (#8701)

This commit is contained in:
Bruno Quaresma
2023-07-25 12:15:46 +02:00
committed by GitHub
parent 7004013537
commit fbb2a6a434
10 changed files with 28 additions and 7 deletions
+4
View File
@@ -9916,6 +9916,10 @@ const docTemplate = `{
"codersdk.UserLatency": {
"type": "object",
"properties": {
"avatar_url": {
"type": "string",
"format": "uri"
},
"latency_ms": {
"$ref": "#/definitions/codersdk.ConnectionLatency"
},
+4
View File
@@ -8966,6 +8966,10 @@
"codersdk.UserLatency": {
"type": "object",
"properties": {
"avatar_url": {
"type": "string",
"format": "uri"
},
"latency_ms": {
"$ref": "#/definitions/codersdk.ConnectionLatency"
},
+1
View File
@@ -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),
+9 -6
View File
@@ -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,
+2 -1
View File
@@ -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
+1
View File
@@ -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,
+1
View File
@@ -44,6 +44,7 @@ type UserLatency struct {
TemplateIDs []uuid.UUID `json:"template_ids" format:"uuid"`
UserID uuid.UUID `json:"user_id" format:"uuid"`
Username string `json:"username"`
AvatarURL string `json:"avatar_url" format:"uri"`
LatencyMS ConnectionLatency `json:"latency_ms"`
}
+1
View File
@@ -117,6 +117,7 @@ curl -X GET http://coder-server:8080/api/v2/insights/user-latency \
"template_ids": ["497f6eca-6276-4993-bfeb-53cbbbba6f08"],
"users": [
{
"avatar_url": "http://example.com",
"latency_ms": {
"p50": 31.312,
"p95": 119.832
+4
View File
@@ -4879,6 +4879,7 @@ If the schedule is empty, the user will be updated to use the default schedule.|
```json
{
"avatar_url": "http://example.com",
"latency_ms": {
"p50": 31.312,
"p95": 119.832
@@ -4893,6 +4894,7 @@ If the schedule is empty, the user will be updated to use the default schedule.|
| Name | Type | Required | Restrictions | Description |
| -------------- | -------------------------------------------------------- | -------- | ------------ | ----------- |
| `avatar_url` | string | false | | |
| `latency_ms` | [codersdk.ConnectionLatency](#codersdkconnectionlatency) | false | | |
| `template_ids` | array of string | false | | |
| `user_id` | string | false | | |
@@ -4907,6 +4909,7 @@ If the schedule is empty, the user will be updated to use the default schedule.|
"template_ids": ["497f6eca-6276-4993-bfeb-53cbbbba6f08"],
"users": [
{
"avatar_url": "http://example.com",
"latency_ms": {
"p50": 31.312,
"p95": 119.832
@@ -4938,6 +4941,7 @@ If the schedule is empty, the user will be updated to use the default schedule.|
"template_ids": ["497f6eca-6276-4993-bfeb-53cbbbba6f08"],
"users": [
{
"avatar_url": "http://example.com",
"latency_ms": {
"p50": 31.312,
"p95": 119.832
+1
View File
@@ -1176,6 +1176,7 @@ export interface UserLatency {
readonly template_ids: string[]
readonly user_id: string
readonly username: string
readonly avatar_url: string
readonly latency_ms: ConnectionLatency
}