Skip to content

Commit fdd38e3

Browse files
updating group_by at dashboard level (#979)
Co-authored-by: Maciej Wilk <mawilk@akamai.com>
1 parent 595faf9 commit fdd38e3

7 files changed

Lines changed: 301 additions & 206 deletions

monitor_dashboards.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ type MonitorDashboard struct {
1414
Type DashboardType `json:"type"`
1515
ServiceType ServiceType `json:"service_type"`
1616
Label string `json:"label"`
17+
GroupBy []string `json:"group_by"`
1718
Created *time.Time `json:"-"`
1819
Updated *time.Time `json:"-"`
1920
Widgets []DashboardWidget `json:"widgets"`

test/integration/fixtures/TestMonitorDashboards_Get.yaml

Lines changed: 264 additions & 148 deletions
Large diffs are not rendered by default.

test/integration/monitor_dashboards_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,15 @@ func validateDashboards(
7878
require.NotEmpty(t, dashboards.Created)
7979
require.NotEmpty(t, dashboards.Updated)
8080
require.NotEmpty(t, dashboards.Widgets)
81+
if dashboards.GroupBy != nil {
82+
require.NotEmpty(t, dashboards.GroupBy, "group_by should not be empty when present")
83+
}
8184

8285
// Validate group_by and filters for each widget
8386
for _, widget := range dashboards.Widgets {
84-
require.NotNil(t, widget.GroupBy, "Expected group_by to be present in widget")
87+
if widget.GroupBy != nil {
88+
require.NotEmpty(t, widget.GroupBy, "group_by should not be empty when present")
89+
}
8590
require.GreaterOrEqual(t, len(widget.GroupBy), 0, "group_by should be a slice (possibly empty)")
8691
// filters is optional
8792
if widget.Filters != nil {

test/unit/fixtures/monitor_dashboard_by_id.json

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"type": "standard",
44
"service_type": "dbaas",
55
"label": "Resource Usage",
6+
"group_by": ["entity_id"],
67
"created": "2024-11-05T01:13:34",
78
"updated": "2024-11-05T01:13:34",
89
"widgets": [
@@ -14,8 +15,7 @@
1415
"size": 12,
1516
"chart_type": "area",
1617
"y_label": "cpu_usage",
17-
"aggregate_function": "sum",
18-
"group_by": ["entity_id"]
18+
"aggregate_function": "avg"
1919
},
2020
{
2121
"metric": "memory_usage",
@@ -25,8 +25,7 @@
2525
"size": 6,
2626
"chart_type": "area",
2727
"y_label": "memory_usage",
28-
"aggregate_function": "sum",
29-
"group_by": ["entity_id"]
28+
"aggregate_function": "avg"
3029
},
3130
{
3231
"metric": "available_memory",
@@ -36,8 +35,7 @@
3635
"size": 6,
3736
"chart_type": "area",
3837
"y_label": "available_memory",
39-
"aggregate_function": "sum",
40-
"group_by": ["entity_id"]
38+
"aggregate_function": "avg"
4139
},
4240
{
4341
"metric": "disk_usage",
@@ -47,8 +45,7 @@
4745
"size": 6,
4846
"chart_type": "area",
4947
"y_label": "disk_usage",
50-
"aggregate_function": "sum",
51-
"group_by": ["entity_id"]
48+
"aggregate_function": "avg"
5249
},
5350
{
5451
"metric": "available_disk",
@@ -58,8 +55,7 @@
5855
"size": 6,
5956
"chart_type": "area",
6057
"y_label": "available_disk",
61-
"aggregate_function": "sum",
62-
"group_by": ["entity_id"]
58+
"aggregate_function": "avg"
6359
},
6460
{
6561
"metric": "read_iops",
@@ -69,8 +65,7 @@
6965
"size": 6,
7066
"chart_type": "area",
7167
"y_label": "read_iops",
72-
"aggregate_function": "sum",
73-
"group_by": ["entity_id"]
68+
"aggregate_function": "avg"
7469
},
7570
{
7671
"metric": "write_iops",
@@ -80,8 +75,7 @@
8075
"size": 6,
8176
"chart_type": "area",
8277
"y_label": "write_iops",
83-
"aggregate_function": "sum",
84-
"group_by": ["entity_id"]
78+
"aggregate_function": "avg"
8579
}
8680
]
8781
}

test/unit/fixtures/monitor_dashboard_by_service_type.json

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"type": "standard",
66
"service_type": "dbaas",
77
"label": "Resource Usage",
8+
"group_by": ["entity_id"],
89
"created": "2024-11-05T01:13:34",
910
"updated": "2024-11-05T01:13:34",
1011
"widgets": [
@@ -16,8 +17,7 @@
1617
"size": 12,
1718
"chart_type": "area",
1819
"y_label": "cpu_usage",
19-
"aggregate_function": "sum",
20-
"group_by": ["entity_id"]
20+
"aggregate_function": "avg"
2121
},
2222
{
2323
"metric": "memory_usage",
@@ -27,8 +27,7 @@
2727
"size": 6,
2828
"chart_type": "area",
2929
"y_label": "memory_usage",
30-
"aggregate_function": "sum",
31-
"group_by": ["entity_id"]
30+
"aggregate_function": "avg"
3231
},
3332
{
3433
"metric": "available_memory",
@@ -38,8 +37,7 @@
3837
"size": 6,
3938
"chart_type": "area",
4039
"y_label": "available_memory",
41-
"aggregate_function": "sum",
42-
"group_by": ["entity_id"]
40+
"aggregate_function": "avg"
4341
},
4442
{
4543
"metric": "disk_usage",
@@ -49,8 +47,7 @@
4947
"size": 6,
5048
"chart_type": "area",
5149
"y_label": "disk_usage",
52-
"aggregate_function": "sum",
53-
"group_by": ["entity_id"]
50+
"aggregate_function": "avg"
5451
},
5552
{
5653
"metric": "available_disk",
@@ -60,8 +57,7 @@
6057
"size": 6,
6158
"chart_type": "area",
6259
"y_label": "available_disk",
63-
"aggregate_function": "sum",
64-
"group_by": ["entity_id"]
60+
"aggregate_function": "avg"
6561
},
6662
{
6763
"metric": "read_iops",
@@ -71,8 +67,7 @@
7167
"size": 6,
7268
"chart_type": "area",
7369
"y_label": "read_iops",
74-
"aggregate_function": "sum",
75-
"group_by": ["entity_id"]
70+
"aggregate_function": "avg"
7671
},
7772
{
7873
"metric": "write_iops",
@@ -82,8 +77,7 @@
8277
"size": 6,
8378
"chart_type": "area",
8479
"y_label": "write_iops",
85-
"aggregate_function": "sum",
86-
"group_by": ["entity_id"]
80+
"aggregate_function": "avg"
8781
}
8882
]
8983
}

test/unit/fixtures/monitor_dashboards.json

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"type": "standard",
66
"service_type": "dbaas",
77
"label": "Resource Usage",
8+
"group_by": ["entity_id"],
89
"created": "2024-11-05T01:13:34",
910
"updated": "2024-11-05T01:13:34",
1011
"widgets": [
@@ -16,8 +17,7 @@
1617
"size": 12,
1718
"chart_type": "area",
1819
"y_label": "cpu_usage",
19-
"aggregate_function": "sum",
20-
"group_by": ["entity_id"]
20+
"aggregate_function": "avg"
2121
},
2222
{
2323
"metric": "memory_usage",
@@ -27,8 +27,7 @@
2727
"size": 6,
2828
"chart_type": "area",
2929
"y_label": "memory_usage",
30-
"aggregate_function": "sum",
31-
"group_by": ["entity_id"]
30+
"aggregate_function": "avg"
3231
},
3332
{
3433
"metric": "available_memory",
@@ -38,8 +37,7 @@
3837
"size": 6,
3938
"chart_type": "area",
4039
"y_label": "available_memory",
41-
"aggregate_function": "sum",
42-
"group_by": ["entity_id"]
40+
"aggregate_function": "avg"
4341
},
4442
{
4543
"metric": "disk_usage",
@@ -49,8 +47,7 @@
4947
"size": 6,
5048
"chart_type": "area",
5149
"y_label": "disk_usage",
52-
"aggregate_function": "sum",
53-
"group_by": ["entity_id"]
50+
"aggregate_function": "avg"
5451
},
5552
{
5653
"metric": "available_disk",
@@ -60,8 +57,7 @@
6057
"size": 6,
6158
"chart_type": "area",
6259
"y_label": "available_disk",
63-
"aggregate_function": "sum",
64-
"group_by": ["entity_id"]
60+
"aggregate_function": "avg"
6561
},
6662
{
6763
"metric": "read_iops",
@@ -71,8 +67,7 @@
7167
"size": 6,
7268
"chart_type": "area",
7369
"y_label": "read_iops",
74-
"aggregate_function": "sum",
75-
"group_by": ["entity_id"]
70+
"aggregate_function": "avg"
7671
},
7772
{
7873
"metric": "write_iops",
@@ -82,15 +77,7 @@
8277
"size": 6,
8378
"chart_type": "area",
8479
"y_label": "write_iops",
85-
"aggregate_function": "sum",
86-
"group_by": ["entity_id"],
87-
"filters": [
88-
{
89-
"dimension_label": "pattern",
90-
"operator": "in",
91-
"value": "publicout,privateout"
92-
}
93-
]
80+
"aggregate_function": "avg"
9481
}
9582
]
9683
}

