/
emr_cluster_detail.sp
442 lines (384 loc) · 9.5 KB
/
emr_cluster_detail.sp
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
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
dashboard "emr_cluster_detail" {
title = "AWS EMR Cluster Detail"
documentation = file("./dashboards/emr/docs/emr_cluster_detail.md")
tags = merge(local.emr_common_tags, {
type = "Detail"
})
input "emr_cluster_arn" {
title = "Select a cluster:"
query = query.emr_cluster_input
width = 4
}
container {
card {
width = 3
query = query.emr_cluster_auto_termination
args = [self.input.emr_cluster_arn.value]
}
card {
width = 3
query = query.emr_cluster_state
args = [self.input.emr_cluster_arn.value]
}
card {
width = 3
query = query.emr_cluster_logging
args = [self.input.emr_cluster_arn.value]
}
card {
width = 3
query = query.emr_cluster_log_encryption
args = [self.input.emr_cluster_arn.value]
}
}
with "ec2_amis_for_emr_cluster" {
query = query.ec2_amis_for_emr_cluster
args = [self.input.emr_cluster_arn.value]
}
with "iam_roles_for_emr_cluster" {
query = query.iam_roles_for_emr_cluster
args = [self.input.emr_cluster_arn.value]
}
with "s3_buckets_for_emr_cluster" {
query = query.s3_buckets_for_emr_cluster
args = [self.input.emr_cluster_arn.value]
}
container {
graph {
title = "Relationships"
type = "graph"
direction = "TD"
node {
base = node.ec2_ami
args = {
ec2_ami_image_ids = with.ec2_amis_for_emr_cluster.rows[*].image_id
}
}
node {
base = node.emr_cluster
args = {
emr_cluster_arns = [self.input.emr_cluster_arn.value]
}
}
node {
base = node.emr_instance
args = {
emr_cluster_arns = [self.input.emr_cluster_arn.value]
}
}
node {
base = node.emr_instance_fleet
args = {
emr_cluster_arns = [self.input.emr_cluster_arn.value]
}
}
node {
base = node.emr_instance_group
args = {
emr_cluster_arns = [self.input.emr_cluster_arn.value]
}
}
node {
base = node.iam_role
args = {
iam_role_arns = with.iam_roles_for_emr_cluster.rows[*].role_arn
}
}
node {
base = node.s3_bucket
args = {
s3_bucket_arns = with.s3_buckets_for_emr_cluster.rows[*].s3_bucket_arn
}
}
edge {
base = edge.emr_cluster_to_ec2_ami
args = {
emr_cluster_arns = [self.input.emr_cluster_arn.value]
}
}
edge {
base = edge.emr_cluster_to_emr_instance_fleet
args = {
emr_cluster_arns = [self.input.emr_cluster_arn.value]
}
}
edge {
base = edge.emr_cluster_to_emr_instance_group
args = {
emr_cluster_arns = [self.input.emr_cluster_arn.value]
}
}
edge {
base = edge.emr_cluster_to_iam_role
args = {
emr_cluster_arns = [self.input.emr_cluster_arn.value]
}
}
edge {
base = edge.emr_cluster_to_s3_bucket
args = {
emr_cluster_arns = [self.input.emr_cluster_arn.value]
}
}
edge {
base = edge.emr_instance_fleet_to_emr_instance
args = {
emr_cluster_arns = [self.input.emr_cluster_arn.value]
}
}
edge {
base = edge.emr_instance_group_to_emr_instance
args = {
emr_cluster_arns = [self.input.emr_cluster_arn.value]
}
}
}
}
container {
container {
width = 6
table {
title = "Overview"
type = "line"
width = 6
query = query.emr_cluster_overview
args = [self.input.emr_cluster_arn.value]
}
table {
title = "Tags"
width = 6
query = query.emr_cluster_tags
args = [self.input.emr_cluster_arn.value]
}
}
container {
width = 6
table {
title = "Status"
query = query.emr_cluster_status
args = [self.input.emr_cluster_arn.value]
}
table {
title = "Instances"
query = query.emr_cluster_instance
args = [self.input.emr_cluster_arn.value]
column "ARN" {
display = "none"
}
column "EC2 Instance ID" {
href = "${dashboard.ec2_instance_detail.url_path}?input.instance_arn={{.'ARN' | @uri}}"
}
}
}
}
container {
table {
title = "Applications"
width = 6
query = query.emr_cluster_applications
args = [self.input.emr_cluster_arn.value]
}
table {
title = "EC2 Instance Attributes"
width = 6
query = query.emr_cluster_ec2_instance_attributes
args = [self.input.emr_cluster_arn.value]
}
}
}
# Input queries
query "emr_cluster_input" {
sql = <<-EOQ
select
title as label,
cluster_arn as value,
json_build_object(
'id', id,
'account_id', account_id,
'region', region
) as tags
from
aws_emr_cluster
order by
title;
EOQ
}
# With queries
query "ec2_amis_for_emr_cluster" {
sql = <<-EOQ
select
custom_ami_id as image_id
from
aws_emr_cluster
where
custom_ami_id is not null
and cluster_arn = $1;
EOQ
}
query "iam_roles_for_emr_cluster" {
sql = <<-EOQ
select
r.arn as role_arn
from
aws_iam_role as r,
aws_emr_cluster as c
where
c.cluster_arn = $1
and r.name = c.service_role;
EOQ
}
query "s3_buckets_for_emr_cluster" {
sql = <<-EOQ
select
b.arn as s3_bucket_arn
from
aws_emr_cluster as c
left join
aws_s3_bucket as b
on split_part(log_uri, '/', 3) = b.name
where
log_uri is not null
and cluster_arn = $1;
EOQ
}
# Card queries
query "emr_cluster_auto_termination" {
sql = <<-EOQ
select
'Auto Termination' as label,
case when auto_terminate then 'Enabled' else 'Disabled' end as value
from
aws_emr_cluster
where
cluster_arn = $1;
EOQ
}
query "emr_cluster_state" {
sql = <<-EOQ
select
'State' as label,
initcap(state) as value,
case when state = 'TERMINATED_WITH_ERRORS' then 'alert' else 'ok' end as type
from
aws_emr_cluster
where
cluster_arn = $1;
EOQ
}
query "emr_cluster_logging" {
sql = <<-EOQ
select
'Logging' as label,
case when log_uri is null then 'Disabled' else 'Enabled' end as value,
case when log_uri is null then 'alert' else 'ok' end as type
from
aws_emr_cluster
where
cluster_arn = $1;
EOQ
}
query "emr_cluster_log_encryption" {
sql = <<-EOQ
select
'Log Encryption' as label,
case when log_encryption_kms_key_id is null then 'Disabled' else 'Enabled' end as value,
case when log_encryption_kms_key_id is null then 'alert' else 'ok' end as type
from
aws_emr_cluster
where
cluster_arn = $1;
EOQ
}
# Other detail page queries
query "emr_cluster_overview" {
sql = <<-EOQ
select
title as "Title",
id as "ID",
instance_collection_type as "Instance Collection Type",
region as "Region",
account_id as "Account ID",
cluster_arn as "ARN"
from
aws_emr_cluster
where
cluster_arn = $1
EOQ
}
query "emr_cluster_tags" {
sql = <<-EOQ
select
tag ->> 'Key' as "Key",
tag ->> 'Value' as "Value"
from
aws_emr_cluster,
jsonb_array_elements(tags_src) as tag
where
cluster_arn = $1
order by
tag ->> 'Key';
EOQ
}
query "emr_cluster_instance" {
sql = <<-EOQ
select
i.id as "ID",
i.ec2_instance_id as "EC2 Instance ID",
i.state as "State",
i.instance_fleet_id as "Instance Fleet ID",
i.instance_group_id as "Instance Group ID",
ec2i.arn as "ARN"
from
aws_emr_instance as i,
aws_emr_cluster as c,
aws_ec2_instance as ec2i
where
i.cluster_id = c.id
and i.ec2_instance_id = ec2i.instance_id
and cluster_arn = $1;
EOQ
}
query "emr_cluster_status" {
sql = <<-EOQ
select
status -> 'StateChangeReason' ->> 'Code' as "Code",
status -> 'StateChangeReason' ->> 'Message' as "Message",
status -> 'Timeline' ->> 'CreationDateTime' as "Creation Time",
status -> 'Timeline' ->> 'ReadyDateTime' as "Ready Time",
status -> 'Timeline' ->> 'EndDateTime' as "End Time"
from
aws_emr_cluster
where
cluster_arn = $1;
EOQ
}
query "emr_cluster_applications" {
sql = <<-EOQ
select
app ->> 'Name' as "Name",
app ->> 'Version' as "Version",
app -> 'Args' as "Args",
app -> 'AdditionalInfo' as "Additional Info"
from
aws_emr_cluster,
jsonb_array_elements(applications) as app
where
cluster_arn = $1;
EOQ
}
query "emr_cluster_ec2_instance_attributes" {
sql = <<-EOQ
select
ec2_instance_attributes ->> 'Ec2KeyName' as "Ec2 Key Name",
ec2_instance_attributes ->> 'Ec2SubnetId' as "Ec2 Subnet Id",
ec2_instance_attributes ->> 'IamInstanceProfile' as "Iam Instance Profile",
ec2_instance_attributes ->> 'Ec2AvailabilityZone' as "Ec2 Availability Zone",
ec2_instance_attributes ->> 'ServiceAccessSecurityGroup' as "Service Access Security Group",
ec2_instance_attributes ->> 'EmrManagedSlaveSecurityGroup' as "Emr Managed Slave Security Group",
ec2_instance_attributes ->> 'EmrManagedMasterSecurityGroup' as "Emr Managed Master Security Group"
from
aws_emr_cluster
where
cluster_arn = $1;
EOQ
}