Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support passing alert IDs to service dashboards #27

Merged
merged 3 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
source = "../sections/alerts"
count = var.alert != "" ? 1 : 0
source = "../sections/alerts"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could also consider making this a list 🤔

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],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var.alert == "" ? [] : [module.alerts.section],
var.alert == "" ? [] : [module.alerts[0].section],

or

Suggested change
var.alert == "" ? [] : [module.alerts.section],
[for x in module.alerts : x.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 = ""
}

Loading