Skip to content

Commit c2a3614

Browse files
authored
feat(dashboards): configuring dashboard resource to accept min_interval (#469)
* feat: configuring dashboard resource to accept min_interval for promql min interval definition * feat: add unit tests, changing dashboardFrom function to receive minInterval * feat: remove default value for min_interval * fix: remove import for incomplete dashboards import * chore: add terraform.lock to .gitignore
1 parent 546f39e commit c2a3614

File tree

4 files changed

+51
-1
lines changed

4 files changed

+51
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
example.tf
77
terraform.tfplan
88
terraform.tfstate
9+
.terraform.lock.hcl
910
bin/
1011
modules-dev/
1112
/pkg/

sysdig/internal/client/v2/model_dashboard.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,7 @@ type Dashboard struct {
433433
CreatedOnDate string `json:"createdOnDate"`
434434
ModifiedOnDate string `json:"modifiedOnDate"`
435435
TeamSharingOptions TeamSharingOptions `json:"teamSharingOptions"`
436+
MinInterval string `json:"minInterval"`
436437
}
437438

438439
type dashboardWrapper struct {

sysdig/resource_sysdig_monitor_dashboard.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,10 @@ func resourceSysdigMonitorDashboard() *schema.Resource {
275275
Type: schema.TypeInt,
276276
Computed: true,
277277
},
278+
"min_interval": {
279+
Type: schema.TypeString,
280+
Optional: true,
281+
},
278282
},
279283
}
280284
}
@@ -388,6 +392,7 @@ func dashboardFromResourceData(data *schema.ResourceData) (dashboard *v2.Dashboa
388392
dashboard = v2.NewDashboard(data.Get("name").(string), data.Get("description").(string)).AsPublic(data.Get("public").(bool))
389393
dashboard.Version = cast.ToInt(data.Get("version"))
390394
dashboard.PublicToken = data.Get("public_token").(string)
395+
dashboard.MinInterval = data.Get("min_interval").(string)
391396

392397
panels, err := panelsFromResourceData(data)
393398
if err != nil {
@@ -407,7 +412,6 @@ func dashboardFromResourceData(data *schema.ResourceData) (dashboard *v2.Dashboa
407412
return nil, err
408413
}
409414
dashboard.SharingSettings = shares
410-
411415
return dashboard, nil
412416
}
413417

@@ -730,6 +734,7 @@ func dashboardToResourceData(dashboard *v2.Dashboard, data *schema.ResourceData)
730734
_ = data.Set("description", dashboard.Description)
731735
_ = data.Set("public", dashboard.Public)
732736
_ = data.Set("public_token", dashboard.PublicToken)
737+
_ = data.Set("min_interval", dashboard.MinInterval)
733738

734739
var panels []map[string]interface{}
735740
for i, panel := range dashboard.Panels {

sysdig/resource_sysdig_monitor_dashboard_test.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,12 @@ func TestAccDashboard(t *testing.T) {
323323
),
324324
),
325325
},
326+
{
327+
Config: minimumDashboardWithMinInterval(rText(), "70s"), // Assuming this function returns the desired Terraform config
328+
Check: resource.ComposeTestCheckFunc(
329+
resource.TestCheckResourceAttr("sysdig_monitor_dashboard.dashboard", "min_interval", "70s"),
330+
),
331+
},
326332
},
327333
})
328334
}
@@ -396,6 +402,43 @@ resource "sysdig_monitor_dashboard" "dashboard_2" {
396402
`, name, name)
397403
}
398404

405+
func minimumDashboardWithMinInterval(name string, minInterval string) string {
406+
return fmt.Sprintf(`
407+
resource "sysdig_monitor_dashboard" "dashboard" {
408+
name = "TERRAFORM TEST - METRIC %s"
409+
description = "TERRAFORM TEST - METRIC %s"
410+
min_interval = "%s"
411+
panel {
412+
pos_x = 0
413+
pos_y = 0
414+
width = 12 # Maximum size: 24
415+
height = 6
416+
type = "timechart"
417+
name = "example panel"
418+
description = "description"
419+
420+
legend {
421+
show_current = true
422+
position = "bottom"
423+
layout = "inline"
424+
}
425+
426+
query {
427+
promql = "avg(avg_over_time(sysdig_host_cpu_used_percent[$__interval]))"
428+
unit = "percent"
429+
430+
format {
431+
display_format = "auto"
432+
input_format = "0-100"
433+
y_axis = "auto"
434+
null_value_display_mode = "nullGap"
435+
}
436+
}
437+
}
438+
}
439+
`, name, name, minInterval)
440+
}
441+
399442
func multiplePanelsDashboard(name string) string {
400443
return fmt.Sprintf(`
401444
resource "sysdig_monitor_dashboard" "dashboard" {

0 commit comments

Comments
 (0)