Skip to content

Commit 2121113

Browse files
authored
use custom service for monitoring to support multi-region (#1171)
basic_service does not allow multi-region service support --------- Signed-off-by: Kenny Leung <[email protected]>
1 parent ecd26ff commit 2121113

File tree

3 files changed

+7
-16
lines changed

3 files changed

+7
-16
lines changed

modules/slo/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ No modules.
1919
|------|------|
2020
| [google_monitoring_alert_policy.slo_burn_rate_multi_region](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/monitoring_alert_policy) | resource |
2121
| [google_monitoring_alert_policy.slo_burn_rate_per_region](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/monitoring_alert_policy) | resource |
22-
| [google_monitoring_service.this](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/monitoring_service) | resource |
22+
| [google_monitoring_custom_service.this](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/monitoring_custom_service) | resource |
2323
| [google_monitoring_slo.availability](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/monitoring_slo) | resource |
2424
| [google_monitoring_slo.availability_per_region](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/monitoring_slo) | resource |
2525

@@ -32,7 +32,7 @@ No modules.
3232
| <a name="input_regions"></a> [regions](#input\_regions) | A list of regions that the cloudrun service is deployed in. | `list(string)` | n/a | yes |
3333
| <a name="input_service_name"></a> [service\_name](#input\_service\_name) | Name of service to setup SLO for. | `string` | n/a | yes |
3434
| <a name="input_service_type"></a> [service\_type](#input\_service\_type) | Type of service to setup SLO for. | `string` | `"CLOUD_RUN"` | no |
35-
| <a name="input_slo"></a> [slo](#input\_slo) | Configuration for setting up SLO | <pre>object({<br/> enable = optional(bool, false)<br/> enable_alerting = optional(bool, false)<br/> availability = optional(object(<br/> {<br/> multi_region_goal = optional(number, 0.999)<br/> per_region_goal = optional(number, 0.999)<br/> }<br/> ), null)<br/> })</pre> | `{}` | no |
35+
| <a name="input_slo"></a> [slo](#input\_slo) | Configuration for setting up SLO | <pre>object({<br/> enable = optional(bool, false)<br/> enable_alerting = optional(bool, false)<br/> availability = optional(object(<br/> {<br/> multi_region_goal = optional(number, 0.999)<br/> per_region_goal = optional(number, 0.999)<br/> }<br/> ), {})<br/> })</pre> | `{}` | no |
3636

3737
## Outputs
3838

modules/slo/main.tf

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,14 @@ locals {
22
region_filter = "one_of(${join(", ", formatlist("%q", var.regions))})"
33
}
44

5-
resource "google_monitoring_service" "this" {
5+
resource "google_monitoring_custom_service" "this" {
66
service_id = "${lower(var.service_type)}-${lower(var.service_name)}"
77
project = var.project_id
8-
9-
basic_service {
10-
service_type = var.service_type
11-
service_labels = {
12-
service_name = var.service_name
13-
}
14-
}
158
}
169

1710
# SLO with availability SLI across all regions
1811
resource "google_monitoring_slo" "availability" {
19-
count = var.slo.availability != null ? 1 : 0
20-
21-
service = google_monitoring_service.this.service_id
12+
service = google_monitoring_custom_service.this.service_id
2213
slo_id = "${var.service_name}-availability-multi-region"
2314
display_name = "${var.service_name} - Multi-region Availability SLO"
2415
project = var.project_id
@@ -34,7 +25,7 @@ resource "google_monitoring_slo" "availability" {
3425
resource "google_monitoring_slo" "availability_per_region" {
3526
for_each = var.slo.availability != null ? toset(var.regions) : []
3627

37-
service = google_monitoring_service.this.service_id
28+
service = google_monitoring_custom_service.this.service_id
3829
slo_id = "${var.service_name}-availability-${each.value}"
3930
display_name = "${var.service_name} - ${each.value} Availability SLO"
4031
project = var.project_id
@@ -60,7 +51,7 @@ resource "google_monitoring_alert_policy" "slo_burn_rate_multi_region" {
6051

6152
condition_threshold {
6253
filter = <<-EOT
63-
select_slo_burn_rate("${google_monitoring_slo.availability[0].id}", 3600)
54+
select_slo_burn_rate("${google_monitoring_slo.availability.id}", 3600)
6455
EOT
6556

6657
duration = "0s"

modules/slo/variables.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ variable "slo" {
2929
multi_region_goal = optional(number, 0.999)
3030
per_region_goal = optional(number, 0.999)
3131
}
32-
), null)
32+
), {})
3333
})
3434
default = {}
3535
}

0 commit comments

Comments
 (0)