Skip to content

Commit

Permalink
support passing alert IDs to service dashboards (#27)
Browse files Browse the repository at this point in the history
This should produce full-width alert chart widgets for each alert. I
might need to iterate on this with changes in tf-prober to see this all
working together. It at least doesn't regress for non-alert-having
services.

---------

Signed-off-by: Jason Hall <[email protected]>
  • Loading branch information
imjasonh authored Dec 22, 2023
1 parent 053eec0 commit 1f49244
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 8 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
}
4 changes: 2 additions & 2 deletions dashboard/sections/collapsible/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ variable "tiles" {}
variable "collapsed" { default = false }

locals {
start_row = min([for s in var.tiles : s.yPos]...)
start_row = length(var.tiles) == 0 ? 0 : min([for s in var.tiles : s.yPos]...)
}

module "width" { source = "../width" }
Expand All @@ -12,7 +12,7 @@ output "section" {
value = concat([{
yPos = local.start_row
xPos = 0,
height = max([for s in var.tiles : s.yPos + s.height - local.start_row]...),
height = length(var.tiles) == 0 ? 0 : max([for s in var.tiles : s.yPos + s.height - local.start_row]...),
width = module.width.size,
widget = {
title = var.title
Expand Down
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 1f49244

Please sign in to comment.