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

fix dashboard, causing missing required displayName error #609

Merged
merged 2 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
fix dash
Signed-off-by: Kenny Leung <kleung@chainguard.dev>
  • Loading branch information
k4leung4 committed Oct 24, 2024
commit 34ebc2059449b842032dbbd04dc230140bba4d36
9 changes: 5 additions & 4 deletions modules/bucket-events/dashboard.tf
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ module "layout" {
]
}

module "dashboard-json" {
source = "../dashboard/json"
module "dashboard" {
source = "../dashboard"

object = {
displayName = "GCS Bucket Events: ${var.bucket} in ${local.region}"
Expand All @@ -61,6 +61,7 @@ module "dashboard-json" {
}
}

resource "google_monitoring_dashboard" "dashboard" {
dashboard_json = module.dashboard-json.json
moved {
from = google_monitoring_dashboard.dashboard
to = module.dashboard.google_monitoring_dashboard.dashboard
}
9 changes: 5 additions & 4 deletions modules/cloudevent-broker/ingress.tf
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ module "layout" {
]
}

module "dashboard-json" {
source = "../dashboard/json"
module "dashboard" {
source = "../dashboard"

object = {
displayName = "Cloud Events Broker Ingress: ${var.name}"
Expand All @@ -118,6 +118,7 @@ module "dashboard-json" {
}
}

resource "google_monitoring_dashboard" "dashboard" {
dashboard_json = module.dashboard-json.json
moved {
from = google_monitoring_dashboard.dashboard
to = module.dashboard.google_monitoring_dashboard.dashboard
}
54 changes: 54 additions & 0 deletions modules/dashboard/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,60 @@

The modules in this directory define [`google_monitoring_dashboard`](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/monitoring_dashboard) resources in a repeatable structured way.

This module itself creates a dashboard that cleans up defaulted no-op changes.

Check failure on line 6 in modules/dashboard/README.md

View workflow job for this annotation

GitHub Actions / Lint

[trailing whitespace] reported by reviewdog 🐶 Space at end of line Raw Output: modules/dashboard/README.md:6:Space at end of line
- The [Service](service/README.md) and [Job](job/README.md) modules define pre-configured dashboards for Cloud Run services and Cloud Run jobs, respectively.
- The [`cloudevent-receiver`](cloudevent-receiver/README.md) module defines a pre-configured dashboard for a Cloud Run-based event handler receiving events from a `cloudevent-trigger`.
- The modules in [`./widgets`](widgets/) define the widgets used by the dashboards, in a way that can be reused to create custom dashboards.

```hcl
// Call module to generate cleaned up json
module "dashboard" {
source = "chainguard-dev/common/infra//modules/dashboard"

object = {
displayName = "Elastic Build"
labels = { "elastic-builds" : "" }
dashboardFilters = []

mosaicLayout = {
columns = module.width.size
tiles = module.layout.tiles,
}
}
}
```

The dashboard resource should now diff properly.

<!-- BEGIN_TF_DOCS -->
## Requirements

No requirements.

## Providers

| Name | Version |
|------|---------|
| <a name="provider_google"></a> [google](#provider\_google) | n/a |

## Modules

No modules.

## Resources

| Name | Type |
|------|------|
| [google_monitoring_dashboard.dashboard](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/monitoring_dashboard) | resource |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_object"></a> [object](#input\_object) | Object to encode into JSON | `object({})` | n/a | yes |

## Outputs

No outputs.
<!-- END_TF_DOCS -->
9 changes: 5 additions & 4 deletions modules/dashboard/alerts/dashboard.tf
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ locals {
}]
}

module "dashboard-json" {
source = "../json"
module "dashboard" {
source = ".."

object = {
displayName = var.title
Expand All @@ -43,6 +43,7 @@ module "dashboard-json" {
}
}

resource "google_monitoring_dashboard" "dashboard" {
dashboard_json = module.dashboard-json.json
moved {
from = google_monitoring_dashboard.dashboard
to = module.dashboard.google_monitoring_dashboard.dashboard
}
32 changes: 19 additions & 13 deletions modules/dashboard/cloudevent-receiver/dashboard.tf
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ module "width" { source = "../sections/width" }

module "layout" {
// This funky for_each just creates one instance when split_triggers is false
for_each = var.split_triggers ? {} : {(var.service_name): ""}
for_each = toset(var.split_triggers ? [] : [var.service_name])

source = "../sections/layout"
sections = concat(
[for key in sort(keys(var.triggers)) : module.subscription[key].section],
Expand All @@ -70,10 +71,10 @@ module "layout" {
)
}

module "dashboard-json" {
for_each = var.split_triggers ? {} : {(var.service_name): ""}
module "dashboard" {
for_each = toset(var.split_triggers ? [] : [var.service_name])

source = "../json"
source = "../"

// This funky for_each just creates one instance when split_triggers is false
object = {
Expand All @@ -96,10 +97,15 @@ module "dashboard-json" {
}
}

resource "google_monitoring_dashboard" "dashboard" {
for_each = var.split_triggers ? {} : {(var.service_name): ""}
moved {
from = google_monitoring_dashboard.dashboard
to = module.trigger_dashboard.google_monitoring_dashboard.dashboard
}

dashboard_json = module.dashboard-json[each.key].json
output "json" {
value = {
for k,v in module.dashboard : k => v.json
}
}

// Google cloud has a limit of 50 widgets per dashboard so we create a dashboard
Expand All @@ -109,6 +115,7 @@ resource "google_monitoring_dashboard" "dashboard" {
// This module is opt-in and will replace the layout module above
module "trigger_layout" {
for_each = var.split_triggers ? var.triggers : {}

source = "../sections/layout"
sections = concat([module.subscription[each.key].section],
[
Expand All @@ -127,10 +134,10 @@ module "trigger_layout" {
// do not hit the widget limit.
//
// This resource is opt-in and will replace the dashboard resource above
module "trigger-dashboard-jsons" {
module "trigger-dashboards" {
for_each = var.split_triggers ? var.triggers : {}

source = "../json"
source = "../"

object = {
displayName = "Cloud Event Receiver: ${var.service_name} (${each.key})"
Expand All @@ -152,8 +159,7 @@ module "trigger-dashboard-jsons" {
}
}

resource "google_monitoring_dashboard" "trigger_dashboards" {
for_each = var.split_triggers ? var.triggers : {}

dashboard_json = module.trigger-dashboard-jsons[each.key].json
moved {
from = google_monitoring_dashboard.trigger_dashboards
to = module.trigger_dashboards.google_monitoring_dashboard.dashboard
}
9 changes: 5 additions & 4 deletions modules/dashboard/job/dashboard.tf
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ module "layout" {
]
}

module "dashboard-json" {
source = "../json"
module "dashboard" {
source = ".."

object = {
displayName = "Cloud Run Job: ${var.job_name}"
Expand All @@ -57,6 +57,7 @@ module "dashboard-json" {
}
}

resource "google_monitoring_dashboard" "dashboard" {
dashboard_json = module.dashboard-json.json
moved {
from = google_monitoring_dashboard.dashboard
to = module.dashboard.google_monitoring_dashboard.dashboard
}
58 changes: 0 additions & 58 deletions modules/dashboard/json/README.md

This file was deleted.

16 changes: 12 additions & 4 deletions modules/dashboard/json/main.tf → modules/dashboard/main.tf
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
variable "object" {
description = "Object to encode into JSON"
type = object({})
}

output "json" {
value = replace(replace(replace(replace(replace(replace(replace(
locals {
json = replace(replace(replace(replace(replace(replace(replace(replace(
jsonencode(var.object),
"\"collapsibleGroup\":{\"collapsed\":false},", ""),
"\"collapsed\":false", ""),
",\"xPos\":0", ""),
",\"yPos\":0", ""),
",\"thresholds\":[]", ""),
",\"crossSeriesReducer\":\"REDUCE_NONE\"", ""),
",\"perSeriesAligner\":\"ALIGN_NONE\"", ""),
"\"dashboardFilters\":[],", ""),
",\"groupByFields\":[]", "")
}

resource "google_monitoring_dashboard" "dashboard" {
dashboard_json = local.json
}

output "json" {
value = local.json
}
9 changes: 5 additions & 4 deletions modules/dashboard/service/dashboard.tf
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ module "layout" {
)
}

module "dashboard-json" {
source = "../json"
module "dashboard" {
source = ".."

object = {
displayName = "Cloud Run Service: ${var.service_name}"
Expand All @@ -94,6 +94,7 @@ module "dashboard-json" {
}
}

resource "google_monitoring_dashboard" "dashboard" {
dashboard_json = module.dashboard-json.json
moved {
from = google_monitoring_dashboard.dashboard
to = module.dashboard.google_monitoring_dashboard.dashboard
}
6 changes: 5 additions & 1 deletion modules/github-bots/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ module "cloudevent-trigger" {
}

module "dashboard" {
source = "chainguard-dev/common/infra//modules/dashboard/cloudevent-receiver"
source = "../dashboard/cloudevent-receiver"

project_id = var.project_id
service_name = var.name
Expand All @@ -90,3 +90,7 @@ module "dashboard" {

notification_channels = var.notification_channels
}

output "json" {
value = module.dashboard.json
}
9 changes: 5 additions & 4 deletions modules/github-events/dashboard.tf
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ module "layout" {
]
}

module "dashboard-json" {
source = "../dashboard/json"
module "dashboard" {
source = "../dashboard"

object = {
displayName = "GitHub Webhook Events"
Expand All @@ -54,6 +54,7 @@ module "dashboard-json" {
}
}

resource "google_monitoring_dashboard" "dashboard" {
dashboard_json = module.dashboard-json.json
moved {
from = google_monitoring_dashboard.dashboard
to = module.dashboard.google_monitoring_dashboard.dashboard
}
9 changes: 5 additions & 4 deletions modules/workqueue/dashboard.tf
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ module "layout" {
]
}

module "dashboard-json" {
source = "../dashboard/json"
module "dashboard" {
source = "../dashboard"

object = {
displayName = "Cloud Workqueue: ${var.name}"
Expand All @@ -192,6 +192,7 @@ module "dashboard-json" {
}
}

resource "google_monitoring_dashboard" "dashboard" {
dashboard_json = module.dashboard-json.json
moved {
from = google_monitoring_dashboard.dashboard
to = module.dashboard.google_monitoring_dashboard.dashboard
}
Loading