Skip to content
Draft
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
1 change: 1 addition & 0 deletions monitor_dashboards.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type MonitorDashboard struct {
Type DashboardType `json:"type"`
ServiceType ServiceType `json:"service_type"`
Label string `json:"label"`
GroupBy []string `json:"group_by"`
Created *time.Time `json:"-"`
Updated *time.Time `json:"-"`
Widgets []DashboardWidget `json:"widgets"`
Expand Down
412 changes: 264 additions & 148 deletions test/integration/fixtures/TestMonitorDashboards_Get.yaml

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion test/integration/monitor_dashboards_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,15 @@ func validateDashboards(
require.NotEmpty(t, dashboards.Created)
require.NotEmpty(t, dashboards.Updated)
require.NotEmpty(t, dashboards.Widgets)
if dashboards.GroupBy != nil {
require.NotEmpty(t, dashboards.GroupBy, "group_by should not be empty when present")
}

// Validate group_by and filters for each widget
for _, widget := range dashboards.Widgets {
require.NotNil(t, widget.GroupBy, "Expected group_by to be present in widget")
if widget.GroupBy != nil {
require.NotEmpty(t, widget.GroupBy, "group_by should not be empty when present")
}
require.GreaterOrEqual(t, len(widget.GroupBy), 0, "group_by should be a slice (possibly empty)")
// filters is optional
if widget.Filters != nil {
Expand Down
22 changes: 8 additions & 14 deletions test/unit/fixtures/monitor_dashboard_by_id.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"type": "standard",
"service_type": "dbaas",
"label": "Resource Usage",
"group_by": ["entity_id"],
"created": "2024-11-05T01:13:34",
"updated": "2024-11-05T01:13:34",
"widgets": [
Expand All @@ -14,8 +15,7 @@
"size": 12,
"chart_type": "area",
"y_label": "cpu_usage",
"aggregate_function": "sum",
"group_by": ["entity_id"]
"aggregate_function": "avg"
},
{
"metric": "memory_usage",
Expand All @@ -25,8 +25,7 @@
"size": 6,
"chart_type": "area",
"y_label": "memory_usage",
"aggregate_function": "sum",
"group_by": ["entity_id"]
"aggregate_function": "avg"
},
{
"metric": "available_memory",
Expand All @@ -36,8 +35,7 @@
"size": 6,
"chart_type": "area",
"y_label": "available_memory",
"aggregate_function": "sum",
"group_by": ["entity_id"]
"aggregate_function": "avg"
},
{
"metric": "disk_usage",
Expand All @@ -47,8 +45,7 @@
"size": 6,
"chart_type": "area",
"y_label": "disk_usage",
"aggregate_function": "sum",
"group_by": ["entity_id"]
"aggregate_function": "avg"
},
{
"metric": "available_disk",
Expand All @@ -58,8 +55,7 @@
"size": 6,
"chart_type": "area",
"y_label": "available_disk",
"aggregate_function": "sum",
"group_by": ["entity_id"]
"aggregate_function": "avg"
},
{
"metric": "read_iops",
Expand All @@ -69,8 +65,7 @@
"size": 6,
"chart_type": "area",
"y_label": "read_iops",
"aggregate_function": "sum",
"group_by": ["entity_id"]
"aggregate_function": "avg"
},
{
"metric": "write_iops",
Expand All @@ -80,8 +75,7 @@
"size": 6,
"chart_type": "area",
"y_label": "write_iops",
"aggregate_function": "sum",
"group_by": ["entity_id"]
"aggregate_function": "avg"
}
]
}
22 changes: 8 additions & 14 deletions test/unit/fixtures/monitor_dashboard_by_service_type.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"type": "standard",
"service_type": "dbaas",
"label": "Resource Usage",
"group_by": ["entity_id"],
"created": "2024-11-05T01:13:34",
"updated": "2024-11-05T01:13:34",
"widgets": [
Expand All @@ -16,8 +17,7 @@
"size": 12,
"chart_type": "area",
"y_label": "cpu_usage",
"aggregate_function": "sum",
"group_by": ["entity_id"]
"aggregate_function": "avg"
},
{
"metric": "memory_usage",
Expand All @@ -27,8 +27,7 @@
"size": 6,
"chart_type": "area",
"y_label": "memory_usage",
"aggregate_function": "sum",
"group_by": ["entity_id"]
"aggregate_function": "avg"
},
{
"metric": "available_memory",
Expand All @@ -38,8 +37,7 @@
"size": 6,
"chart_type": "area",
"y_label": "available_memory",
"aggregate_function": "sum",
"group_by": ["entity_id"]
"aggregate_function": "avg"
},
{
"metric": "disk_usage",
Expand All @@ -49,8 +47,7 @@
"size": 6,
"chart_type": "area",
"y_label": "disk_usage",
"aggregate_function": "sum",
"group_by": ["entity_id"]
"aggregate_function": "avg"
},
{
"metric": "available_disk",
Expand All @@ -60,8 +57,7 @@
"size": 6,
"chart_type": "area",
"y_label": "available_disk",
"aggregate_function": "sum",
"group_by": ["entity_id"]
"aggregate_function": "avg"
},
{
"metric": "read_iops",
Expand All @@ -71,8 +67,7 @@
"size": 6,
"chart_type": "area",
"y_label": "read_iops",
"aggregate_function": "sum",
"group_by": ["entity_id"]
"aggregate_function": "avg"
},
{
"metric": "write_iops",
Expand All @@ -82,8 +77,7 @@
"size": 6,
"chart_type": "area",
"y_label": "write_iops",
"aggregate_function": "sum",
"group_by": ["entity_id"]
"aggregate_function": "avg"
}
]
}
Expand Down
29 changes: 8 additions & 21 deletions test/unit/fixtures/monitor_dashboards.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"type": "standard",
"service_type": "dbaas",
"label": "Resource Usage",
"group_by": ["entity_id"],
"created": "2024-11-05T01:13:34",
"updated": "2024-11-05T01:13:34",
"widgets": [
Expand All @@ -16,8 +17,7 @@
"size": 12,
"chart_type": "area",
"y_label": "cpu_usage",
"aggregate_function": "sum",
"group_by": ["entity_id"]
"aggregate_function": "avg"
},
{
"metric": "memory_usage",
Expand All @@ -27,8 +27,7 @@
"size": 6,
"chart_type": "area",
"y_label": "memory_usage",
"aggregate_function": "sum",
"group_by": ["entity_id"]
"aggregate_function": "avg"
},
{
"metric": "available_memory",
Expand All @@ -38,8 +37,7 @@
"size": 6,
"chart_type": "area",
"y_label": "available_memory",
"aggregate_function": "sum",
"group_by": ["entity_id"]
"aggregate_function": "avg"
},
{
"metric": "disk_usage",
Expand All @@ -49,8 +47,7 @@
"size": 6,
"chart_type": "area",
"y_label": "disk_usage",
"aggregate_function": "sum",
"group_by": ["entity_id"]
"aggregate_function": "avg"
},
{
"metric": "available_disk",
Expand All @@ -60,8 +57,7 @@
"size": 6,
"chart_type": "area",
"y_label": "available_disk",
"aggregate_function": "sum",
"group_by": ["entity_id"]
"aggregate_function": "avg"
},
{
"metric": "read_iops",
Expand All @@ -71,8 +67,7 @@
"size": 6,
"chart_type": "area",
"y_label": "read_iops",
"aggregate_function": "sum",
"group_by": ["entity_id"]
"aggregate_function": "avg"
},
{
"metric": "write_iops",
Expand All @@ -82,15 +77,7 @@
"size": 6,
"chart_type": "area",
"y_label": "write_iops",
"aggregate_function": "sum",
"group_by": ["entity_id"],
"filters": [
{
"dimension_label": "pattern",
"operator": "in",
"value": "publicout,privateout"
}
]
"aggregate_function": "avg"
}
]
}
Expand Down
14 changes: 6 additions & 8 deletions test/unit/monitor_dashboards_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@ func TestListMonitorDashboards(t *testing.T) {

assert.Equal(t, linodego.DashboardType("standard"), clients[0].Type, "Expected dashboard type to match")
assert.Equal(t, linodego.ServiceType("dbaas"), clients[0].ServiceType, "Expected service_type to match")

// Assert group_by field (on first widget)
assert.NotNil(t, clients[0].Widgets[0].GroupBy, "Expected group_by to be present")
assert.NotEmpty(t, clients[0].Widgets[0].GroupBy, "group_by should not be empty if present")
assert.NotEmpty(t, clients[0].GroupBy, "Expected group_by to be present at dashboard level")
assert.Equal(t, []string{"entity_id"}, clients[0].GroupBy, "Expected dashboard group_by to match")

// Assert filters field (optional, on first widget)
if clients[0].Widgets[0].Filters != nil {
Expand All @@ -57,6 +55,8 @@ func TestListMonitorDashboardsByID(t *testing.T) {

assert.Equal(t, linodego.DashboardType("standard"), clients.Type, "Expected dashboard type to match")
assert.Equal(t, linodego.ServiceType("dbaas"), clients.ServiceType, "Expected service_type to match")
assert.NotEmpty(t, clients.GroupBy, "Expected group_by to be present at dashboard level")
assert.Equal(t, []string{"entity_id"}, clients.GroupBy, "Expected dashboard group_by to match")
}

// monitor_dashboard_by_service_type
Expand All @@ -79,10 +79,8 @@ func TestListMonitorDashboardsByServiceType(t *testing.T) {

assert.Equal(t, linodego.DashboardType("standard"), clients[0].Type, "Expected dashboard type to match")
assert.Equal(t, linodego.ServiceType("dbaas"), clients[0].ServiceType, "Expected service_type to match")

// Assert group_by field (on first widget)
assert.NotNil(t, clients[0].Widgets[0].GroupBy, "Expected group_by to be present")
assert.NotEmpty(t, clients[0].Widgets[0].GroupBy, "group_by should not be empty if present")
assert.NotEmpty(t, clients[0].GroupBy, "Expected group_by to be present at dashboard level")
assert.Equal(t, []string{"entity_id"}, clients[0].GroupBy, "Expected dashboard group_by to match")

// Assert filters field (optional, on first widget)
if clients[0].Widgets[0].Filters != nil {
Expand Down