-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #51 from bqbooster/rework_compute_cost_and_billing
Rework compute cost & billing
- Loading branch information
Showing
13 changed files
with
209 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{{ | ||
config( | ||
materialized='view', | ||
) | ||
}} | ||
|
||
SELECT | ||
TIMESTAMP_TRUNC(HOUR, YEAR) AS year, | ||
TIMESTAMP_TRUNC(HOUR, MONTH) AS month, | ||
TIMESTAMP_TRUNC(HOUR, DAY) AS day, | ||
* | ||
FROM {{ ref('compute_cost_per_hour') }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
version: 2 | ||
|
||
models: | ||
- name: compute_cost_per_hour_view | ||
description: > | ||
An enriched view over the model that stores the compute cost per hour. | ||
meta: | ||
label: "Compute cost per hour" | ||
order_fields_by: "label" | ||
group_label: "Compute cost" | ||
columns: | ||
- name: year | ||
description: The year of the compute cost. | ||
- name: month | ||
description: The month of the compute cost. | ||
- name: day | ||
description: The day of the compute cost. | ||
- name: hour | ||
description: The hour of the compute cost. | ||
- name: project_id | ||
description: The project id of the job. | ||
- name: total_query_cost | ||
description: The total cost of all queries run during the hour. | ||
- name: failing_query_cost | ||
description: The total cost of all queries that failed during the hour. | ||
- name: total_slot_ms | ||
description: The total number of slot time milliseconds used by all queries during the hour. | ||
- name: total_slot_time | ||
description: The total number of slot time in human readable format used by all queries during the hour. | ||
- name: query_count | ||
description: The total number of queries run during the hour. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{{ | ||
config( | ||
materialized='view', | ||
) | ||
}} | ||
SELECT | ||
TIMESTAMP_TRUNC(MINUTE, YEAR) AS year, | ||
TIMESTAMP_TRUNC(MINUTE, MONTH) AS month, | ||
TIMESTAMP_TRUNC(MINUTE, DAY) AS day, | ||
TIMESTAMP_TRUNC(MINUTE, HOUR) AS hour, | ||
* | ||
FROM {{ ref('compute_cost_per_minute') }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
version: 2 | ||
|
||
models: | ||
- name: compute_cost_per_minute_view | ||
description: > | ||
An enriched view over the model that stores the compute cost per minute. | ||
meta: | ||
label: "Compute cost per minute" | ||
order_fields_by: "label" | ||
group_label: "Compute cost" | ||
columns: | ||
- name: year | ||
description: The year of the compute cost. | ||
- name: month | ||
description: The month of the compute cost. | ||
- name: day | ||
description: The day of the compute cost. | ||
- name: hour | ||
description: The hour of the compute cost. | ||
- name: minute | ||
description: The minute of the compute cost. | ||
- name: project_id | ||
description: The project id of the job. | ||
- name: total_query_cost | ||
description: The total cost of all queries run during the minute. | ||
- name: failing_query_cost | ||
description: The total cost of all queries that failed during the minute. | ||
- name: total_slot_ms | ||
description: The total number of slot time milliseconds used by all queries during the minute. | ||
- name: total_slot_time | ||
description: The total number of slot time in human readable format used by all queries during the minute. | ||
- name: query_count | ||
description: The total number of queries run during the minute. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
28 changes: 28 additions & 0 deletions
28
models/compute/intermediate/cost/compute_cost_per_hour.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{{ | ||
config( | ||
materialized='incremental', | ||
incremental_strategy = 'insert_overwrite', | ||
on_schema_change='append_new_columns', | ||
partition_by={ | ||
"field": "hour", | ||
"granularity": "day", | ||
"data_type": "timestamp", | ||
"copy_partitions": should_use_copy_partitions() | ||
}, | ||
cluster_by = ['hour', 'project_id'], | ||
partition_expiration_days = var('output_partition_expiration_days') | ||
) | ||
}} | ||
{%- call set_sql_header(config) %} | ||
{{ milliseconds_to_readable_time_udf() }} | ||
{%- endcall %} | ||
SELECT | ||
TIMESTAMP_TRUNC(MINUTE, HOUR) AS hour, | ||
project_id, | ||
SUM(ROUND(total_query_cost, 2)) AS total_query_cost, | ||
SUM(ROUND(failing_query_cost, 2)) AS failing_query_cost, | ||
SUM(total_slot_ms) AS total_slot_ms, | ||
MILLISECONDS_TO_READABLE_TIME_UDF(total_slot_ms, 2) AS total_slot_time, | ||
SUM(query_count) AS query_count | ||
FROM {{ ref("compute_cost_per_minute") }} | ||
GROUP BY ALL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
models/compute/intermediate/cost/compute_cost_per_minute.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
version: 2 | ||
|
||
models: | ||
- name: compute_cost_per_minute | ||
description: > | ||
A model that stores the compute cost per hour. | ||
meta: | ||
label: "Compute cost per minute" | ||
order_fields_by: "label" | ||
group_label: "Compute cost" | ||
columns: | ||
- name: hour | ||
description: The hour of the compute cost. | ||
- name: minute | ||
description: The minute of the compute cost. | ||
- name: project_id | ||
description: The project id of the job. | ||
- name: total_query_cost | ||
description: The total cost of all queries run during the minute. | ||
- name: failing_query_cost | ||
description: The total cost of all queries that failed during the minute. | ||
- name: total_slot_ms | ||
description: The total number of slot time milliseconds used by all queries during the minute. | ||
- name: total_slot_time | ||
description: The total number of slot time in human readable format used by all queries during the hour. | ||
- name: query_count | ||
description: The total number of queries run during the minute. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters