Skip to content

Commit 8c9943c

Browse files

File tree

7 files changed

+75
-19
lines changed

7 files changed

+75
-19
lines changed

modules/cloudevent-broker/ingress.tf

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,10 @@ module "http" {
6363
}
6464

6565
module "resources" {
66-
source = "../dashboard/sections/resources"
67-
title = "Resources"
68-
filter = ["resource.type=\"cloud_run_revision\""]
66+
source = "../dashboard/sections/resources"
67+
title = "Resources"
68+
filter = ["resource.type=\"cloud_run_revision\"", "resource.labels.service_name=\"${var.name}\""]
69+
cloudrun_name = var.name
6970
}
7071

7172
module "width" { source = "../dashboard/sections/width" }

modules/dashboard/cloudevent-receiver/dashboard.tf

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ module "http" {
2323
}
2424

2525
module "resources" {
26-
source = "../sections/resources"
27-
title = "Resources"
28-
filter = ["resource.type=\"cloud_run_revision\""]
26+
source = "../sections/resources"
27+
title = "Resources"
28+
filter = ["resource.type=\"cloud_run_revision\"", "resource.labels.service_name=\"${var.service_name}\""]
29+
cloudrun_name = var.service_name
2930
}
3031

3132
module "width" { source = "../sections/width" }

modules/dashboard/job/dashboard.tf

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ module "logs" {
55
}
66

77
module "resources" {
8-
source = "../sections/resources"
9-
title = "Resources"
10-
filter = ["resource.type=\"cloud_run_job\""]
8+
source = "../sections/resources"
9+
title = "Resources"
10+
filter = ["resource.type=\"cloud_run_job\"", "resource.labels.job_name=\"${var.job_name}\""]
11+
cloudrun_name = var.job_name
1112
}
1213

1314
module "width" { source = "../sections/width" }

modules/dashboard/sections/resources/main.tf

Lines changed: 51 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
variable "title" { type = string }
22
variable "filter" { type = list(string) }
3+
variable "cloudrun_name" { type = string }
34
variable "collapsed" { default = false }
5+
variable "notification_channels" {
6+
type = list(string)
7+
default = []
8+
}
49

510
module "width" { source = "../width" }
611

@@ -55,6 +60,38 @@ module "received_bytes" {
5560
primary_reduce = "REDUCE_NONE"
5661
}
5762

63+
module "oom_alert" {
64+
source = "../../widgets/alert"
65+
title = google_monitoring_alert_policy.oom.display_name
66+
alert_name = google_monitoring_alert_policy.oom.name
67+
}
68+
69+
resource "google_monitoring_alert_policy" "oom" {
70+
# In the absence of data, incident will auto-close in 7 days
71+
alert_strategy {
72+
auto_close = "604800s"
73+
74+
notification_rate_limit {
75+
period = "86400s" // re-alert once a day if condition still valid.
76+
}
77+
}
78+
79+
display_name = "${var.cloudrun_name} OOM Alert"
80+
combiner = "OR"
81+
82+
conditions {
83+
display_name = "${var.cloudrun_name} OOM Alert"
84+
85+
condition_matched_log {
86+
filter = "${join(" AND ", var.filter)} AND logName:\"run.googleapis.com%2Fvarlog%2Fsystem\" AND severity=ERROR AND textPayload:\"Consider increasing the memory limit\""
87+
}
88+
}
89+
90+
enabled = "true"
91+
92+
notification_channels = var.notification_channels
93+
}
94+
5895
locals {
5996
columns = 3
6097
unit = module.width.size / local.columns
@@ -67,39 +104,46 @@ locals {
67104
yPos = 0,
68105
xPos = local.col[0],
69106
height = local.unit,
70-
width = local.unit,
71-
widget = module.cpu_utilization.widget,
107+
width = module.width.size,
108+
widget = module.oom_alert.widget,
72109
},
73110
{
74-
yPos = 0,
111+
yPos = local.unit,
112+
xPos = local.col[0],
113+
height = local.unit,
114+
width = local.unit,
115+
widget = module.cpu_utilization.widget,
116+
},
117+
{
118+
yPos = local.unit,
75119
xPos = local.col[1],
76120
height = local.unit,
77121
width = local.unit,
78122
widget = module.memory_utilization.widget,
79123
},
80124
{
81-
yPos = 0,
125+
yPos = local.unit,
82126
xPos = local.col[2],
83127
height = local.unit,
84128
width = local.unit,
85129
widget = module.instance_count.widget,
86130
},
87131
{
88-
yPos = local.unit,
132+
yPos = local.unit * 2,
89133
xPos = local.col[0],
90134
height = local.unit,
91135
width = local.unit,
92136
widget = module.startup_latency.widget,
93137
},
94138
{
95-
yPos = local.unit,
139+
yPos = local.unit * 2,
96140
xPos = local.col[1],
97141
height = local.unit,
98142
width = local.unit,
99143
widget = module.sent_bytes.widget,
100144
},
101145
{
102-
yPos = local.unit,
146+
yPos = local.unit * 2,
103147
xPos = local.col[2],
104148
height = local.unit,
105149
width = local.unit,

modules/dashboard/service/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ No requirements.
8282
|------|-------------|------|---------|:--------:|
8383
| <a name="input_alerts"></a> [alerts](#input\_alerts) | A mapping from alerting policy names to the alert ids to add to the dashboard. | `map(string)` | `{}` | no |
8484
| <a name="input_labels"></a> [labels](#input\_labels) | Additional labels to apply to the dashboard. | `map` | `{}` | no |
85+
| <a name="input_notification_channels"></a> [notification\_channels](#input\_notification\_channels) | List of notification channels to alert. | `list(string)` | `[]` | no |
8586
| <a name="input_project_id"></a> [project\_id](#input\_project\_id) | ID of the GCP project | `string` | n/a | yes |
8687
| <a name="input_service_name"></a> [service\_name](#input\_service\_name) | Name of the service(s) to monitor | `string` | n/a | yes |
8788

modules/dashboard/service/dashboard.tf

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@ module "grpc" {
2626
}
2727

2828
module "resources" {
29-
source = "../sections/resources"
30-
title = "Resources"
31-
filter = ["resource.type=\"cloud_run_revision\""]
29+
source = "../sections/resources"
30+
title = "Resources"
31+
filter = ["resource.type=\"cloud_run_revision\"", "resource.labels.service_name=\"${var.service_name}\""]
32+
cloudrun_name = var.service_name
33+
notification_channels = var.notification_channels
3234
}
3335

3436
module "alerts" {

modules/dashboard/service/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,9 @@ variable "project_id" {
1818
description = "ID of the GCP project"
1919
type = string
2020
}
21+
22+
variable "notification_channels" {
23+
description = "List of notification channels to alert."
24+
type = list(string)
25+
default = []
26+
}

0 commit comments

Comments
 (0)