Skip to content
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

Update slots_by_second.sql #16

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions information_schema/slots_by_second.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@
-- Change this value to change how far in the past the query will search
DECLARE interval_in_days INT64 DEFAULT 7;

DECLARE time_period INT64;
SET time_period = (1000); -- Number of milliseconds in a second
DECLARE time_period INT64 DEFAULT (1000); -- Number of milliseconds in a second

BEGIN
WITH src AS (
SELECT
SAFE_DIVIDE(SUM(total_slot_ms), time_period) AS slotUsage,
DATETIME_TRUNC(creation_time,
SECOND) AS creationTime
SAFE_DIVIDE(SUM(period_slot_ms), time_period) AS slotUsage, -- Divide by 1 second (1000 ms) to convert to slots/second
period_start
FROM
`<project-name>`.`<dataset-region>`.INFORMATION_SCHEMA.JOBS_BY_PROJECT
`<project-name>`.`<dataset-region>`.INFORMATION_SCHEMA.JOBS_TIMELINE
WHERE
creation_time BETWEEN TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL interval_in_days DAY)
AND CURRENT_TIMESTAMP()
AND total_slot_ms IS NOT NULL
period_start BETWEEN TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL interval_in_days DAY) AND CURRENT_TIMESTAMP()
AND job_type <> 'SCRIPT' -- Exclude scripts since they pull in child process slots and skew results
GROUP BY
creationTime),
timeSeries AS(
period_start
ORDER BY
period_start DESC
),
timeSeries AS(
SELECT
*
FROM
Expand All @@ -34,12 +34,13 @@ BEGIN
timeInterval
FROM
src RIGHT OUTER JOIN timeSeries
ON creationTime = timeInterval)
ON period_start = timeInterval
)

SELECT
*
FROM
joined
ORDER BY
timeInterval ASC;
END
END