Skip to content

Commit

Permalink
Attempt to filter out default values from dashboard sections.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
wlynch committed Apr 22, 2024
1 parent 27d40ce commit 29e42b4
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 17 deletions.
6 changes: 3 additions & 3 deletions modules/dashboard/sections/collapsible/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions modules/dashboard/sections/layout/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 11 additions & 6 deletions modules/dashboard/widgets/xy-ratio/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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)
}
}
}
Expand Down
17 changes: 11 additions & 6 deletions modules/dashboard/widgets/xy/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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
}
}
}
Expand Down

0 comments on commit 29e42b4

Please sign in to comment.