test/unit/monitor_dashboards_test.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,8 @@ func TestListMonitorDashboards(t *testing.T) {
2727

2828
assert.Equal(t, linodego.DashboardType("standard"), clients[0].Type, "Expected dashboard type to match")
2929
assert.Equal(t, linodego.ServiceType("dbaas"), clients[0].ServiceType, "Expected service_type to match")
30-
31-
// Assert group_by field (on first widget)
32-
assert.NotNil(t, clients[0].Widgets[0].GroupBy, "Expected group_by to be present")
33-
assert.NotEmpty(t, clients[0].Widgets[0].GroupBy, "group_by should not be empty if present")
30+
assert.NotEmpty(t, clients[0].GroupBy, "Expected group_by to be present at dashboard level")
31+
assert.Equal(t, []string{"entity_id"}, clients[0].GroupBy, "Expected dashboard group_by to match")
3432

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

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

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

8080
assert.Equal(t, linodego.DashboardType("standard"), clients[0].Type, "Expected dashboard type to match")
8181
assert.Equal(t, linodego.ServiceType("dbaas"), clients[0].ServiceType, "Expected service_type to match")
82-
83-
// Assert group_by field (on first widget)
84-
assert.NotNil(t, clients[0].Widgets[0].GroupBy, "Expected group_by to be present")
85-
assert.NotEmpty(t, clients[0].Widgets[0].GroupBy, "group_by should not be empty if present")
82+
assert.NotEmpty(t, clients[0].GroupBy, "Expected group_by to be present at dashboard level")
83+
assert.Equal(t, []string{"entity_id"}, clients[0].GroupBy, "Expected dashboard group_by to match")
8684

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

0 commit comments

Comments
 (0)