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 the out of boundary error #16792

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
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