Skip to content

Commit

Permalink
Simplify dashboard layout (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
iRevive authored Mar 19, 2023
1 parent b677aee commit 446caea
Show file tree
Hide file tree
Showing 15 changed files with 1,364 additions and 418 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ data "gdashboard_dashboard" "dashboard" {
title = "My dashboard"
layout {
row {
section {
title = "Basic Details"
panel {
size = {
height = 8
Expand Down
160 changes: 145 additions & 15 deletions docs/data-sources/dashboard.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "gdashboard_dashboard Data Source - terraform-provider-gdashboard"
subcategory: ""
description: |-
Expand All @@ -24,6 +23,28 @@ data "gdashboard_timeseries" "jvm_memory" {
}
}
data "gdashboard_timeseries" "http_requests" {
title = "HTTP Requests"
queries {
prometheus {
uid = "prometheus"
expr = "sum(increase(http_request_total{container_name='container'}[$__rate_interval]))"
}
}
}
data "gdashboard_timeseries" "http_status" {
title = "HTTP Status"
queries {
prometheus {
uid = "prometheus"
expr = "sum(increase(http_status_total{container_name='container'}[$__rate_interval]))"
}
}
}
data "gdashboard_dashboard" "jvm_dashboard" {
title = "JVM Dashboard"
description = "JVM details"
Expand Down Expand Up @@ -60,7 +81,9 @@ data "gdashboard_dashboard" "jvm_dashboard" {
}
layout {
row {
section {
title = "JVM"
panel {
size = {
height = 8
Expand All @@ -69,10 +92,90 @@ data "gdashboard_dashboard" "jvm_dashboard" {
source = data.gdashboard_timeseries.jvm_memory.json
}
}
section { // each panel is on a new row
title = "HTTP"
row { // force a new row/line
panel {
size = {
height = 8
width = 10
}
source = data.gdashboard_timeseries.http_requests.json
}
}
row { // force a new row/line
panel {
size = {
height = 8
width = 10
}
source = data.gdashboard_timeseries.http_status.json
}
}
}
}
}
```

## Layout Explained

The `layout` block is used to define the structure of the dashboard by grouping the panels into sections.
The layout block can contain one or more section blocks, and each section block can contain one or more panel blocks.

You have the option to include `title` and `collapsed` attributes. If either of these attributes is included,
the section will be collapsible, appearing as a row that can be expanded or collapsed based on the user's preference.

______

The panels are placed starting from the top-left corner of the section and are positioned in a way that preserves their order.
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.

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.

______

You can use the `row` block instead of the `panel` block to explicitly mark rows when defining a layout.
By using `row`, you have greater control over the placement of the panels within the section.

For example, you can place each panel on a new line/row:
```terraform
layout {
section {
title = "HTTP"
row { // force a new row/line
panel {
size = {
height = 8
width = 10
}
source = data.gdashboard_timeseries.http_requests.json
}
}
row { // force a new row/line
panel {
size = {
height = 8
width = 10
}
source = data.gdashboard_timeseries.http_status.json
}
}
}
}
```

**Note:** the section block cannot have both `panel` and `row` blocks at the same time. You must use either one or the other.
______

In the example above, the layout block contains two **collapsible** section blocks, one titled "JVM" and the other "HTTP".
The "JVM" section has a single panel block with dimensions `8x10`, and the data source specified as `data.gdashboard_timeseries.jvm_memory.json`.
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.

<!-- schema generated by tfplugindocs -->
## Schema

Expand Down Expand Up @@ -103,25 +206,53 @@ data "gdashboard_dashboard" "jvm_dashboard" {

Optional:

- `row` (Block List) The row within the dashboard. (see [below for nested schema](#nestedblock--layout--row))
- `section` (Block List) The row within the dashboard. (see [below for nested schema](#nestedblock--layout--section))

<a id="nestedblock--layout--section"></a>
### Nested Schema for `layout.section`

Optional:

- `collapsed` (Boolean) Whether the row is collapsed or not.
- `panel` (Block List) The definition of the panel within the row. (see [below for nested schema](#nestedblock--layout--section--panel))
- `row` (Block List) The new row to align the nested panels. (see [below for nested schema](#nestedblock--layout--section--row))
- `title` (String) The title of the row. If the title is defined the row is treated as collapsible.

<a id="nestedblock--layout--section--panel"></a>
### Nested Schema for `layout.section.panel`

Required:

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

<a id="nestedblock--layout--row"></a>
### Nested Schema for `layout.row`
<a id="nestedatt--layout--section--panel--size"></a>
### Nested Schema for `layout.section.panel.size`

Required:

- `height` (Number) The height of the panel.
- `width` (Number) The width of the panel.



<a id="nestedblock--layout--section--row"></a>
### Nested Schema for `layout.section.row`

Optional:

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

<a id="nestedblock--layout--row--panel"></a>
### Nested Schema for `layout.row.panel`
<a id="nestedblock--layout--section--row--panel"></a>
### Nested Schema for `layout.section.row.panel`

Required:

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

<a id="nestedatt--layout--row--panel--size"></a>
### Nested Schema for `layout.row.panel.size`
<a id="nestedatt--layout--section--row--panel--size"></a>
### Nested Schema for `layout.section.row.panel.size`

Required:

Expand All @@ -132,6 +263,7 @@ Required:




<a id="nestedblock--time"></a>
### Nested Schema for `time`

Expand Down Expand Up @@ -186,7 +318,7 @@ Required:

Optional:

- `datasource` (Block List) The datasource to use. (see [below for nested schema](#nestedblock--variables--adhoc--datasource))
- `datasource` (Block, Optional) The datasource to use. (see [below for nested schema](#nestedblock--variables--adhoc--datasource))
- `description` (String) The description of the variable.
- `filter` (Block List) The predefined filters. (see [below for nested schema](#nestedblock--variables--adhoc--filter))
- `hide` (String) Which variable information to hide from the dashboard. The choices are: `label`, `variable`.
Expand Down Expand Up @@ -282,7 +414,7 @@ Optional:
- `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))
- `label` (String) The optional display name.
- `multi` (Boolean) Whether to allow selecting multiple values at the same time or not.
- `source` (Block List) The datasource selector. (see [below for nested schema](#nestedblock--variables--datasource--source))
- `source` (Block, Optional) The datasource selector. (see [below for nested schema](#nestedblock--variables--datasource--source))

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


48 changes: 0 additions & 48 deletions docs/data-sources/row.md

This file was deleted.

4 changes: 3 additions & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ data "gdashboard_dashboard" "dashboard" {
title = "My dashboard"
layout {
row {
section {
title = "Basic Details"
panel {
size = {
height = 8
Expand Down
50 changes: 49 additions & 1 deletion examples/data-sources/gdashboard_dashboard/data-source.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,28 @@ data "gdashboard_timeseries" "jvm_memory" {
}
}

data "gdashboard_timeseries" "http_requests" {
title = "HTTP Requests"

queries {
prometheus {
uid = "prometheus"
expr = "sum(increase(http_request_total{container_name='container'}[$__rate_interval]))"
}
}
}

data "gdashboard_timeseries" "http_status" {
title = "HTTP Status"

queries {
prometheus {
uid = "prometheus"
expr = "sum(increase(http_status_total{container_name='container'}[$__rate_interval]))"
}
}
}

data "gdashboard_dashboard" "jvm_dashboard" {
title = "JVM Dashboard"
description = "JVM details"
Expand Down Expand Up @@ -45,7 +67,9 @@ data "gdashboard_dashboard" "jvm_dashboard" {
}

layout {
row {
section {
title = "JVM"

panel {
size = {
height = 8
Expand All @@ -54,5 +78,29 @@ data "gdashboard_dashboard" "jvm_dashboard" {
source = data.gdashboard_timeseries.jvm_memory.json
}
}

section { // each panel is on a new row
title = "HTTP"

row { // force a new row/line
panel {
size = {
height = 8
width = 10
}
source = data.gdashboard_timeseries.http_requests.json
}
}

row { // force a new row/line
panel {
size = {
height = 8
width = 10
}
source = data.gdashboard_timeseries.http_status.json
}
}
}
}
}
7 changes: 0 additions & 7 deletions examples/data-sources/gdashboard_row/data-source.tf

This file was deleted.

4 changes: 3 additions & 1 deletion examples/provider/provider_grafana_example.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ data "gdashboard_dashboard" "dashboard" {
title = "My dashboard"

layout {
row {
section {
title = "Basic Details"

panel {
size = {
height = 8
Expand Down
Loading

0 comments on commit 446caea

Please sign in to comment.