Skip to content
Prev Previous commit
Next Next commit
Revert "use 1 minute granularity instead of 5"
This reverts commit 77e8382.
  • Loading branch information
mafredri committed Aug 18, 2023
commit 98a835c37e8309ac83e8ea26f4137150e825921a
4 changes: 2 additions & 2 deletions coderd/database/querier.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions coderd/database/queries.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions coderd/database/queries/insights.sql
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ GROUP BY workspace_agent_stats.user_id, users.username, users.avatar_url
ORDER BY user_id ASC;

-- name: GetTemplateInsights :one
-- GetTemplateInsights has a granularity of 1 minute where if a session/app was
-- in use during a minute, we will add 1 minute to the total usage for that
-- 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).
WITH ts AS (
SELECT
d::timestamptz AS from_,
(d::timestamptz + '1 minute'::interval) AS to_,
EXTRACT(epoch FROM '1 minute'::interval) AS seconds
(d::timestamptz + '5 minute'::interval) AS to_,
EXTRACT(epoch FROM '5 minute'::interval) AS seconds
FROM
-- Subtract 1 second from end_time to avoid including the next interval in the results.
generate_series(@start_time::timestamptz, (@end_time::timestamptz) - '1 second'::interval, '1 minute'::interval) d
generate_series(@start_time::timestamptz, (@end_time::timestamptz) - '1 second'::interval, '5 minute'::interval) d
), agent_stats_by_interval_and_user AS (
SELECT
ts.from_,
Expand Down Expand Up @@ -79,11 +79,11 @@ FROM agent_stats_by_interval_and_user;
WITH ts AS (
SELECT
d::timestamptz AS from_,
(d::timestamptz + '1 minute'::interval) AS to_,
EXTRACT(epoch FROM '1 minute'::interval) AS seconds
(d::timestamptz + '5 minute'::interval) AS to_,
EXTRACT(epoch FROM '5 minute'::interval) AS seconds
FROM
-- Subtract 1 second from end_time to avoid including the next interval in the results.
generate_series(@start_time::timestamptz, (@end_time::timestamptz) - '1 second'::interval, '1 minute'::interval) d
generate_series(@start_time::timestamptz, (@end_time::timestamptz) - '1 second'::interval, '5 minute'::interval) d
), app_stats_by_user_and_agent AS (
SELECT
ts.from_,
Expand Down