Skip to content

Commit

Permalink
Fix the out of boundary error (#9628) (#16792)
Browse files Browse the repository at this point in the history
[upstream:3bacb448e960f8c56905e7012311953e920310e9]

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Dec 13, 2023
1 parent b239600 commit 206fb3b
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .changelog/9628.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
monitoring: fixed the index out of range crash in `dashboard_json` perma-diffs for the resource `google_monitoring_dashboard`
```
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func removeComputedKeys(old map[string]interface{}, new map[string]interface{})

if reflect.ValueOf(v).Kind() == reflect.Slice {
for i, j := range v.([]interface{}) {
if reflect.ValueOf(j).Kind() == reflect.Map {
if reflect.ValueOf(j).Kind() == reflect.Map && len(new[k].([]interface{})) > i {
old[k].([]interface{})[i] = removeComputedKeys(j.(map[string]interface{}), new[k].([]interface{})[i].(map[string]interface{}))
}
}
Expand Down
55 changes: 55 additions & 0 deletions google/services/monitoring/resource_monitoring_dashboard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,15 @@ func TestAccMonitoringDashboard_update(t *testing.T) {
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"project"},
},
{
Config: testAccMonitoringDashboard_gridLayoutUpdate(),
},
{
ResourceName: "google_monitoring_dashboard.dashboard",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"project"},
},
},
})
}
Expand Down Expand Up @@ -244,6 +253,52 @@ EOF
`)
}

func testAccMonitoringDashboard_gridLayoutUpdate() string {
return fmt.Sprintf(`
resource "google_monitoring_dashboard" "dashboard" {
dashboard_json = <<EOF
{
"displayName": "Grid Layout Example",
"gridLayout": {
"columns": "2",
"widgets": [
{
"title": "Widget 1",
"xyChart": {
"dataSets": [{
"timeSeriesQuery": {
"timeSeriesFilter": {
"filter": "metric.type=\"agent.googleapis.com/nginx/connections/accepted_count\"",
"aggregation": {
"perSeriesAligner": "ALIGN_RATE"
}
},
"unitOverride": "1"
},
"plotType": "LINE"
}],
"timeshiftDuration": "0s",
"yAxis": {
"label": "y1Axis",
"scale": "LINEAR"
}
}
},
{
"text": {
"content": "Widget 2",
"format": "MARKDOWN"
}
}
]
}
}
EOF
}
`)
}

func testAccMonitoringDashboard_rowLayout() string {
return fmt.Sprintf(`
resource "google_monitoring_dashboard" "dashboard" {
Expand Down

0 comments on commit 206fb3b

Please sign in to comment.