mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat(coderd/database): use template_usage_stats in GetTemplateInsights query (#12666)
This PR updates the `GetTemplateInsights` query to use rolled up `template_usage_stats` instead of raw agent and app stats.
This commit is contained in:
@@ -178,9 +178,15 @@ type sqlcQuerier interface {
|
||||
GetTemplateByID(ctx context.Context, id uuid.UUID) (Template, error)
|
||||
GetTemplateByOrganizationAndName(ctx context.Context, arg GetTemplateByOrganizationAndNameParams) (Template, error)
|
||||
GetTemplateDAUs(ctx context.Context, arg GetTemplateDAUsParams) ([]GetTemplateDAUsRow, error)
|
||||
// GetTemplateInsights has a granularity of 5 minutes where if a session/app was
|
||||
// in use during a minute, we will add 5 minutes to the total usage for that
|
||||
// session/app (per user).
|
||||
// GetTemplateInsights returns the aggregate user-produced usage of all
|
||||
// workspaces in a given timeframe. The template IDs, active users, and
|
||||
// usage_seconds all reflect any usage in the template, including apps.
|
||||
//
|
||||
// When combining data from multiple templates, we must make a guess at
|
||||
// how the user behaved for the 30 minute interval. In this case we make
|
||||
// the assumption that if the user used two workspaces for 15 minutes,
|
||||
// they did so sequentially, thus we sum the usage up to a maximum of
|
||||
// 30 minutes with LEAST(SUM(n), 30).
|
||||
GetTemplateInsights(ctx context.Context, arg GetTemplateInsightsParams) (GetTemplateInsightsRow, error)
|
||||
// GetTemplateInsightsByInterval returns all intervals between start and end
|
||||
// time, if end time is a partial interval, it will be included in the results and
|
||||
|
||||
Reference in New Issue
Block a user