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

An-4796/runtime-detection #263

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions data/github_actions__runtime_detection.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
workflow_name
dbt_run_abi_refresh
dbt_run_dev_refresh
dbt_run_operation_reorg
dbt_run_scheduled_curated
dbt_run_scheduled_non_realtime
dbt_run_streamline_chainhead
dbt_run_streamline_decoder
31 changes: 31 additions & 0 deletions models/github_actions/github_actions__current_workflows.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{{ config(
materialized = 'view',
tags = ['gha_tasks']
) }}

SELECT
NAME,
status,
created_at,
updated_at,
run_started_at,
run_attempt,
run_number,
TIMESTAMPDIFF(seconds, run_started_at, SYSDATE()) / 60 AS run_minutes,
id,
workflow_id,
html_url
FROM
TABLE(
github_actions.tf_runs(
'FlipsideCrypto',
'bsc-models',{ 'status' :'in_progress' }
)
)
WHERE
NAME IN (
SELECT
workflow_name
FROM
{{ ref('github_actions__runtime_detection') }}
)
8 changes: 8 additions & 0 deletions models/github_actions/github_actions__current_workflows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: 2
models:
- name: github_actions__current_workflows
columns:
- name: RUN_MINUTES
tests:
- dbt_expectations.expect_column_values_to_be_between:
max_value: 59
132 changes: 132 additions & 0 deletions models/github_actions/github_actions__workflow_history.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
{{ config(
materialized = 'incremental',
incremental_strategy = 'delete+insert',
unique_key = 'workflow_history_id',
tags = ['gha_tasks'],
full_refresh = false
) }}

WITH

{% if is_incremental() %}
-- get latest
workflow_runs AS (

SELECT
id AS run_id,
NAME,
node_id,
check_suite_id,
check_suite_node_id,
head_branch,
head_sha,
run_number,
event,
display_title,
status,
conclusion,
workflow_id,
url,
html_url,
pull_requests,
created_at,
updated_at,
actor,
run_attempt,
run_started_at,
triggering_actor,
jobs_url,
logs_url,
check_suite_url,
artifacts_url,
cancel_url,
rerun_url,
workflow_url,
head_commit,
repository,
head_repository
FROM
TABLE(
github_actions.tf_runs(
'FlipsideCrypto',
'bsc-models',{ 'per_page' :'100',
'page': '1' }
)
)
WHERE
NAME IN (
SELECT
workflow_name
FROM
{{ ref('github_actions__runtime_detection') }}
)
AND conclusion IS NOT NULL
)
{% else %}
-- get history, last 100 pages
workflow_runs AS ({% for item in range(100) %}
(
SELECT
id AS run_id,
NAME,
node_id,
check_suite_id,
check_suite_node_id,
head_branch,
head_sha,
run_number,
event,
display_title,
status,
conclusion,
workflow_id,
url,
html_url,
pull_requests,
created_at,
updated_at,
actor,
run_attempt,
run_started_at,
triggering_actor,
jobs_url,
logs_url,
check_suite_url,
artifacts_url,
cancel_url,
rerun_url,
workflow_url,
head_commit,
repository,
head_repository
FROM
TABLE(github_actions.tf_runs(
'FlipsideCrypto',
'bsc-models',{ 'per_page' :'100',
'page': '{{ item }}' }
)
)
WHERE
NAME IN (
SELECT
workflow_name
FROM
{{ ref('github_actions__runtime_detection') }})
AND conclusion IS NOT NULL)
{% if not loop.last %}
UNION ALL
{% endif %}
{% endfor %})
{% endif %}

SELECT
*,
{{ dbt_utils.generate_surrogate_key(
['run_id']
) }} AS workflow_history_id,
SYSDATE() AS inserted_timestamp,
SYSDATE() AS modified_timestamp
FROM
workflow_runs qualify (ROW_NUMBER() over (PARTITION BY run_id
ORDER BY
created_at DESC)) = 1