forked from looker/block-gcp-billing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gcp_billing_export_core.view.lkml
260 lines (232 loc) · 8.32 KB
/
gcp_billing_export_core.view.lkml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
include: "//@{CONFIG_PROJECT_NAME}/gcp_billing_export.view"
view: gcp_billing_export {
extends: [gcp_billing_export_config]
}
view: gcp_billing_export_core {
derived_table: {
sql:
SELECT
*,
GENERATE_UUID() as pk
FROM
@{SCHEMA_NAME}.@{BILLING_EXPORT_TABLE_NAME}
WHERE
{% condition date_filter %} _PARTITIONTIME {% endcondition %} ;;
}
### FILTER ONLY FIELDS
filter: date_filter {
type: date
}
parameter: date_view {
type: unquoted
default_value: "Day"
allowed_value: {
label: "Year"
value: "YEAR"
}
allowed_value: {
label: "Month"
value: "MONTH"
}
allowed_value: {
label: "Day"
value: "DATE"
}
}
### Field description reference https://cloud.google.com/billing/docs/how-to/export-data-bigquery
### DIMENSIONS
dimension: pk {
type: string
primary_key: yes
hidden: yes
# sql: CONCAT(${billing_account_id},CAST(${usage_start_raw} as STRING),${gcp_billing_export_service.id}, ${gcp_billing_export_sku.id}) ;;
sql: ${TABLE}.pk ;;
}
dimension: is_last_month {
type: yesno
sql: ${usage_start_month_num} = EXTRACT(month from CURRENT_TIMESTAMP())-1
AND ${usage_start_year} = EXTRACT(year from CURRENT_TIMESTAMP());;
}
dimension: billing_date {
description: "Use with filter only field 'Date View' to alter granularity"
type: string
label_from_parameter: date_view
sql: EXTRACT({% parameter date_view %} from ${usage_start_raw}) ;;
}
dimension: billing_account_id {
description: "The billing account ID that the usage is associated with."
type: string
sql: ${TABLE}.billing_account_id ;;
}
dimension: cost {
description: "The cost associated to an SKU, between Start Date and End Date"
type: number
sql: ${TABLE}.cost ;;
}
dimension: credits { # Nested record
hidden: yes
sql: ${TABLE}.credits ;;
}
dimension: currency {
description: "The currency the cost was billed in"
type: string
sql: ${TABLE}.currency ;;
}
dimension: currency_conversion_rate {
description: "The exchange rate from US dollars to the local currency. That is, cost/currency_conversion_rate is the cost in US dollars."
type: number
sql: ${TABLE}.currency_conversion_rate ;;
}
dimension: labels { # Nested record
hidden: yes
sql: ${TABLE}.labels ;;
}
dimension: sku_category {
type: string
description: "Provides an additional layer of granularity above SKU"
drill_fields: [gcp_billing_export_sku.description]
sql:
CASE
WHEN (${gcp_billing_export_service.description} = "Compute Engine"
AND ${gcp_billing_export_sku.description} LIKE '%Licensing%') THEN 'Compute Engine License'
WHEN (${gcp_billing_export_service.description} = "Compute Engine"
AND ${gcp_billing_export_sku.description} LIKE '%Network%') THEN 'Networking'
WHEN (${gcp_billing_export_service.description} = "Compute Engine"
AND (${gcp_billing_export_sku.description} LIKE '%instance%'
or ${gcp_billing_export_sku.description} LIKE '%Instance%')) THEN 'Compute Engine Instance'
WHEN (${gcp_billing_export_service.description} = "Compute Engine"
AND ${gcp_billing_export_sku.description} LIKE '%PD%') THEN 'Compute Engine Storage'
WHEN (${gcp_billing_export_service.description} = "Compute Engine"
AND ${gcp_billing_export_sku.description} LIKE '%Intel%') THEN 'Compute Engine Instance'
WHEN (${gcp_billing_export_service.description} = "Compute Engine"
AND ${gcp_billing_export_sku.description} LIKE '%Storage%') THEN 'Compute Engine Storage'
WHEN (${gcp_billing_export_service.description} = "Compute Engine"
AND ${gcp_billing_export_sku.description} LIKE '%Ip%') THEN 'Networking'
WHEN (${gcp_billing_export_service.description} = "BigQuery"
AND ${gcp_billing_export_sku.description} LIKE '%Storage%') THEN 'BigQuery Storage'
WHEN (${gcp_billing_export_service.description} = "BigQuery"
AND ${gcp_billing_export_sku.description} = "Analysis") THEN 'BigQuery Analysis'
WHEN (${gcp_billing_export_service.description} = "BigQuery"
AND ${gcp_billing_export_sku.description} = 'Streaming Insert') THEN 'BigQuery Streaming'
WHEN (${gcp_billing_export_service.description} = 'Cloud Storage'
AND ${gcp_billing_export_sku.description} LIKE '%Storage%') THEN 'GCS Storage'
WHEN (${gcp_billing_export_service.description} = 'Cloud Storage'
AND ${gcp_billing_export_sku.description} LIKE '%Download%') THEN 'GCS Download'
WHEN (${gcp_billing_export_service.description} = 'Cloud Dataflow'
AND ${gcp_billing_export_sku.description} LIKE '%PD%') THEN 'Dataflow PD'
WHEN (${gcp_billing_export_service.description} = 'Cloud Dataflow'
AND (${gcp_billing_export_sku.description} LIKE '%vCPU%'
OR ${gcp_billing_export_sku.description} LIKE '%RAM%')) THEN 'Dataflow Compute'
ELSE ${gcp_billing_export_service.description}
END ;;
}
dimension: project { # Nested record
hidden: yes
sql: ${TABLE}.project ;;
}
dimension: service { # Nested record
hidden: yes
sql: ${TABLE}.service ;;
}
dimension: sku { # Nested record
hidden: yes
sql: ${TABLE}.sku ;;
}
dimension: usage { # Nested record
hidden: yes
sql: ${TABLE}.usage ;;
}
### DIMENSION GROUPS
dimension_group: export {
description: "Time at which the billing was exported"
type: time
timeframes: [
raw,
time,
date,
week,
month,
month_name,
month_num,
week_of_year,
day_of_month,
quarter,
year
]
sql: ${TABLE}.export_time ;;
}
dimension_group: usage_end {
description: "Time at which the cost associated with a SKU ended"
type: time
timeframes: [
raw,
time,
date,
week,
month,
month_name,
month_num,
week_of_year,
day_of_month,
quarter,
year
]
sql: ${TABLE}.usage_end_time ;;
}
dimension_group: usage_start {
description: "Time at which the cost associated with a SKU started"
type: time
timeframes: [
raw,
time,
date,
week,
month,
month_name,
month_num,
week_of_year,
day_of_month,
quarter,
year
]
sql: ${TABLE}.usage_start_time ;;
}
### MEASURES
measure: cost_before_credits {
description: "The cost associated to an SKU before any credits, between the Start Date and End Date"
type: sum
sql: ${TABLE}.cost ;;
value_format_name: decimal_2
html: {% if currency._value == 'GBP' %}
<a href="{{ link }}"> £{{ rendered_value }}</a>
{% elsif currency == 'USD' %}
<a href="{{ link }}"> ${{ rendered_value }}</a>
{% elsif currency == 'EUR' %}
<a href="{{ link }}"> €{{ rendered_value }}</a>
{% else %}
<a href="{{ link }}"> {{ rendered_value }} {{ currency._value }}</a>
{% endif %} ;;
drill_fields: [gcp_billing_export_project.name, gcp_billing_export_service.description, sku_category, gcp_billing_export_sku.description, gcp_billing_export_usage.unit, gcp_billing_export_usage.total_usage, total_cost]
}
measure: total_usage {
description: "The units of Usage is the dimension 'Resource', please use the two together"
type: sum
sql: ${gcp_billing_export_usage.usage} ;;
html: {{value}} {{ gcp_billing_export_usage.unit._value }} ;;
}
measure: total_cost { # in_query in link specifications to avoid fanout
description: "The total cost associated to the SKU with credits applied, between the Start Date and End Date"
type: number
sql: ${cost_before_credits} + ${gcp_billing_export_credits.total_credit} ;;
value_format_name: decimal_2
html: {% if currency._value == 'GBP' %}
<a href="{{ link }}"> £{{ rendered_value }}</a>
{% elsif currency == 'USD' %}
<a href="{{ link }}"> ${{ rendered_value }}</a>
{% elsif currency == 'EUR' %}
<a href="{{ link }}"> €{{ rendered_value }}</a>
{% else %}
<a href="{{ link }}"> {{ rendered_value }} {{ currency._value }}</a>
{% endif %} ;;
}
}