Skip to content

Commit

Permalink
Improve types
Browse files Browse the repository at this point in the history
  • Loading branch information
tlindsay committed Sep 25, 2024
1 parent 41e266f commit 9e58597
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 21 deletions.
22 changes: 10 additions & 12 deletions fastly/observability_custom_dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type ObservabilityCustomDashboard struct {
// DashboardItem describes an item (or "widget") of a dashboard
type DashboardItem struct {
// DataSource describes the source of the metrics to be displayed (required)
DataSource DataSource `json:"data_source"`
DataSource DashboardDataSource `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)
Expand All @@ -50,38 +50,36 @@ type DashboardItem struct {
// 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"`
Visualization DashboardVisualization `json:"visualization"`
}

type SourceType string
type DashboardSourceType string

const (
SourceTypeStatsEdge = "stats.edge"
SourceTypeStatsDomain = "stats.domain"
SourceTypeStatsOrigin = "stats.origin"
)

// DataSource describes the data to display in a DashboardItem
type DataSource struct {
// DashboardDataSource describes the data to display in a DashboardItem
type DashboardDataSource struct {
// Config describes configuration options for the selected data source (required)
Config SourceConfig `json:"config"`
Config DashboardSourceConfig `json:"config"`
// Type is the source of the data to display (required)
Type SourceType `json:"type"`
Type DashboardSourceType `json:"type"`
}

type Metric string

type SourceConfig struct {
type DashboardSourceConfig struct {
// Metrics is the list metrics to visualize (required)
// Valid options are defined by the selected SourceType. See https://www.fastly.com/documentation/reference/api/observability/custom-dashboards/#data-source
Metrics []Metric `json:"metrics"`
Metrics []string `json:"metrics"`
}

type VisualizationType string

const VisualizationTypeChart VisualizationType = "chart"

type Visualization struct {
type DashboardVisualization struct {
// Config describes configuration options for the given visualization (required)
Config VisualizationConfig `json:"config"`
// Type is type of visualization to display. Currently only "chart" is supported (required)
Expand Down
18 changes: 9 additions & 9 deletions fastly/observability_custom_dashboard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ func TestClient_ObservabilityCustomDashboards(t *testing.T) {
Description: ToPointer("My dashboard is super cool."),
Name: "My Cool Dashboard",
Items: []DashboardItem{{
DataSource: DataSource{
Config: SourceConfig{
Metrics: []Metric{"requests"},
DataSource: DashboardDataSource{
Config: DashboardSourceConfig{
Metrics: []string{"requests"},
},
Type: SourceTypeStatsEdge,
},
Span: 4,
Subtitle: "This is a subtitle",
Title: "A Dashboard Item",
Visualization: Visualization{
Visualization: DashboardVisualization{
Config: VisualizationConfig{PlotType: PlotTypeLine},
Type: VisualizationTypeChart,
},
Expand Down Expand Up @@ -90,21 +90,21 @@ func TestClient_ObservabilityCustomDashboards(t *testing.T) {
// Update
var ucd *ObservabilityCustomDashboard
items := ocd.Items
items[0].DataSource.Config.Metrics = []Metric{"edge_hit_requests"}
items[0].DataSource.Config.Metrics = []string{"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"},
DataSource: DashboardDataSource{
Config: DashboardSourceConfig{
Metrics: []string{"requests"},
},
Type: SourceTypeStatsEdge,
},
Span: 4,
Subtitle: "This is a subtitle",
Title: "A New Dashboard Item",
Visualization: Visualization{
Visualization: DashboardVisualization{
Config: VisualizationConfig{PlotType: PlotTypeLine},
Type: VisualizationTypeChart,
},
Expand Down

0 comments on commit 9e58597

Please sign in to comment.