Skip to content

Commit

Permalink
support passing an alert ID to service dashboards
Browse files Browse the repository at this point in the history
Signed-off-by: Jason Hall <jason@chainguard.dev>
  • Loading branch information
imjasonh committed Dec 21, 2023
1 parent acde85a commit d41f8a4
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 6 deletions.
34 changes: 34 additions & 0 deletions dashboard/sections/alerts/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
variable "title" { type = string }
variable "collapsed" { default = false }
variable "alert" { type = string }

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

module "alert" {
source = "../../widgets/alert"
title = "Alert"
alert_name = var.alert
}

locals {
tiles = [{
yPos = 0
xPos = 0
height = 3
width = module.width.size
widget = module.alert.widget
}]
}

module "collapsible" {
source = "../collapsible"

// If no alert is defined, this is an empty collapsed section.
title = var.title
tiles = var.alert == "" ? [] : local.tiles
collapsed = var.collapsed || var.alert == ""
}

output "section" {
value = module.collapsible.section
}
2 changes: 2 additions & 0 deletions dashboard/service/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ No requirements.

| Name | Source | Version |
|------|--------|---------|
| <a name="module_alerts"></a> [alerts](#module\_alerts) | ../sections/alerts | n/a |
| <a name="module_http"></a> [http](#module\_http) | ../sections/http | n/a |
| <a name="module_layout"></a> [layout](#module\_layout) | ../sections/layout | n/a |
| <a name="module_logs"></a> [logs](#module\_logs) | ../sections/logs | n/a |
Expand All @@ -68,6 +69,7 @@ No requirements.

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_alert"></a> [alert](#input\_alert) | Alerting policies to add to the dashboard. | `string` | `""` | no |
| <a name="input_labels"></a> [labels](#input\_labels) | Additional labels to apply to the dashboard. | `map` | `{}` | no |
| <a name="input_service_name"></a> [service\_name](#input\_service\_name) | Name of the service(s) to monitor | `string` | n/a | yes |

Expand Down
21 changes: 15 additions & 6 deletions dashboard/service/dashboard.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,24 @@ module "resources" {
filter = ["resource.type=\"cloud_run_revision\""]
}

module "alerts" {
source = "../sections/alerts"
alert = var.alert
title = "Alert"
}

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

module "layout" {
source = "../sections/layout"
sections = [
module.logs.section,
module.http.section,
module.resources.section,
]
source = "../sections/layout"
sections = concat(
var.alert == "" ? [] : [module.alerts.section],
[
module.logs.section,
module.http.section,
module.resources.section,
]
)
}

resource "google_monitoring_dashboard" "dashboard" {
Expand Down
7 changes: 7 additions & 0 deletions dashboard/service/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,10 @@ variable "labels" {
description = "Additional labels to apply to the dashboard."
default = {}
}

variable "alert" {
description = "Alerting policies to add to the dashboard."
type = string
default = ""
}

0 comments on commit d41f8a4

Please sign in to comment.