-
Notifications
You must be signed in to change notification settings - Fork 894
feat(coderd): add times_used
to coder_app
s in insights API
#13292
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
times_used
to coder_app
s in insights API
For now, only applied to `coder_app`s, same logic can be implemented for VS Code, SSH, etc. Part of #13099
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -249,7 +249,7 @@ WITH | |
apps.slug, | ||
apps.display_name, | ||
apps.icon, | ||
tus.app_usage_mins | ||
(tus.app_usage_mins -> apps.slug)::smallint AS usage_mins | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Drive-by optimization to avoid |
||
FROM | ||
apps | ||
JOIN | ||
|
@@ -273,14 +273,36 @@ WITH | |
display_name, | ||
icon, | ||
-- See motivation in GetTemplateInsights for LEAST(SUM(n), 30). | ||
LEAST(SUM(app_usage.value::smallint), 30) AS usage_mins | ||
LEAST(SUM(usage_mins), 30) AS usage_mins | ||
FROM | ||
template_usage_stats_with_apps, jsonb_each(app_usage_mins) AS app_usage | ||
WHERE | ||
app_usage.key = slug | ||
template_usage_stats_with_apps | ||
GROUP BY | ||
start_time, user_id, slug, display_name, icon | ||
), | ||
-- Analyze the users unique app usage across all templates. Count | ||
-- usage across consecutive intervals as continuous usage. | ||
times_used AS ( | ||
SELECT DISTINCT ON (user_id, slug, display_name, icon, uniq) | ||
slug, | ||
display_name, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. QQ: If somebody changes the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It'll handle it according to current behavior -- a change in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But it should nit as technically the app is the same app. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It depends, in aggregation across the whole deployment (which we don't show, but is possible), the apps might not be the same at all. For now I would not want to introduce one feature that behaves differently from the rest, we already show multiple entries for apps and parameters if something (like the display name) has changed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. I am aware if the existing behavior and suggesting that we should change it sometimes in the future to be more robust to cosmetic changes to a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @matifali actually, have you recently confirmed this is still a problem? I think this is mainly a problem with parameters. If the app name changes it should only use the most recent name, at least since the rollup refactor. |
||
icon, | ||
-- Turn start_time into a unique identifier that identifies a users | ||
-- continuous app usage. The value of uniq is otherwise garbage. | ||
-- | ||
-- Since we're aggregating per user app usage across templates, | ||
-- there can be duplicate start_times. To handle this, we use the | ||
-- dense_rank() function, otherwise row_number() would suffice. | ||
start_time - ( | ||
dense_rank() OVER ( | ||
PARTITION BY | ||
user_id, slug, display_name, icon | ||
ORDER BY | ||
start_time | ||
) * '30 minutes'::interval | ||
) AS uniq | ||
FROM | ||
template_usage_stats_with_apps | ||
Comment on lines
+284
to
+304
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What sort of additional load does this place on the DB? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't measure but I don't expect it to be a lot, this is similar in weight (or lighter) as the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I posted the explains, it seems to be parallel and very cheap. |
||
), | ||
-- Even though we allow identical apps to be aggregated across | ||
-- templates, we still want to be able to report which templates | ||
-- the data comes from. | ||
|
@@ -302,7 +324,17 @@ SELECT | |
ai.slug, | ||
ai.display_name, | ||
ai.icon, | ||
(SUM(ai.usage_mins) * 60)::bigint AS usage_seconds | ||
(SUM(ai.usage_mins) * 60)::bigint AS usage_seconds, | ||
COALESCE(( | ||
SELECT | ||
COUNT(*) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is just about cardinality of app usage, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, we are only interested in rows of this table, not of it's content. |
||
FROM | ||
times_used | ||
WHERE | ||
times_used.slug = ai.slug | ||
AND times_used.display_name = ai.display_name | ||
AND times_used.icon = ai.icon | ||
), 0)::bigint AS times_used | ||
FROM | ||
app_insights AS ai | ||
JOIN | ||
|
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.
TIL
dense_rank()