-
Notifications
You must be signed in to change notification settings - Fork 943
feat: expose app insights as Prometheus metrics #10346
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 18 commits
c944ede
5aad13d
a987458
514aa33
1952141
1c71868
5687a18
16eedee
52c3287
642e279
ca722de
b2deb7a
026c1a0
7a7087c
5140fbc
be7b50e
3afec05
9084b30
0e85cd4
890511c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
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.
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 |
---|---|---|
|
@@ -218,6 +218,52 @@ SELECT | |
FROM app_stats_by_user_and_agent | ||
GROUP BY access_method, slug_or_port, display_name, icon, is_app; | ||
|
||
-- name: GetTemplateAppInsightsByTemplate :many | ||
WITH app_stats_by_user_and_agent AS ( | ||
SELECT | ||
s.start_time, | ||
60 as seconds, | ||
w.template_id, | ||
was.user_id, | ||
was.agent_id, | ||
was.slug_or_port, | ||
wa.display_name, | ||
(wa.slug IS NOT NULL)::boolean AS is_app | ||
FROM workspace_app_stats was | ||
JOIN workspaces w ON ( | ||
w.id = was.workspace_id | ||
) | ||
-- We do a left join here because we want to include user IDs that have used | ||
-- e.g. ports when counting active users. | ||
LEFT JOIN workspace_apps wa ON ( | ||
wa.agent_id = was.agent_id | ||
AND wa.slug = was.slug_or_port | ||
) | ||
-- This table contains both 1 minute entries and >1 minute entries, | ||
-- to calculate this with our uniqueness constraints, we generate series | ||
-- for the longer intervals. | ||
CROSS JOIN LATERAL generate_series( | ||
date_trunc('minute', was.session_started_at), | ||
-- Subtract 1 microsecond to avoid creating an extra series. | ||
date_trunc('minute', was.session_ended_at - '1 microsecond'::interval), | ||
'1 minute'::interval | ||
) s(start_time) | ||
WHERE | ||
s.start_time >= @start_time::timestamptz | ||
-- Subtract one minute because the series only contains the start time. | ||
AND s.start_time < (@end_time::timestamptz) - '1 minute'::interval | ||
GROUP BY s.start_time, w.template_id, was.user_id, was.agent_id, was.slug_or_port, wa.display_name, wa.slug | ||
) | ||
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. Would it make sense to keep this part as similar as 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. The reasons why I decided to "fork" the query are:
I would rather keep the forked query, but I could add a comment to justify above differences? Unless you are aware of a smart trick which isn't a FUNCTION. EDIT: I guess we can improve this in a follow-up 👍 |
||
|
||
SELECT | ||
template_id, | ||
display_name, | ||
COALESCE(COUNT(DISTINCT user_id))::bigint AS active_users, | ||
SUM(seconds) AS usage_seconds | ||
FROM app_stats_by_user_and_agent | ||
WHERE is_app IS TRUE | ||
GROUP BY template_id, display_name; | ||
|
||
-- name: GetTemplateInsightsByInterval :many | ||
-- GetTemplateInsightsByInterval returns all intervals between start and end | ||
-- time, if end time is a partial interval, it will be included in the results and | ||
|
Uh oh!
There was an error while loading. Please reload this page.