From 6d65f9b8e9b63122e8c65512c1052b80dd086625 Mon Sep 17 00:00:00 2001 From: Jason Hall Date: Tue, 19 Dec 2023 14:06:47 -0500 Subject: [PATCH] simplify inputs/outputs, add docs Signed-off-by: Jason Hall --- dashboard/job/README.md | 9 ++---- dashboard/job/dashboard.tf | 55 ++++++---------------------------- dashboard/job/variables.tf | 12 +++----- dashboard/service/README.md | 9 ++---- dashboard/service/dashboard.tf | 47 ++++++++--------------------- dashboard/service/variables.tf | 11 ++----- dashboard/topic/README.md | 5 +--- dashboard/topic/dashboard.tf | 12 -------- dashboard/topic/variables.tf | 1 - 9 files changed, 33 insertions(+), 128 deletions(-) diff --git a/dashboard/job/README.md b/dashboard/job/README.md index 25499808..d8bb0156 100644 --- a/dashboard/job/README.md +++ b/dashboard/job/README.md @@ -13,7 +13,6 @@ No requirements. | Name | Source | Version | |------|--------|---------| -| [alert](#module\_alert) | ../tiles/alert | n/a | | [cpu\_utilization](#module\_cpu\_utilization) | ../tiles/xy | n/a | | [logs](#module\_logs) | ../tiles/logs | n/a | | [memory\_utilization](#module\_memory\_utilization) | ../tiles/xy | n/a | @@ -31,13 +30,9 @@ No requirements. | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| -| [alert\_policies](#input\_alert\_policies) | n/a |
map(object({
id = string
}))
| `{}` | no | -| [job\_name](#input\_job\_name) | n/a | `string` | n/a | yes | -| [project\_id](#input\_project\_id) | n/a | `string` | n/a | yes | +| [job\_name](#input\_job\_name) | Name of the job(s) to monitor | `string` | n/a | yes | ## Outputs -| Name | Description | -|------|-------------| -| [url](#output\_url) | n/a | +No outputs. diff --git a/dashboard/job/dashboard.tf b/dashboard/job/dashboard.tf index 9b0b5dec..fc005b54 100644 --- a/dashboard/job/dashboard.tf +++ b/dashboard/job/dashboard.tf @@ -1,13 +1,4 @@ -locals { - common_filter = ["resource.type=\"cloud_run_job\""] -} - -module "alert" { - for_each = var.alert_policies - source = "../tiles/alert" - title = "Alert: ${each.key}" - alert_name = each.value.id -} +locals { common_filter = ["resource.type=\"cloud_run_job\""] } module "logs" { source = "../tiles/logs" @@ -56,8 +47,6 @@ module "received_bytes" { } resource "google_monitoring_dashboard" "dashboard" { - project = var.project_id - dashboard_json = jsonencode({ displayName = "Cloud Run Job: ${var.job_name}" dashboardFilters = [{ @@ -68,40 +57,14 @@ resource "google_monitoring_dashboard" "dashboard" { // https://cloud.google.com/monitoring/api/ref_v3/rest/v1/projects.dashboards#GridLayout gridLayout = { columns = 3 - widgets = concat( - [for k in sort(keys(var.alert_policies)) : module.alert[k].tile], - [ - module.logs.tile, - module.cpu_utilization.tile, - module.memory_utilization.tile, - module.startup_latency.tile, - module.sent_bytes.tile, - module.received_bytes.tile, - - // These also work: - //{ text = { - // content = "_Created on ${timestamp()}_", - // format = "MARKDOWN" - //} }, - //{ blank = {} }, - - // Only allowed in mosaicLayout, where we manage rows/columns ourselves :( - // { collapsibleGroup = { collapsed = true } }, - - // NB: Sometimes updating the dashboard fails due to: - // https://github.com/hashicorp/terraform-provider-google/issues/16439 - // When this happens, terraform destroy and apply again. - ], - ) + widgets = [ + module.logs.tile, + module.cpu_utilization.tile, + module.memory_utilization.tile, + module.startup_latency.tile, + module.sent_bytes.tile, + module.received_bytes.tile, + ] } }) } - -locals { - parts = split("/", resource.google_monitoring_dashboard.dashboard.id) - dashboard_id = local.parts[length(local.parts) - 1] -} - -output "url" { - value = "https://console.cloud.google.com/monitoring/dashboards/builder/${local.dashboard_id};duration=P1D?project=${var.project_id}" -} diff --git a/dashboard/job/variables.tf b/dashboard/job/variables.tf index 6a577f72..7e83b2c2 100644 --- a/dashboard/job/variables.tf +++ b/dashboard/job/variables.tf @@ -1,9 +1,5 @@ -variable "project_id" { type = string } -variable "job_name" { type = string } - -variable "alert_policies" { - type = map(object({ - id = string - })) - default = {} +variable "job_name" { + description = "Name of the job(s) to monitor" + type = string } + diff --git a/dashboard/service/README.md b/dashboard/service/README.md index 924f8517..21faadbe 100644 --- a/dashboard/service/README.md +++ b/dashboard/service/README.md @@ -13,7 +13,6 @@ No requirements. | Name | Source | Version | |------|--------|---------| -| [alert](#module\_alert) | ../tiles/alert | n/a | | [cpu\_utilization](#module\_cpu\_utilization) | ../tiles/xy | n/a | | [incoming\_latency](#module\_incoming\_latency) | ../tiles/latency | n/a | | [instance\_count](#module\_instance\_count) | ../tiles/xy | n/a | @@ -34,13 +33,9 @@ No requirements. | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| -| [alert\_policies](#input\_alert\_policies) | n/a |
map(object({
id = string
}))
| `{}` | no | -| [project\_id](#input\_project\_id) | n/a | `string` | n/a | yes | -| [service\_name](#input\_service\_name) | n/a | `string` | n/a | yes | +| [service\_name](#input\_service\_name) | Name of the service(s) to monitor | `string` | n/a | yes | ## Outputs -| Name | Description | -|------|-------------| -| [url](#output\_url) | n/a | +No outputs. diff --git a/dashboard/service/dashboard.tf b/dashboard/service/dashboard.tf index d4d10b66..3ce2150d 100644 --- a/dashboard/service/dashboard.tf +++ b/dashboard/service/dashboard.tf @@ -1,13 +1,4 @@ -locals { - common_filter = ["resource.type=\"cloud_run_revision\""] -} - -module "alert" { - for_each = var.alert_policies - source = "../tiles/alert" - title = "Alert: ${each.key}" - alert_name = each.value.id -} +locals { common_filter = ["resource.type=\"cloud_run_revision\""] } module "logs" { source = "../tiles/logs" @@ -83,8 +74,6 @@ module "received_bytes" { } resource "google_monitoring_dashboard" "dashboard" { - project = var.project_id - dashboard_json = jsonencode({ displayName = "Cloud Run Service: ${var.service_name}" dashboardFilters = [{ @@ -95,29 +84,17 @@ resource "google_monitoring_dashboard" "dashboard" { // https://cloud.google.com/monitoring/api/ref_v3/rest/v1/projects.dashboards#GridLayout gridLayout = { columns = 3 - widgets = concat( - [for k in sort(keys(var.alert_policies)) : module.alert[k].tile], - [ - module.logs.tile, - module.request_count.tile, - module.incoming_latency.tile, - module.instance_count.tile, - module.cpu_utilization.tile, - module.memory_utilization.tile, - module.startup_latency.tile, - module.sent_bytes.tile, - module.received_bytes.tile, - ], - ) + widgets = [ + module.logs.tile, + module.request_count.tile, + module.incoming_latency.tile, + module.instance_count.tile, + module.cpu_utilization.tile, + module.memory_utilization.tile, + module.startup_latency.tile, + module.sent_bytes.tile, + module.received_bytes.tile, + ] } }) } - -locals { - parts = split("/", resource.google_monitoring_dashboard.dashboard.id) - dashboard_id = local.parts[length(local.parts) - 1] -} - -output "url" { - value = "https://console.cloud.google.com/monitoring/dashboards/builder/${local.dashboard_id};duration=P1D?project=${var.project_id}" -} diff --git a/dashboard/service/variables.tf b/dashboard/service/variables.tf index 7d8cda09..6d6bb3f6 100644 --- a/dashboard/service/variables.tf +++ b/dashboard/service/variables.tf @@ -1,9 +1,4 @@ -variable "project_id" { type = string } -variable "service_name" { type = string } - -variable "alert_policies" { - type = map(object({ - id = string - })) - default = {} +variable "service_name" { + description = "Name of the service(s) to monitor" + type = string } diff --git a/dashboard/topic/README.md b/dashboard/topic/README.md index 7df56b41..fb7b4999 100644 --- a/dashboard/topic/README.md +++ b/dashboard/topic/README.md @@ -29,12 +29,9 @@ No requirements. | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| | [alert\_policies](#input\_alert\_policies) | n/a |
map(object({
id = string
}))
| `{}` | no | -| [project\_id](#input\_project\_id) | n/a | `string` | n/a | yes | | [subscription\_prefix](#input\_subscription\_prefix) | n/a | `string` | n/a | yes | ## Outputs -| Name | Description | -|------|-------------| -| [url](#output\_url) | n/a | +No outputs. diff --git a/dashboard/topic/dashboard.tf b/dashboard/topic/dashboard.tf index e819ebd6..e0d538d8 100644 --- a/dashboard/topic/dashboard.tf +++ b/dashboard/topic/dashboard.tf @@ -49,8 +49,6 @@ module "push-latency" { } resource "google_monitoring_dashboard" "dashboard" { - project = var.project_id - dashboard_json = jsonencode({ displayName = "Subscriptions: ${var.subscription_prefix}", gridLayout = { @@ -64,13 +62,3 @@ resource "google_monitoring_dashboard" "dashboard" { } }) } - -locals { - parts = split("/", resource.google_monitoring_dashboard.dashboard.id) - dashboard_id = local.parts[length(local.parts) - 1] -} - -output "url" { - value = "https://console.cloud.google.com/monitoring/dashboards/builder/${local.dashboard_id};duration=P1D?project=${var.project_id}" -} - diff --git a/dashboard/topic/variables.tf b/dashboard/topic/variables.tf index 4f02c59e..e3fc53c0 100644 --- a/dashboard/topic/variables.tf +++ b/dashboard/topic/variables.tf @@ -1,4 +1,3 @@ -variable "project_id" { type = string } variable "subscription_prefix" { type = string } variable "alert_policies" {