Skip to content

Commit

Permalink
subtitle (#183)
Browse files Browse the repository at this point in the history
  • Loading branch information
MisterSquishy authored Sep 14, 2023
1 parent 3e9a10d commit 70e249d
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .go-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.83.1
1.84.0
1 change: 1 addition & 0 deletions client/metric_dashboards.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type UnifiedChart struct {
YAxis *YAxis `json:"y-axis"`
MetricQueries []MetricQueryWithAttributes `json:"metric-queries"`
Text string `json:"text"`
Subtitle *string `json:"subtitle,omitempty"`
}

type Label struct {
Expand Down
2 changes: 2 additions & 0 deletions docs/resources/dashboard.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ Optional:

- `description` (String)
- `height` (Number)
- `subtitle` (String) Subtitle to show beneath big number, unused in other chart types
- `width` (Number)
- `x_pos` (Number)
- `y_axis` (Block List, Max: 1, Deprecated) (see [below for nested schema](#nestedblock--chart--y_axis))
Expand Down Expand Up @@ -180,6 +181,7 @@ Optional:

- `description` (String)
- `height` (Number)
- `subtitle` (String) Subtitle to show beneath big number, unused in other chart types
- `width` (Number)
- `x_pos` (Number)
- `y_axis` (Block List, Max: 1, Deprecated) (see [below for nested schema](#nestedblock--group--chart--y_axis))
Expand Down
2 changes: 2 additions & 0 deletions docs/resources/metric_dashboard.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ Optional:

- `description` (String)
- `height` (Number)
- `subtitle` (String) Subtitle to show beneath big number, unused in other chart types
- `width` (Number)
- `x_pos` (Number)
- `y_axis` (Block List, Max: 1, Deprecated) (see [below for nested schema](#nestedblock--chart--y_axis))
Expand Down Expand Up @@ -220,6 +221,7 @@ Optional:

- `description` (String)
- `height` (Number)
- `subtitle` (String) Subtitle to show beneath big number, unused in other chart types
- `width` (Number)
- `x_pos` (Number)
- `y_axis` (Block List, Max: 1, Deprecated) (see [below for nested schema](#nestedblock--group--chart--y_axis))
Expand Down
75 changes: 75 additions & 0 deletions lightstep/resource_dashboard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1324,3 +1324,78 @@ resource "lightstep_dashboard" "test_text_panels" {
},
})
}

func TestSubtitle(t *testing.T) {
var dashboard client.UnifiedDashboard

resourceName := "lightstep_dashboard.test_subtitle"

configTemplate := `
resource "lightstep_dashboard" "test_subtitle" {
project_name = "` + testProject + `"
dashboard_name = "test display_type_options"
group {
rank = 0
title = ""
visibility_type = "implicit"
chart {
name = "overall cpu utilization"
type = "timeseries"
rank = 0
x_pos = 4
y_pos = 0
width = 4
height = 4
%s
query {
query_name = "a"
display = "big_number"
hidden = false
query_string = "metric cpu.utilization | delta | group_by[], sum"
}
}
}
}
`

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testGetMetricDashboardDestroy,
Steps: []resource.TestStep{
{
// empty subtitle
Config: fmt.Sprintf(configTemplate, `subtitle = ""`),
Check: resource.ComposeTestCheckFunc(
testAccCheckMetricDashboardExists(resourceName, &dashboard),
resource.TestCheckResourceAttr(resourceName, "group.#", "1"),
resource.TestCheckResourceAttr(resourceName, "group.0.chart.#", "1"),
resource.TestCheckResourceAttr(resourceName, "group.0.chart.0.subtitle", ""),
),
},
{
// subtitle too long, this should be a chart-level description or something
Config: fmt.Sprintf(configTemplate, `subtitle = "this number represents the percentage of CPU cycles available to us that we have actually used"`),
Check: resource.ComposeTestCheckFunc(
testAccCheckMetricDashboardExists(resourceName, &dashboard),
resource.TestCheckResourceAttr(resourceName, "group.#", "1"),
resource.TestCheckResourceAttr(resourceName, "group.0.chart.#", "1"),
),
ExpectError: regexp.MustCompile("expected length of group.0.chart.0.subtitle to be in the range \\(0 - 37\\).*"),
},
{
// normal subtitle
Config: fmt.Sprintf(configTemplate, `subtitle = "percent"`),
Check: resource.ComposeTestCheckFunc(
testAccCheckMetricDashboardExists(resourceName, &dashboard),
resource.TestCheckResourceAttr(resourceName, "group.#", "1"),
resource.TestCheckResourceAttr(resourceName, "group.0.chart.#", "1"),
resource.TestCheckResourceAttr(resourceName, "group.0.chart.0.subtitle", "percent"),
),
},
},
})
}
15 changes: 15 additions & 0 deletions lightstep/resource_metric_dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,12 @@ func getChartSchema(chartSchemaType ChartSchemaType) map[string]*schema.Schema {
Schema: querySchema,
},
},
"subtitle": {
Type: schema.TypeString,
Description: "Subtitle to show beneath big number, unused in other chart types",
Optional: true,
ValidateFunc: validation.StringLenBetween(0, 37),
},
},
)
}
Expand Down Expand Up @@ -554,6 +560,11 @@ func buildCharts(chartsIn []interface{}) ([]client.UnifiedChart, error) {
c.YAxis = yaxis
}

if subtitle, hasSubtitle := chart["subtitle"]; hasSubtitle {
subtitleStr := subtitle.(string)
c.Subtitle = &subtitleStr
}

newCharts = append(newCharts, c)
}
return newCharts, nil
Expand Down Expand Up @@ -781,6 +792,10 @@ func assembleCharts(
}
}

if c.Subtitle != nil {
resource["subtitle"] = *c.Subtitle
}

if chartSchemaType == MetricChartSchema {
resource["query"] = getQueriesFromMetricConditionData(c.MetricQueries)
} else {
Expand Down

0 comments on commit 70e249d

Please sign in to comment.