-
Notifications
You must be signed in to change notification settings - Fork 889
feat(coderd): add parameter insights to template insights #8656
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(coderd): add parameter insights to template insights #8656
Conversation
d4ffac5
to
f60019b
Compare
258a5d2
to
680da6e
Compare
355c9b5
to
bf218e9
Compare
This is what I achieved with Click me{
"report": {
"start_time": "2023-08-01T00:00:00Z",
"end_time": "2023-08-03T11:00:00Z",
"template_ids": [],
"active_users": 0,
"apps_usage": [
{
"template_ids": [],
"type": "builtin",
"display_name": "Visual Studio Code",
"slug": "vscode",
"icon": "/icon/code.svg",
"seconds": 0
},
{
"template_ids": [],
"type": "builtin",
"display_name": "JetBrains",
"slug": "jetbrains",
"icon": "/icon/intellij.svg",
"seconds": 0
},
{
"template_ids": [],
"type": "builtin",
"display_name": "Web Terminal",
"slug": "reconnecting-pty",
"icon": "/icon/terminal.svg",
"seconds": 0
},
{
"template_ids": [],
"type": "builtin",
"display_name": "SSH",
"slug": "ssh",
"icon": "/icon/terminal.svg",
"seconds": 0
}
],
"parameters_usage": [
{
"template_ids": [
"6762af63-c8da-487a-9b05-814b18f5b3a9"
],
"display_name": "",
"name": "Compute instances",
"values": [
{
"value": "3",
"count": 2
}
]
},
{
"template_ids": [
"6762af63-c8da-487a-9b05-814b18f5b3a9"
],
"display_name": "",
"name": "Docker Image",
"values": [
{
"value": "ghcr.io/harrison-ai/coder-dev:base",
"count": 2
}
]
},
{
"template_ids": [
"6762af63-c8da-487a-9b05-814b18f5b3a9"
],
"display_name": "Very random string",
"name": "Optional random string",
"values": [
{
"value": "aaa",
"count": 1
},
{
"value": "ffff",
"count": 1
}
]
},
{
"template_ids": [
"6762af63-c8da-487a-9b05-814b18f5b3a9"
],
"display_name": "",
"name": "Region",
"options": [
{
"name": "US Central",
"description": "Select for central!",
"value": "us-central1-a",
"icon": "/icon/goland.svg"
},
{
"name": "US East",
"description": "Select for east!",
"value": "us-east1-a",
"icon": "/icon/folder.svg"
},
{
"name": "US West",
"description": "Select for west!",
"value": "us-west2-a",
"icon": ""
}
],
"values": [
{
"value": "us-west2-a",
"count": 2
}
]
},
{
"template_ids": [
"6762af63-c8da-487a-9b05-814b18f5b3a9"
],
"display_name": "",
"name": "Security groups",
"values": [
{
"value": "[\"Web Server Security Group\",\"Database Security Group\",\"Backend Security Group\"]",
"count": 2
}
]
},
{
"template_ids": [
"6762af63-c8da-487a-9b05-814b18f5b3a9"
],
"display_name": "Very random string",
"name": "buggy-1",
"values": [
{
"value": "",
"count": 2
}
]
},
{
"template_ids": [
"6762af63-c8da-487a-9b05-814b18f5b3a9"
],
"display_name": "Force rebuild",
"name": "force-rebuild",
"values": [
{
"value": "false",
"count": 2
}
]
},
{
"template_ids": [
"6762af63-c8da-487a-9b05-814b18f5b3a9"
],
"display_name": "Location",
"name": "location",
"options": [
{
"name": "US (Virginia)",
"description": "",
"value": "eastus",
"icon": "/emojis/1f1fa-1f1f8.png"
},
{
"name": "US (Virginia) 2",
"description": "",
"value": "eastus2",
"icon": "/emojis/1f1fa-1f1f8.png"
},
{
"name": "US (Texas)",
"description": "",
"value": "southcentralus",
"icon": "/emojis/1f1fa-1f1f8.png"
},
{
"name": "US (Washington)",
"description": "",
"value": "westus2",
"icon": "/emojis/1f1fa-1f1f8.png"
},
{
"name": "US (Arizona)",
"description": "",
"value": "westus3",
"icon": "/emojis/1f1fa-1f1f8.png"
},
{
"name": "US (Iowa)",
"description": "",
"value": "centralus",
"icon": "/emojis/1f1fa-1f1f8.png"
},
{
"name": "Canada (Toronto)",
"description": "",
"value": "canadacentral",
"icon": "/emojis/1f1e8-1f1e6.png"
},
{
"name": "Brazil (Sao Paulo)",
"description": "",
"value": "brazilsouth",
"icon": "/emojis/1f1e7-1f1f7.png"
},
{
"name": "East Asia (Hong Kong)",
"description": "",
"value": "eastasia",
"icon": "/emojis/1f1f0-1f1f7.png"
},
{
"name": "Southeast Asia (Singapore)",
"description": "",
"value": "southeastasia",
"icon": "/emojis/1f1f0-1f1f7.png"
},
{
"name": "Australia (New South Wales)",
"description": "",
"value": "australiaeast",
"icon": "/emojis/1f1e6-1f1fa.png"
},
{
"name": "China (Hebei)",
"description": "",
"value": "chinanorth3",
"icon": "/emojis/1f1e8-1f1f3.png"
},
{
"name": "India (Pune)",
"description": "",
"value": "centralindia",
"icon": "/emojis/1f1ee-1f1f3.png"
},
{
"name": "Japan (Tokyo)",
"description": "",
"value": "japaneast",
"icon": "/emojis/1f1ef-1f1f5.png"
},
{
"name": "Korea (Seoul)",
"description": "",
"value": "koreacentral",
"icon": "/emojis/1f1f0-1f1f7.png"
},
{
"name": "Europe (Ireland)",
"description": "",
"value": "northeurope",
"icon": "/emojis/1f1ea-1f1fa.png"
},
{
"name": "Europe (Netherlands)",
"description": "",
"value": "westeurope",
"icon": "/emojis/1f1ea-1f1fa.png"
},
{
"name": "France (Paris)",
"description": "",
"value": "francecentral",
"icon": "/emojis/1f1eb-1f1f7.png"
},
{
"name": "Germany (Frankfurt)",
"description": "",
"value": "germanywestcentral",
"icon": "/emojis/1f1e9-1f1ea.png"
},
{
"name": "Norway (Oslo)",
"description": "",
"value": "norwayeast",
"icon": "/emojis/1f1f3-1f1f4.png"
},
{
"name": "Sweden (Gävle)",
"description": "",
"value": "swedencentral",
"icon": "/emojis/1f1f8-1f1ea.png"
},
{
"name": "Switzerland (Zurich)",
"description": "",
"value": "switzerlandnorth",
"icon": "/emojis/1f1e8-1f1ed.png"
},
{
"name": "Qatar (Doha)",
"description": "",
"value": "qatarcentral",
"icon": "/emojis/1f1f6-1f1e6.png"
},
{
"name": "UAE (Dubai)",
"description": "",
"value": "uaenorth",
"icon": "/emojis/1f1e6-1f1ea.png"
},
{
"name": "South Africa (Johannesburg)",
"description": "",
"value": "southafricanorth",
"icon": "/emojis/1f1ff-1f1e6.png"
},
{
"name": "UK (London)",
"description": "",
"value": "uksouth",
"icon": "/emojis/1f1ec-1f1e7.png"
}
],
"values": [
{
"value": "eastus",
"count": 2
}
]
},
{
"template_ids": [
"6762af63-c8da-487a-9b05-814b18f5b3a9"
],
"display_name": "",
"name": "mtojek_region",
"options": [
{
"name": "Los Angeles, CA",
"description": "",
"value": "Los Angeles, CA",
"icon": ""
},
{
"name": "Moncks Corner, SC",
"description": "",
"value": "Moncks Corner, SC",
"icon": ""
},
{
"name": "Eemshaven, NL",
"description": "",
"value": "Eemshaven, NL",
"icon": ""
}
],
"values": [
{
"value": "Los Angeles, CA",
"count": 2
}
]
},
{
"template_ids": [
"6762af63-c8da-487a-9b05-814b18f5b3a9"
],
"display_name": "My Project ID",
"name": "project_id",
"values": [
{
"value": "12345",
"count": 2
}
]
},
{
"template_ids": [
"6762af63-c8da-487a-9b05-814b18f5b3a9"
],
"display_name": "Force devcontainer rebuild",
"name": "rebuild_devcontainer",
"values": [
{
"value": "false",
"count": 2
}
]
},
{
"template_ids": [
"6762af63-c8da-487a-9b05-814b18f5b3a9"
],
"display_name": "Git Repo URL",
"name": "repo_url",
"values": [
{
"value": "https://github.com/mtojek/coder",
"count": 2
}
]
}
]
},
"interval_reports": []
} |
for _, templateID := range arg.TemplateIDs { | ||
template, err := q.db.GetTemplateByID(ctx, templateID) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if err := q.authorizeContext(ctx, rbac.ActionUpdate, template); err != nil { | ||
return nil, err | ||
} | ||
} | ||
if len(arg.TemplateIDs) == 0 { | ||
if err := q.authorizeContext(ctx, rbac.ActionUpdate, rbac.ResourceTemplate.All()); err != nil { | ||
return nil, err | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GetTemplatesWithFilter
might be more performant here instead of calling GetTemplateByID
in a tight loop?
Edit: or you could leverage GetAuthorizedTemplates
to check if the caller has the required permissions on the requested templates.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Turns out this wasn't a useful suggestion :( GetTemplatesWithFilter
will return an empty slice if you do not have the permissions on any of the supplied TemplateIDs.
This reverts commit 81146cd.
@@ -1227,6 +1227,25 @@ func (q *querier) GetTemplateInsights(ctx context.Context, arg database.GetTempl | |||
return q.db.GetTemplateInsights(ctx, arg) | |||
} | |||
|
|||
func (q *querier) GetTemplateParameterInsights(ctx context.Context, arg database.GetTemplateParameterInsightsParams) ([]database.GetTemplateParameterInsightsRow, error) { | |||
for _, templateID := range arg.TemplateIDs { | |||
template, err := q.db.GetTemplateByID(ctx, templateID) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: this will generally only be called with a single TemplateID as a parameter, so we hopefully shouldn't see a pathological case of querying hundreds of templates.
This PR adds support for template parameter insights to the template insights endpoint.
Ref: #8787
Sample output: