Skip to content

Commit 446caea

Browse files
authored
Simplify dashboard layout (#57)
1 parent b677aee commit 446caea

File tree

15 files changed

+1364
-418
lines changed

15 files changed

+1364
-418
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ data "gdashboard_dashboard" "dashboard" {
4747
title = "My dashboard"
4848
4949
layout {
50-
row {
50+
section {
51+
title = "Basic Details"
52+
5153
panel {
5254
size = {
5355
height = 8

docs/data-sources/dashboard.md

Lines changed: 145 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
---
2-
# generated by https://github.com/hashicorp/terraform-plugin-docs
32
page_title: "gdashboard_dashboard Data Source - terraform-provider-gdashboard"
43
subcategory: ""
54
description: |-
@@ -24,6 +23,28 @@ data "gdashboard_timeseries" "jvm_memory" {
2423
}
2524
}
2625
26+
data "gdashboard_timeseries" "http_requests" {
27+
title = "HTTP Requests"
28+
29+
queries {
30+
prometheus {
31+
uid = "prometheus"
32+
expr = "sum(increase(http_request_total{container_name='container'}[$__rate_interval]))"
33+
}
34+
}
35+
}
36+
37+
data "gdashboard_timeseries" "http_status" {
38+
title = "HTTP Status"
39+
40+
queries {
41+
prometheus {
42+
uid = "prometheus"
43+
expr = "sum(increase(http_status_total{container_name='container'}[$__rate_interval]))"
44+
}
45+
}
46+
}
47+
2748
data "gdashboard_dashboard" "jvm_dashboard" {
2849
title = "JVM Dashboard"
2950
description = "JVM details"
@@ -60,7 +81,9 @@ data "gdashboard_dashboard" "jvm_dashboard" {
6081
}
6182
6283
layout {
63-
row {
84+
section {
85+
title = "JVM"
86+
6487
panel {
6588
size = {
6689
height = 8
@@ -69,10 +92,90 @@ data "gdashboard_dashboard" "jvm_dashboard" {
6992
source = data.gdashboard_timeseries.jvm_memory.json
7093
}
7194
}
95+
96+
section { // each panel is on a new row
97+
title = "HTTP"
98+
99+
row { // force a new row/line
100+
panel {
101+
size = {
102+
height = 8
103+
width = 10
104+
}
105+
source = data.gdashboard_timeseries.http_requests.json
106+
}
107+
}
108+
109+
row { // force a new row/line
110+
panel {
111+
size = {
112+
height = 8
113+
width = 10
114+
}
115+
source = data.gdashboard_timeseries.http_status.json
116+
}
117+
}
118+
}
119+
}
120+
}
121+
```
122+
123+
## Layout Explained
124+
125+
The `layout` block is used to define the structure of the dashboard by grouping the panels into sections.
126+
The layout block can contain one or more section blocks, and each section block can contain one or more panel blocks.
127+
128+
You have the option to include `title` and `collapsed` attributes. If either of these attributes is included,
129+
the section will be collapsible, appearing as a row that can be expanded or collapsed based on the user's preference.
130+
131+
______
132+
133+
The panels are placed starting from the top-left corner of the section and are positioned in a way that preserves their order.
134+
In other words, the first panel specified in the configuration will be placed in the top-left corner of the section, followed by the second panel, and so on.
135+
136+
It's important to note that the placement of panels cannot be manually specified, and it is determined by the order in which the panels are defined in the configuration.
137+
138+
______
139+
140+
You can use the `row` block instead of the `panel` block to explicitly mark rows when defining a layout.
141+
By using `row`, you have greater control over the placement of the panels within the section.
142+
143+
For example, you can place each panel on a new line/row:
144+
```terraform
145+
layout {
146+
section {
147+
title = "HTTP"
148+
149+
row { // force a new row/line
150+
panel {
151+
size = {
152+
height = 8
153+
width = 10
154+
}
155+
source = data.gdashboard_timeseries.http_requests.json
156+
}
157+
}
158+
159+
row { // force a new row/line
160+
panel {
161+
size = {
162+
height = 8
163+
width = 10
164+
}
165+
source = data.gdashboard_timeseries.http_status.json
166+
}
167+
}
72168
}
73169
}
74170
```
75171

172+
**Note:** the section block cannot have both `panel` and `row` blocks at the same time. You must use either one or the other.
173+
______
174+
175+
In the example above, the layout block contains two **collapsible** section blocks, one titled "JVM" and the other "HTTP".
176+
The "JVM" section has a single panel block with dimensions `8x10`, and the data source specified as `data.gdashboard_timeseries.jvm_memory.json`.
177+
The "HTTP" section has two panel blocks, both with dimensions `8x10` and data sources `data.gdashboard_timeseries.http_requests.json` and `data.gdashboard_timeseries.http_status.json`, respectively.
178+
76179
<!-- schema generated by tfplugindocs -->
77180
## Schema
78181

@@ -103,25 +206,53 @@ data "gdashboard_dashboard" "jvm_dashboard" {
103206

104207
Optional:
105208

106-
- `row` (Block List) The row within the dashboard. (see [below for nested schema](#nestedblock--layout--row))
209+
- `section` (Block List) The row within the dashboard. (see [below for nested schema](#nestedblock--layout--section))
210+
211+
<a id="nestedblock--layout--section"></a>
212+
### Nested Schema for `layout.section`
213+
214+
Optional:
215+
216+
- `collapsed` (Boolean) Whether the row is collapsed or not.
217+
- `panel` (Block List) The definition of the panel within the row. (see [below for nested schema](#nestedblock--layout--section--panel))
218+
- `row` (Block List) The new row to align the nested panels. (see [below for nested schema](#nestedblock--layout--section--row))
219+
- `title` (String) The title of the row. If the title is defined the row is treated as collapsible.
220+
221+
<a id="nestedblock--layout--section--panel"></a>
222+
### Nested Schema for `layout.section.panel`
223+
224+
Required:
225+
226+
- `size` (Attributes) The size of the panel. (see [below for nested schema](#nestedatt--layout--section--panel--size))
227+
- `source` (String) The JSON source of the panel.
107228

108-
<a id="nestedblock--layout--row"></a>
109-
### Nested Schema for `layout.row`
229+
<a id="nestedatt--layout--section--panel--size"></a>
230+
### Nested Schema for `layout.section.panel.size`
231+
232+
Required:
233+
234+
- `height` (Number) The height of the panel.
235+
- `width` (Number) The width of the panel.
236+
237+
238+
239+
<a id="nestedblock--layout--section--row"></a>
240+
### Nested Schema for `layout.section.row`
110241

111242
Optional:
112243

113-
- `panel` (Block List) The definition of the panel within the row. (see [below for nested schema](#nestedblock--layout--row--panel))
244+
- `panel` (Block List) The definition of the panel within the row. (see [below for nested schema](#nestedblock--layout--section--row--panel))
114245

115-
<a id="nestedblock--layout--row--panel"></a>
116-
### Nested Schema for `layout.row.panel`
246+
<a id="nestedblock--layout--section--row--panel"></a>
247+
### Nested Schema for `layout.section.row.panel`
117248

118249
Required:
119250

120-
- `size` (Attributes) The size of the panel. (see [below for nested schema](#nestedatt--layout--row--panel--size))
251+
- `size` (Attributes) The size of the panel. (see [below for nested schema](#nestedatt--layout--section--row--panel--size))
121252
- `source` (String) The JSON source of the panel.
122253

123-
<a id="nestedatt--layout--row--panel--size"></a>
124-
### Nested Schema for `layout.row.panel.size`
254+
<a id="nestedatt--layout--section--row--panel--size"></a>
255+
### Nested Schema for `layout.section.row.panel.size`
125256

126257
Required:
127258

@@ -132,6 +263,7 @@ Required:
132263

133264

134265

266+
135267
<a id="nestedblock--time"></a>
136268
### Nested Schema for `time`
137269

@@ -186,7 +318,7 @@ Required:
186318

187319
Optional:
188320

189-
- `datasource` (Block List) The datasource to use. (see [below for nested schema](#nestedblock--variables--adhoc--datasource))
321+
- `datasource` (Block, Optional) The datasource to use. (see [below for nested schema](#nestedblock--variables--adhoc--datasource))
190322
- `description` (String) The description of the variable.
191323
- `filter` (Block List) The predefined filters. (see [below for nested schema](#nestedblock--variables--adhoc--filter))
192324
- `hide` (String) Which variable information to hide from the dashboard. The choices are: `label`, `variable`.
@@ -282,7 +414,7 @@ Optional:
282414
- `include_all` (Block List) An option to include all variables. If `custom_value` is blank, then the Grafana concatenates (adds together) all the values in the query. (see [below for nested schema](#nestedblock--variables--datasource--include_all))
283415
- `label` (String) The optional display name.
284416
- `multi` (Boolean) Whether to allow selecting multiple values at the same time or not.
285-
- `source` (Block List) The datasource selector. (see [below for nested schema](#nestedblock--variables--datasource--source))
417+
- `source` (Block, Optional) The datasource selector. (see [below for nested schema](#nestedblock--variables--datasource--source))
286418

287419
<a id="nestedblock--variables--datasource--include_all"></a>
288420
### Nested Schema for `variables.datasource.include_all`
@@ -409,5 +541,3 @@ Optional:
409541
- `description` (String) The description of the variable.
410542
- `hide` (String) Which variable information to hide from the dashboard. The choices are: `label`, `variable`.
411543
- `label` (String) The optional display name.
412-
413-

docs/data-sources/row.md

Lines changed: 0 additions & 48 deletions
This file was deleted.

docs/index.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ data "gdashboard_dashboard" "dashboard" {
3737
title = "My dashboard"
3838
3939
layout {
40-
row {
40+
section {
41+
title = "Basic Details"
42+
4143
panel {
4244
size = {
4345
height = 8

examples/data-sources/gdashboard_dashboard/data-source.tf

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,28 @@ data "gdashboard_timeseries" "jvm_memory" {
99
}
1010
}
1111

12+
data "gdashboard_timeseries" "http_requests" {
13+
title = "HTTP Requests"
14+
15+
queries {
16+
prometheus {
17+
uid = "prometheus"
18+
expr = "sum(increase(http_request_total{container_name='container'}[$__rate_interval]))"
19+
}
20+
}
21+
}
22+
23+
data "gdashboard_timeseries" "http_status" {
24+
title = "HTTP Status"
25+
26+
queries {
27+
prometheus {
28+
uid = "prometheus"
29+
expr = "sum(increase(http_status_total{container_name='container'}[$__rate_interval]))"
30+
}
31+
}
32+
}
33+
1234
data "gdashboard_dashboard" "jvm_dashboard" {
1335
title = "JVM Dashboard"
1436
description = "JVM details"
@@ -45,7 +67,9 @@ data "gdashboard_dashboard" "jvm_dashboard" {
4567
}
4668

4769
layout {
48-
row {
70+
section {
71+
title = "JVM"
72+
4973
panel {
5074
size = {
5175
height = 8
@@ -54,5 +78,29 @@ data "gdashboard_dashboard" "jvm_dashboard" {
5478
source = data.gdashboard_timeseries.jvm_memory.json
5579
}
5680
}
81+
82+
section { // each panel is on a new row
83+
title = "HTTP"
84+
85+
row { // force a new row/line
86+
panel {
87+
size = {
88+
height = 8
89+
width = 10
90+
}
91+
source = data.gdashboard_timeseries.http_requests.json
92+
}
93+
}
94+
95+
row { // force a new row/line
96+
panel {
97+
size = {
98+
height = 8
99+
width = 10
100+
}
101+
source = data.gdashboard_timeseries.http_status.json
102+
}
103+
}
104+
}
57105
}
58106
}

examples/data-sources/gdashboard_row/data-source.tf

Lines changed: 0 additions & 7 deletions
This file was deleted.

examples/provider/provider_grafana_example.tf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ data "gdashboard_dashboard" "dashboard" {
1313
title = "My dashboard"
1414

1515
layout {
16-
row {
16+
section {
17+
title = "Basic Details"
18+
1719
panel {
1820
size = {
1921
height = 8

0 commit comments

Comments
 (0)