Skip to content

Commit

Permalink
Drop unnecessary InputDashboardItem type and improve dashboard update…
Browse files Browse the repository at this point in the history
… test
  • Loading branch information
tlindsay committed Sep 16, 2024
1 parent 0b7148d commit 13c5804
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
version: 1
interactions:
- request:
body: '{"description":"My dashboard is super cool.","items":[],"name":"My Cool
Dashboard"}'
body: '{"description":"My dashboard is super cool.","items":[{"data_source":{"config":{"metrics":["requests"]},"type":"stats.edge"},"span":4,"subtitle":"This
is a subtitle","title":"A Dashboard Item","visualization":{"config":{"plot_type":"line"},"type":"chart"}}],"name":"My
Cool Dashboard"}'
form: {}
headers:
Accept:
Expand All @@ -15,19 +16,20 @@ interactions:
url: https://api.fastly.com/observability/dashboards
method: POST
response:
body: '{"id":"2i2SYSBHe4ktahuorJrn8P","name":"My Cool Dashboard","description":"My
dashboard is super cool.","items":[],"created_at":"2024-09-13T21:08:15Z","updated_at":"2024-09-13T21:08:15Z","created_by":"7Y26Rzri7e1Jp2feVbkX8H","updated_by":"7Y26Rzri7e1Jp2feVbkX8H"}'
body: '{"id":"4d8YrSYlEVN7O9q55PTROf","name":"My Cool Dashboard","description":"My
dashboard is super cool.","items":[{"id":"4Ntbw0nSnAOre49gUjzpE8","span":4,"title":"A
Dashboard Item","subtitle":"This is a subtitle","data_source":{"type":"stats.edge","config":{"metrics":["requests"]}},"visualization":{"type":"chart","config":{"plot_type":"line"}}}],"created_at":"2024-09-16T18:50:27Z","updated_at":"2024-09-16T18:50:27Z","created_by":"7Y26Rzri7e1Jp2feVbkX8H","updated_by":"7Y26Rzri7e1Jp2feVbkX8H"}'
headers:
Accept-Ranges:
- bytes
Cache-Control:
- no-store
Content-Length:
- "261"
- "493"
Content-Type:
- application/json
Date:
- Fri, 13 Sep 2024 21:08:15 GMT
- Mon, 16 Sep 2024 18:50:27 GMT
Pragma:
- no-cache
Server:
Expand All @@ -45,9 +47,9 @@ interactions:
X-Cache-Hits:
- 0, 0
X-Served-By:
- cache-chi-klot8100135-CHI, cache-pdk-katl1840061-PDK
- cache-chi-klot8100135-CHI, cache-pdk-kpdk1780083-PDK
X-Timer:
- S1726261696.923679,VS0,VE68
- S1726512628.902944,VS0,VE79
status: 201 Created
code: 201
duration: ""
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ interactions:
headers:
User-Agent:
- FastlyGo/9.8.0 (+github.com/fastly/go-fastly; go1.23.0)
url: https://api.fastly.com/observability/dashboards/2i2SYSBHe4ktahuorJrn8P
url: https://api.fastly.com/observability/dashboards/4d8YrSYlEVN7O9q55PTROf
method: DELETE
response:
body: ""
Expand All @@ -19,7 +19,7 @@ interactions:
Content-Type:
- application/json
Date:
- Fri, 13 Sep 2024 21:08:16 GMT
- Mon, 16 Sep 2024 18:50:28 GMT
Pragma:
- no-cache
Server:
Expand All @@ -37,9 +37,9 @@ interactions:
X-Cache-Hits:
- 0, 0
X-Served-By:
- cache-chi-klot8100114-CHI, cache-pdk-katl1840061-PDK
- cache-chi-klot8100140-CHI, cache-pdk-kpdk1780083-PDK
X-Timer:
- S1726261696.240009,VS0,VE68
- S1726512628.228117,VS0,VE65
status: 204 No Content
code: 204
duration: ""
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,23 @@ interactions:
headers:
User-Agent:
- FastlyGo/9.8.0 (+github.com/fastly/go-fastly; go1.23.0)
url: https://api.fastly.com/observability/dashboards/2i2SYSBHe4ktahuorJrn8P
url: https://api.fastly.com/observability/dashboards/4d8YrSYlEVN7O9q55PTROf
method: GET
response:
body: '{"id":"2i2SYSBHe4ktahuorJrn8P","name":"My Cool Dashboard","description":"My
dashboard is super cool.","items":[],"created_at":"2024-09-13T21:08:15Z","updated_at":"2024-09-13T21:08:15Z","created_by":"7Y26Rzri7e1Jp2feVbkX8H","updated_by":"7Y26Rzri7e1Jp2feVbkX8H"}'
body: '{"id":"4d8YrSYlEVN7O9q55PTROf","name":"My Cool Dashboard","description":"My
dashboard is super cool.","items":[{"id":"4Ntbw0nSnAOre49gUjzpE8","span":4,"title":"A
Dashboard Item","subtitle":"This is a subtitle","data_source":{"type":"stats.edge","config":{"metrics":["requests"]}},"visualization":{"type":"chart","config":{"plot_type":"line"}}}],"created_at":"2024-09-16T18:50:27Z","updated_at":"2024-09-16T18:50:27Z","created_by":"7Y26Rzri7e1Jp2feVbkX8H","updated_by":"7Y26Rzri7e1Jp2feVbkX8H"}'
headers:
Accept-Ranges:
- bytes
Cache-Control:
- no-store
Content-Length:
- "261"
- "493"
Content-Type:
- application/json
Date:
- Fri, 13 Sep 2024 21:08:16 GMT
- Mon, 16 Sep 2024 18:50:28 GMT
Pragma:
- no-cache
Server:
Expand All @@ -40,9 +41,9 @@ interactions:
X-Cache-Hits:
- 0, 0
X-Served-By:
- cache-chi-klot8100114-CHI, cache-pdk-katl1840061-PDK
- cache-chi-klot8100140-CHI, cache-pdk-kpdk1780083-PDK
X-Timer:
- S1726261696.086195,VS0,VE55
- S1726512628.073431,VS0,VE53
status: 200 OK
code: 200
duration: ""
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ interactions:
5xx","subtitle":"blue is \"compute\", green is not???","data_source":{"type":"stats.edge","config":{"metrics":["compute_resp_status_5xx","status_5xx"]}},"visualization":{"type":"chart","config":{"plot_type":"line"}}}],"created_at":"2023-11-06T22:37:48Z","updated_at":"2023-11-06T22:50:37Z","created_by":"","updated_by":""},{"id":"12rbGpXjMQOMJwUZj0FVf2","name":"fasdf","description":"","items":[{"id":"4OD1b3psvtQ8EPOR5k3KmC","span":4,"title":"fdsaf","subtitle":"sadf","data_source":{"type":"stats.edge","config":{"metrics":["requests"]}},"visualization":{"type":"chart","config":{"plot_type":"line"}}}],"created_at":"2023-05-02T14:32:15Z","updated_at":"2023-05-02T16:59:36Z","created_by":"","updated_by":""},{"id":"4uqEmZo4PdgX2EUWxoGLjN","name":"Just
checking POST headers","description":"","items":[],"created_at":"2024-07-09T18:18:01Z","updated_at":"2024-07-09T18:18:01Z","created_by":"6aqLztR9TLUCE2z3AloYbt","updated_by":"6aqLztR9TLUCE2z3AloYbt"},{"id":"UUP04HJC6BWlHGREbUt1R","name":"My
Cool Dashboard","description":"My dashboard is super cool.","items":[],"created_at":"2024-07-22T19:53:51Z","updated_at":"2024-07-22T19:53:51Z","created_by":"7Y26Rzri7e1Jp2feVbkX8H","updated_by":"7Y26Rzri7e1Jp2feVbkX8H"},{"id":"28AuseY7yJonnqDeXozmrJ","name":"My
Cool Dashboard","description":"My dashboard is super cool.","items":[],"created_at":"2024-07-22T19:54:58Z","updated_at":"2024-07-22T19:54:58Z","created_by":"7Y26Rzri7e1Jp2feVbkX8H","updated_by":"7Y26Rzri7e1Jp2feVbkX8H"},{"id":"2i2SYSBHe4ktahuorJrn8P","name":"My
Cool Dashboard","description":"My dashboard is super cool.","items":[],"created_at":"2024-09-13T21:08:15Z","updated_at":"2024-09-13T21:08:15Z","created_by":"7Y26Rzri7e1Jp2feVbkX8H","updated_by":"7Y26Rzri7e1Jp2feVbkX8H"},{"id":"4vSKQ9rVoUlHNvl3gUbz0z","name":"my
Cool Dashboard","description":"My dashboard is super cool.","items":[],"created_at":"2024-07-22T19:54:58Z","updated_at":"2024-07-22T19:54:58Z","created_by":"7Y26Rzri7e1Jp2feVbkX8H","updated_by":"7Y26Rzri7e1Jp2feVbkX8H"},{"id":"4d8YrSYlEVN7O9q55PTROf","name":"My
Cool Dashboard","description":"My dashboard is super cool.","items":[{"id":"4Ntbw0nSnAOre49gUjzpE8","span":4,"title":"A
Dashboard Item","subtitle":"This is a subtitle","data_source":{"type":"stats.edge","config":{"metrics":["requests"]}},"visualization":{"type":"chart","config":{"plot_type":"line"}}}],"created_at":"2024-09-16T18:50:27Z","updated_at":"2024-09-16T18:50:27Z","created_by":"7Y26Rzri7e1Jp2feVbkX8H","updated_by":"7Y26Rzri7e1Jp2feVbkX8H"},{"id":"4vSKQ9rVoUlHNvl3gUbz0z","name":"my
impersonated dashboard!","description":"","items":[],"created_at":"2024-06-27T22:21:20Z","updated_at":"2024-06-27T22:21:20Z","created_by":"6aqLztR9TLUCE2z3AloYbt","updated_by":"6aqLztR9TLUCE2z3AloYbt"},{"id":"5OGhkA3Y84dgPWjInl9uF9","name":"My
new impersonation dashboard","description":"","items":[{"id":"ElNimE7Iymes5v96eAkil","span":12,"title":"This
is a chart","subtitle":"subtitle...","data_source":{"type":"stats.edge","config":{"metrics":["requests"]}},"visualization":{"type":"chart","config":{"plot_type":"bar"}}}],"created_at":"2024-07-22T19:51:11Z","updated_at":"2024-07-22T19:51:11Z","created_by":"7Y26Rzri7e1Jp2feVbkX8H","updated_by":"7Y26Rzri7e1Jp2feVbkX8H"},{"id":"6kgqXM7F3tWgdCyhFbp9ZB","name":"My
Expand All @@ -34,7 +35,7 @@ interactions:
Content-Type:
- application/json
Date:
- Fri, 13 Sep 2024 21:08:16 GMT
- Mon, 16 Sep 2024 18:50:28 GMT
Pragma:
- no-cache
Server:
Expand All @@ -52,9 +53,9 @@ interactions:
X-Cache-Hits:
- 0, 0
X-Served-By:
- cache-chi-klot8100135-CHI, cache-pdk-katl1840061-PDK
- cache-chi-klot8100135-CHI, cache-pdk-kpdk1780083-PDK
X-Timer:
- S1726261696.005339,VS0,VE64
- S1726512628.995377,VS0,VE62
status: 200 OK
code: 200
duration: ""
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
version: 1
interactions:
- request:
body: '{"description":"My dashboard just got even cooler.","items":[{"data_source":{"config":{"metrics":["requests"]},"type":"stats.edge"},"span":4,"subtitle":"This
is a subtitle","title":"A Dashboard Item","visualization":{"config":{"plot_type":"line"},"type":"chart"}}],"name":"My
body: '{"description":"My dashboard just got even cooler.","items":[{"data_source":{"config":{"metrics":["edge_hit_requests"]},"type":"stats.edge"},"id":"4Ntbw0nSnAOre49gUjzpE8","span":4,"subtitle":"This
is a subtitle","title":"An Updated Dashboard Item","visualization":{"config":{"plot_type":"single-metric"},"type":"chart"}},{"data_source":{"config":{"metrics":["requests"]},"type":"stats.edge"},"span":4,"subtitle":"This
is a subtitle","title":"A New Dashboard Item","visualization":{"config":{"plot_type":"line"},"type":"chart"}}],"name":"My
Updated Dashboard"}'
form: {}
headers:
Expand All @@ -13,23 +14,24 @@ interactions:
- application/json
User-Agent:
- FastlyGo/9.8.0 (+github.com/fastly/go-fastly; go1.23.0)
url: https://api.fastly.com/observability/dashboards/2i2SYSBHe4ktahuorJrn8P
url: https://api.fastly.com/observability/dashboards/4d8YrSYlEVN7O9q55PTROf
method: PATCH
response:
body: '{"id":"2i2SYSBHe4ktahuorJrn8P","name":"My Updated Dashboard","description":"My
dashboard just got even cooler.","items":[{"id":"6bWq84DyDKEm2I6xlZxNQ2","span":4,"title":"A
Dashboard Item","subtitle":"This is a subtitle","data_source":{"type":"stats.edge","config":{"metrics":["requests"]}},"visualization":{"type":"chart","config":{"plot_type":"line"}}}],"created_at":"2024-09-13T21:08:15Z","updated_at":"2024-09-13T21:08:16Z","created_by":"7Y26Rzri7e1Jp2feVbkX8H","updated_by":"7Y26Rzri7e1Jp2feVbkX8H"}'
body: '{"id":"4d8YrSYlEVN7O9q55PTROf","name":"My Updated Dashboard","description":"My
dashboard just got even cooler.","items":[{"id":"4Ntbw0nSnAOre49gUjzpE8","span":4,"title":"An
Updated Dashboard Item","subtitle":"This is a subtitle","data_source":{"type":"stats.edge","config":{"metrics":["edge_hit_requests"]}},"visualization":{"type":"chart","config":{"plot_type":"single-metric"}}},{"id":"2u2k23O7s7RHwHaPHbW1Pg","span":4,"title":"A
New Dashboard Item","subtitle":"This is a subtitle","data_source":{"type":"stats.edge","config":{"metrics":["requests"]}},"visualization":{"type":"chart","config":{"plot_type":"line"}}}],"created_at":"2024-09-16T18:50:27Z","updated_at":"2024-09-16T18:50:28Z","created_by":"7Y26Rzri7e1Jp2feVbkX8H","updated_by":"7Y26Rzri7e1Jp2feVbkX8H"}'
headers:
Accept-Ranges:
- bytes
Cache-Control:
- no-store
Content-Length:
- "503"
- "767"
Content-Type:
- application/json
Date:
- Fri, 13 Sep 2024 21:08:16 GMT
- Mon, 16 Sep 2024 18:50:28 GMT
Pragma:
- no-cache
Server:
Expand All @@ -47,9 +49,9 @@ interactions:
X-Cache-Hits:
- 0, 0
X-Served-By:
- cache-chi-klot8100114-CHI, cache-pdk-katl1840061-PDK
- cache-chi-klot8100140-CHI, cache-pdk-kpdk1780083-PDK
X-Timer:
- S1726261696.156023,VS0,VE70
- S1726512628.140121,VS0,VE73
status: 200 OK
code: 200
duration: ""
27 changes: 6 additions & 21 deletions fastly/observability_custom_dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,25 +207,10 @@ func (c *Client) ListObservabilityCustomDashboards(i *ListObservabilityCustomDas
return ldr, nil
}

type InputDashboardItem struct {
// DataSource describes the source of the metrics to be displayed (required).
DataSource DataSource `json:"data_source"`
// ID is a unique identifier for the DashboardItem (read-only).
ID *string `json:"id,omitempty"`
// Span is the number of columns (1-12) for the DashboardItem to span (default: 4).
Span uint8 `json:"span"`
// Subtitle is a human-readable subtitle to display, often a description of the visualization (optional).
Subtitle string `json:"subtitle"`
// Title is a human-readable title to display (optional).
Title string `json:"title"`
// Visualization describes the way the DashboardItem should display data (required).
Visualization Visualization `json:"visualization"`
}

type CreateObservabilityCustomDashboardInput struct {
Description *string `json:"description,omitempty"`
Items []InputDashboardItem `json:"items"`
Name string `json:"name"`
Description *string `json:"description,omitempty"`
Items []DashboardItem `json:"items"`
Name string `json:"name"`
}

func (c *Client) CreateObservabilityCustomDashboard(i *CreateObservabilityCustomDashboardInput) (*ObservabilityCustomDashboard, error) {
Expand Down Expand Up @@ -270,9 +255,9 @@ func (c *Client) GetObservabilityCustomDashboard(i *GetObservabilityCustomDashbo
type UpdateObservabilityCustomDashboardInput struct {
Description *string `json:"description,omitempty"`
// ID of the dashboard to fetch (required).
ID *string `json:"-"`
Items *[]InputDashboardItem `json:"items,omitempty"`
Name *string `json:"name,omitempty"`
ID *string `json:"-"`
Items *[]DashboardItem `json:"items,omitempty"`
Name *string `json:"name,omitempty"`
}

func (c *Client) UpdateObservabilityCustomDashboard(i *UpdateObservabilityCustomDashboardInput) (*ObservabilityCustomDashboard, error) {
Expand Down
67 changes: 48 additions & 19 deletions fastly/observability_custom_dashboard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package fastly

import (
"testing"

"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
)

func TestClient_ObservabilityCustomDashboards(t *testing.T) {
Expand All @@ -10,7 +13,21 @@ func TestClient_ObservabilityCustomDashboards(t *testing.T) {
cocd := &CreateObservabilityCustomDashboardInput{
Description: ToPointer("My dashboard is super cool."),
Name: "My Cool Dashboard",
Items: []InputDashboardItem{},
Items: []DashboardItem{{
DataSource: DataSource{
Config: SourceConfig{
Metrics: []Metric{"requests"},
},
Type: SourceTypeStatsEdge,
},
Span: 4,
Subtitle: "This is a subtitle",
Title: "A Dashboard Item",
Visualization: Visualization{
Config: VisualizationConfig{PlotType: PlotTypeLine},
Type: VisualizationTypeChart,
},
}},
}

var err error
Expand Down Expand Up @@ -40,7 +57,7 @@ func TestClient_ObservabilityCustomDashboards(t *testing.T) {
t.Errorf("bad name. want: %s, got %s", cocd.Name, ocd.Name)
}

if len(ocd.Items) != 0 {
if len(ocd.Items) != 1 {
t.Errorf("bad items: %v", ocd.Items)
}

Expand Down Expand Up @@ -72,26 +89,32 @@ func TestClient_ObservabilityCustomDashboards(t *testing.T) {

// Update
var ucd *ObservabilityCustomDashboard
items := ocd.Items
items[0].DataSource.Config.Metrics = []Metric{"edge_hit_requests"}
items[0].Visualization.Config.PlotType = PlotTypeSingleMetric
items[0].Title = "An Updated Dashboard Item"

items = append(items, DashboardItem{
DataSource: DataSource{
Config: SourceConfig{
Metrics: []Metric{"requests"},
},
Type: SourceTypeStatsEdge,
},
Span: 4,
Subtitle: "This is a subtitle",
Title: "A New Dashboard Item",
Visualization: Visualization{
Config: VisualizationConfig{PlotType: PlotTypeLine},
Type: VisualizationTypeChart,
},
})
record(t, "observability_custom_dashboards/update_custom_dashboard", func(c *Client) {
ucd, err = c.UpdateObservabilityCustomDashboard(&UpdateObservabilityCustomDashboardInput{
Description: ToPointer("My dashboard just got even cooler."),
ID: &ocd.ID,
Items: &[]InputDashboardItem{{
DataSource: DataSource{
Config: SourceConfig{
Metrics: []Metric{"requests"},
},
Type: SourceTypeStatsEdge,
},
Span: 4,
Subtitle: "This is a subtitle",
Title: "A Dashboard Item",
Visualization: Visualization{
Config: VisualizationConfig{PlotType: PlotTypeLine},
Type: VisualizationTypeChart,
},
}},
Name: ToPointer("My Updated Dashboard"),
Items: &items,
Name: ToPointer("My Updated Dashboard"),
})
})
if err != nil {
Expand All @@ -100,7 +123,13 @@ func TestClient_ObservabilityCustomDashboards(t *testing.T) {
if ucd.Name != "My Updated Dashboard" {
t.Errorf("bad name: %q (%q)", "My Updated Dashboard", ucd.Name)
}
if len(ucd.Items) != 1 {
if len(ucd.Items) != 2 {
t.Errorf("bad items")
}
if diff := cmp.Diff(items[0], ucd.Items[0]); diff != "" {
t.Errorf("dashboard item did not match (-want,+got): %s", diff)
}
if diff := cmp.Diff(items[1], ucd.Items[1], cmpopts.IgnoreFields(DashboardItem{}, "ID")); diff != "" {
t.Errorf("dashboard item did not match (-want,+got): %s", diff)
}
}

0 comments on commit 13c5804

Please sign in to comment.