Skip to content

Commit

Permalink
simplify inputs/outputs, add docs
Browse files Browse the repository at this point in the history
Signed-off-by: Jason Hall <[email protected]>
  • Loading branch information
imjasonh committed Dec 19, 2023
1 parent 2a71fe2 commit 6d65f9b
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 128 deletions.
9 changes: 2 additions & 7 deletions dashboard/job/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ No requirements.

| Name | Source | Version |
|------|--------|---------|
| <a name="module_alert"></a> [alert](#module\_alert) | ../tiles/alert | n/a |
| <a name="module_cpu_utilization"></a> [cpu\_utilization](#module\_cpu\_utilization) | ../tiles/xy | n/a |
| <a name="module_logs"></a> [logs](#module\_logs) | ../tiles/logs | n/a |
| <a name="module_memory_utilization"></a> [memory\_utilization](#module\_memory\_utilization) | ../tiles/xy | n/a |
Expand All @@ -31,13 +30,9 @@ No requirements.

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_alert_policies"></a> [alert\_policies](#input\_alert\_policies) | n/a | <pre>map(object({<br> id = string<br> }))</pre> | `{}` | no |
| <a name="input_job_name"></a> [job\_name](#input\_job\_name) | n/a | `string` | n/a | yes |
| <a name="input_project_id"></a> [project\_id](#input\_project\_id) | n/a | `string` | n/a | yes |
| <a name="input_job_name"></a> [job\_name](#input\_job\_name) | Name of the job(s) to monitor | `string` | n/a | yes |

## Outputs

| Name | Description |
|------|-------------|
| <a name="output_url"></a> [url](#output\_url) | n/a |
No outputs.
<!-- END_TF_DOCS -->
55 changes: 9 additions & 46 deletions dashboard/job/dashboard.tf
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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 = [{
Expand All @@ -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}"
}
12 changes: 4 additions & 8 deletions dashboard/job/variables.tf
Original file line number Diff line number Diff line change
@@ -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
}

9 changes: 2 additions & 7 deletions dashboard/service/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ No requirements.

| Name | Source | Version |
|------|--------|---------|
| <a name="module_alert"></a> [alert](#module\_alert) | ../tiles/alert | n/a |
| <a name="module_cpu_utilization"></a> [cpu\_utilization](#module\_cpu\_utilization) | ../tiles/xy | n/a |
| <a name="module_incoming_latency"></a> [incoming\_latency](#module\_incoming\_latency) | ../tiles/latency | n/a |
| <a name="module_instance_count"></a> [instance\_count](#module\_instance\_count) | ../tiles/xy | n/a |
Expand All @@ -34,13 +33,9 @@ No requirements.

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_alert_policies"></a> [alert\_policies](#input\_alert\_policies) | n/a | <pre>map(object({<br> id = string<br> }))</pre> | `{}` | no |
| <a name="input_project_id"></a> [project\_id](#input\_project\_id) | n/a | `string` | n/a | yes |
| <a name="input_service_name"></a> [service\_name](#input\_service\_name) | n/a | `string` | n/a | yes |
| <a name="input_service_name"></a> [service\_name](#input\_service\_name) | Name of the service(s) to monitor | `string` | n/a | yes |

## Outputs

| Name | Description |
|------|-------------|
| <a name="output_url"></a> [url](#output\_url) | n/a |
No outputs.
<!-- END_TF_DOCS -->
47 changes: 12 additions & 35 deletions dashboard/service/dashboard.tf
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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 = [{
Expand All @@ -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}"
}
11 changes: 3 additions & 8 deletions dashboard/service/variables.tf
Original file line number Diff line number Diff line change
@@ -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
}
5 changes: 1 addition & 4 deletions dashboard/topic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,9 @@ No requirements.
| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_alert_policies"></a> [alert\_policies](#input\_alert\_policies) | n/a | <pre>map(object({<br> id = string<br> }))</pre> | `{}` | no |
| <a name="input_project_id"></a> [project\_id](#input\_project\_id) | n/a | `string` | n/a | yes |
| <a name="input_subscription_prefix"></a> [subscription\_prefix](#input\_subscription\_prefix) | n/a | `string` | n/a | yes |

## Outputs

| Name | Description |
|------|-------------|
| <a name="output_url"></a> [url](#output\_url) | n/a |
No outputs.
<!-- END_TF_DOCS -->
12 changes: 0 additions & 12 deletions dashboard/topic/dashboard.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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}"
}

1 change: 0 additions & 1 deletion dashboard/topic/variables.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
variable "project_id" { type = string }
variable "subscription_prefix" { type = string }

variable "alert_policies" {
Expand Down

0 comments on commit 6d65f9b

Please sign in to comment.