-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathgcp_billing_export.view.lkml
350 lines (312 loc) · 9.66 KB
/
gcp_billing_export.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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
view: gcp_billing_export {
derived_table: {
sql:
SELECT
*,
GENERATE_UUID() as pk
FROM
gcp_logs.gcp_billing_export_v1_#####_#####_######
WHERE
{% condition date_filter %} _PARTITIONTIME {% endcondition %} ;;
}
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"
}
}
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 {
type: string
label_from_parameter: date_view
sql: EXTRACT({% parameter date_view %} from ${usage_start_raw}) ;;
}
dimension: billing_account_id {
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 ;;
}
measure: total_cost {
description: "The total cost associated to the SKU, 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]
}
dimension: credits {
hidden: yes
sql: ${TABLE}.credits ;;
}
measure: total_credit {
description: "The total credit given to the billing account"
type: sum
sql: ${gcp_billing_export_credits.credit_amount} ;;
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_credits.credit_name,gcp_billing_export_credits.credit_amount]
}
dimension: currency {
description: "The currency the cost was billed in"
type: string
sql: ${TABLE}.currency ;;
}
dimension: currency_conversion_rate {
type: number
sql: ${TABLE}.currency_conversion_rate ;;
}
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: labels {
hidden: yes
sql: ${TABLE}.labels ;;
}
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: 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 {
hidden: yes
sql: ${TABLE}.project ;;
}
dimension: service {
hidden: yes
sql: ${TABLE}.service ;;
}
dimension: sku {
hidden: yes
sql: ${TABLE}.sku ;;
}
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 ;;
}
dimension: usage {
hidden: yes
sql: ${TABLE}.usage ;;
}
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} ;;
}
}
view: gcp_billing_export_credits {
dimension: credit_amount {
group_label: "Credits"
description: "The amount of credit given to account"
type: number
sql: ${TABLE}.amount ;;
}
dimension: credit_name {
group_label: "Credits"
description: "Nmae of the credit applied to account"
type: string
sql: ${TABLE}.name ;;
}
dimension: credit_id {
primary_key: yes
# hidden: yes
sql: CONCAT(CAST(${gcp_billing_export.pk} as STRING), ${credit_name}) ;;
}
}
view: gcp_billing_export_usage {
dimension: usage {
group_label: "Resource Usage"
type: number
sql: ${TABLE}.amount ;;
}
dimension: unit {
group_label: "Resource Usage"
label: "Resource"
type: string
sql: ${TABLE}.unit ;;
}
}
view: gcp_billing_export_project {
dimension: id {
primary_key: yes
type: string
sql: ${TABLE}.id ;;
}
dimension: labels {
hidden: yes
sql: ${TABLE}.labels ;;
}
dimension: name {
label: "Project Name"
type: string
sql: ${TABLE}.name;;
drill_fields: [gcp_billing_export_service.description, gcp_billing_export.sku_category, gcp_billing_export_sku.description]
}
}
view: gcp_billing_export_labels {
dimension: label_key {
group_label: "Labels"
type: string
sql: ${TABLE}.key ;;
}
dimension: label_value {
group_label: "Labels"
type: string
sql: ${TABLE}.value ;;
}
dimension: label_id {
primary_key: yes
hidden: yes
sql: CONCAT(CAST(${gcp_billing_export.pk} as STRING), ${label_key}, ${label_value}) ;;
}
}
view: gcp_billing_export_service {
dimension: id {
hidden: yes
type: string
sql: ${TABLE}.id ;;
}
dimension: description {
label: "Service"
type: string
sql: ${TABLE}.description ;;
drill_fields: [gcp_billing_export_project.name, gcp_billing_export.sku_category, gcp_billing_export_sku.description]
}
}
view: gcp_billing_export_sku {
dimension: id {
hidden: yes
type: string
sql: ${TABLE}.id ;;
}
dimension: description {
label: "SKU"
description: "The most granular level of detail"
type: string
sql: ${TABLE}.description ;;
}
}