From 29e42b4b84197cb01761fb0363ca7e31b9a45223 Mon Sep 17 00:00:00 2001 From: Billy Lynch Date: Mon, 22 Apr 2024 18:43:12 -0400 Subject: [PATCH] Attempt to filter out default values from dashboard sections. Default values are zero-ed out by the APIs, causing lots of diffs between wat's live and what's being proposed. This changes the behavior to zero out known common fields. --- modules/dashboard/sections/collapsible/main.tf | 6 +++--- modules/dashboard/sections/layout/main.tf | 4 ++-- modules/dashboard/widgets/xy-ratio/main.tf | 17 +++++++++++------ modules/dashboard/widgets/xy/main.tf | 17 +++++++++++------ 4 files changed, 27 insertions(+), 17 deletions(-) diff --git a/modules/dashboard/sections/collapsible/main.tf b/modules/dashboard/sections/collapsible/main.tf index 874ae2d4..06214223 100644 --- a/modules/dashboard/sections/collapsible/main.tf +++ b/modules/dashboard/sections/collapsible/main.tf @@ -10,14 +10,14 @@ module "width" { source = "../width" } output "section" { value = concat([{ - yPos = local.start_row - xPos = 0, + yPos = local.start_row != 0 ? local.start_row : null, + xPos = null, 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 collapsibleGroup = { - collapsed = var.collapsed + collapsed = var.collapsed ? true : null } }, }], var.tiles) diff --git a/modules/dashboard/sections/layout/main.tf b/modules/dashboard/sections/layout/main.tf index bc0f045e..317dc65b 100644 --- a/modules/dashboard/sections/layout/main.tf +++ b/modules/dashboard/sections/layout/main.tf @@ -14,8 +14,8 @@ locals { // the section, which starts after the topmost tile of the preceding section. rebased = [for s in var.sections : [ for t in s : { - yPos = t.yPos + local.sum_heights[index(var.sections, s)] - xPos = t.xPos + yPos = t.yPos + local.sum_heights[index(var.sections, s)] != 0 ? t.yPos + local.sum_heights[index(var.sections, s)] : null + xPos = t.xPos != 0 ? t.xPos : null height = t.height width = t.width widget = t.widget diff --git a/modules/dashboard/widgets/xy-ratio/main.tf b/modules/dashboard/widgets/xy-ratio/main.tf index f6ec31d2..a5e1f531 100644 --- a/modules/dashboard/widgets/xy-ratio/main.tf +++ b/modules/dashboard/widgets/xy-ratio/main.tf @@ -12,6 +12,11 @@ variable "denominator_align" { default = "ALIGN_RATE" } variable "denominator_reduce" { default = "REDUCE_SUM" } variable "thresholds" { default = [] } +locals { + default_align = "ALIGN_RATE" + default_reduce = "REDUCE_NONE" +} + // https://cloud.google.com/monitoring/api/ref_v3/rest/v1/projects.dashboards#XyChart output "widget" { value = { @@ -30,18 +35,18 @@ output "widget" { filter = join("\n", var.numerator_filter) aggregation = { alignmentPeriod = var.alignment_period - perSeriesAligner = var.numerator_align - crossSeriesReducer = var.numerator_reduce - groupByFields = var.numerator_group_by_fields + perSeriesAligner = var.numerator_align == local.default_align ? null : var.numerator_align + crossSeriesReducer = var.numerator_reduce == local.default_reduce ? null : var.numerator_reduce + groupByFields = length(var.numerator_group_by_fields) == 0 ? null : var.numerator_group_by_fields } } denominator = { filter = join("\n", var.denominator_filter) aggregation = { alignmentPeriod = var.alignment_period - perSeriesAligner = var.denominator_align - crossSeriesReducer = var.denominator_reduce - groupByFields = var.denominator_group_by_fields + perSeriesAligner = var.denominator_align == local.default_align ? null : var.denominator_align + crossSeriesReducer = var.denominator_reduce == local.default_reduce ? null : var.denominator_reduce + groupByFields = length(var.denominator_group_by_fields) } } } diff --git a/modules/dashboard/widgets/xy/main.tf b/modules/dashboard/widgets/xy/main.tf index 4c7a40d6..83b50e09 100644 --- a/modules/dashboard/widgets/xy/main.tf +++ b/modules/dashboard/widgets/xy/main.tf @@ -8,6 +8,11 @@ variable "primary_reduce" { default = "REDUCE_NONE" } variable "secondary_align" { default = "ALIGN_NONE" } variable "secondary_reduce" { default = "REDUCE_NONE" } +locals { + default_align = "ALIGN_RATE" + default_reduce = "REDUCE_NONE" +} + // https://cloud.google.com/monitoring/api/ref_v3/rest/v1/projects.dashboards#XyChart output "widget" { value = { @@ -22,16 +27,16 @@ output "widget" { timeSeriesFilter = { aggregation = { alignmentPeriod = var.alignment_period - perSeriesAligner = var.primary_align - crossSeriesReducer = var.primary_reduce - groupByFields = var.group_by_fields + perSeriesAligner = var.primary_align == local.default_align ? null : var.primary_align + crossSeriesReducer = var.primary_reduce == local.default_reduce ? null : var.primary_reduce + groupByFields = length(var.group_by_fields) == 0 ? null : var.group_by_fields } filter = join("\n", var.filter) secondaryAggregation = { alignmentPeriod = var.alignment_period - perSeriesAligner = var.secondary_align - crossSeriesReducer = var.secondary_reduce - groupByFields = var.group_by_fields + perSeriesAligner = var.secondary_align == local.default_align ? null : var.secondary_align + crossSeriesReducer = var.secondary_reduce == local.default_reduce ? null : var.secondary_reduce + groupByFields = length(var.group_by_fields) == 0 ? null : var.group_by_fields } } }