From e3d02246c01e0c21208c43f00e21691fb3546969 Mon Sep 17 00:00:00 2001 From: Matt Moore Date: Wed, 20 Dec 2023 22:31:17 -0500 Subject: [PATCH] Add support for labeling dashboards. (#24) --- cloudevent-broker/ingress.tf | 4 ++++ dashboard/cloudevent-receiver/README.md | 1 + dashboard/cloudevent-receiver/dashboard.tf | 4 ++++ dashboard/cloudevent-receiver/variables.tf | 5 +++++ dashboard/job/README.md | 1 + dashboard/job/dashboard.tf | 3 +++ dashboard/job/variables.tf | 4 ++++ dashboard/service/README.md | 1 + dashboard/service/dashboard.tf | 3 +++ dashboard/service/variables.tf | 5 +++++ 10 files changed, 31 insertions(+) diff --git a/cloudevent-broker/ingress.tf b/cloudevent-broker/ingress.tf index 9546ded2..bfb39fca 100644 --- a/cloudevent-broker/ingress.tf +++ b/cloudevent-broker/ingress.tf @@ -120,6 +120,10 @@ module "layout" { resource "google_monitoring_dashboard" "dashboard" { dashboard_json = jsonencode({ displayName = "Cloud Events Broker Ingress: ${var.name}" + labels = { + "service" : "" + "eventing" : "" + } dashboardFilters = [{ filterType = "RESOURCE_LABEL" stringValue = var.name diff --git a/dashboard/cloudevent-receiver/README.md b/dashboard/cloudevent-receiver/README.md index e9d965af..90556a1e 100644 --- a/dashboard/cloudevent-receiver/README.md +++ b/dashboard/cloudevent-receiver/README.md @@ -90,6 +90,7 @@ No requirements. | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| +| [labels](#input\_labels) | Additional labels to apply to the dashboard. | `map` | `{}` | no | | [service\_name](#input\_service\_name) | Name of the service(s) to monitor | `string` | n/a | yes | | [triggers](#input\_triggers) | A mapping from a descriptive name to a subscription name prefix. | `map(string)` | n/a | yes | diff --git a/dashboard/cloudevent-receiver/dashboard.tf b/dashboard/cloudevent-receiver/dashboard.tf index 00361c69..c2ff450d 100644 --- a/dashboard/cloudevent-receiver/dashboard.tf +++ b/dashboard/cloudevent-receiver/dashboard.tf @@ -42,6 +42,10 @@ module "layout" { resource "google_monitoring_dashboard" "dashboard" { dashboard_json = jsonencode({ displayName = "Cloud Event Receiver: ${var.service_name}" + labels = merge({ + "service" : "" + "eventing" : "" + }, var.labels) dashboardFilters = [{ filterType = "RESOURCE_LABEL" stringValue = var.service_name diff --git a/dashboard/cloudevent-receiver/variables.tf b/dashboard/cloudevent-receiver/variables.tf index fb221bfb..06c40f92 100644 --- a/dashboard/cloudevent-receiver/variables.tf +++ b/dashboard/cloudevent-receiver/variables.tf @@ -3,6 +3,11 @@ variable "service_name" { type = string } +variable "labels" { + description = "Additional labels to apply to the dashboard." + default = {} +} + variable "triggers" { description = "A mapping from a descriptive name to a subscription name prefix." type = map(string) diff --git a/dashboard/job/README.md b/dashboard/job/README.md index 9b9543ce..2f9687f6 100644 --- a/dashboard/job/README.md +++ b/dashboard/job/README.md @@ -58,6 +58,7 @@ No requirements. | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| | [job\_name](#input\_job\_name) | Name of the job(s) to monitor | `string` | n/a | yes | +| [labels](#input\_labels) | Additional labels to apply to the dashboard. | `map` | `{}` | no | ## Outputs diff --git a/dashboard/job/dashboard.tf b/dashboard/job/dashboard.tf index e6f952d9..fbd88372 100644 --- a/dashboard/job/dashboard.tf +++ b/dashboard/job/dashboard.tf @@ -23,6 +23,9 @@ module "layout" { resource "google_monitoring_dashboard" "dashboard" { dashboard_json = jsonencode({ displayName = "Cloud Run Job: ${var.job_name}" + labels = merge({ + "job" : "" + }, var.labels) dashboardFilters = [{ filterType = "RESOURCE_LABEL" stringValue = var.job_name diff --git a/dashboard/job/variables.tf b/dashboard/job/variables.tf index 7e83b2c2..9912a64a 100644 --- a/dashboard/job/variables.tf +++ b/dashboard/job/variables.tf @@ -3,3 +3,7 @@ variable "job_name" { type = string } +variable "labels" { + description = "Additional labels to apply to the dashboard." + default = {} +} diff --git a/dashboard/service/README.md b/dashboard/service/README.md index c30ce0b4..52d370bf 100644 --- a/dashboard/service/README.md +++ b/dashboard/service/README.md @@ -68,6 +68,7 @@ No requirements. | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| +| [labels](#input\_labels) | Additional labels to apply to the dashboard. | `map` | `{}` | no | | [service\_name](#input\_service\_name) | Name of the service(s) to monitor | `string` | n/a | yes | ## Outputs diff --git a/dashboard/service/dashboard.tf b/dashboard/service/dashboard.tf index 9386a7fe..60239eaa 100644 --- a/dashboard/service/dashboard.tf +++ b/dashboard/service/dashboard.tf @@ -30,6 +30,9 @@ module "layout" { resource "google_monitoring_dashboard" "dashboard" { dashboard_json = jsonencode({ displayName = "Cloud Run Service: ${var.service_name}" + labels = merge({ + "service" : "" + }, var.labels) dashboardFilters = [{ filterType = "RESOURCE_LABEL" stringValue = var.service_name diff --git a/dashboard/service/variables.tf b/dashboard/service/variables.tf index 6d6bb3f6..26939403 100644 --- a/dashboard/service/variables.tf +++ b/dashboard/service/variables.tf @@ -2,3 +2,8 @@ variable "service_name" { description = "Name of the service(s) to monitor" type = string } + +variable "labels" { + description = "Additional labels to apply to the dashboard." + default = {} +}