Skip to content

Commit

Permalink
Merge pull request #109 from gdashboard/logs-panel
Browse files Browse the repository at this point in the history
Support `Logs` panel
  • Loading branch information
iRevive authored Feb 23, 2024
2 parents d984e03 + 0e6938f commit 9dcbbee
Show file tree
Hide file tree
Showing 14 changed files with 562 additions and 15 deletions.
4 changes: 2 additions & 2 deletions docs/data-sources/gauge.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
page_title: "gdashboard_gauge Data Source - terraform-provider-gdashboard"
subcategory: ""
description: |-
Gauge panel data source. See Grafana documentation https://grafana.com/docs/grafana/latest/panels-visualizations/visualizations/gauge/. for more details
Gauge panel data source. See Grafana documentation https://grafana.com/docs/grafana/latest/panels-visualizations/visualizations/gauge/ for more details.
---

# gdashboard_gauge (Data Source)

Gauge panel data source. See Grafana [documentation](https://grafana.com/docs/grafana/latest/panels-visualizations/visualizations/gauge/). for more details
Gauge panel data source. See Grafana [documentation](https://grafana.com/docs/grafana/latest/panels-visualizations/visualizations/gauge/) for more details.

## Minimal Example

Expand Down
118 changes: 118 additions & 0 deletions docs/data-sources/logs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
---
page_title: "gdashboard_logs Data Source - terraform-provider-gdashboard"
subcategory: ""
description: |-
Logs panel data source. See Grafana documentation https://grafana.com/docs/grafana/latest/panels-visualizations/visualizations/logs/ for more details.
---

# gdashboard_logs (Data Source)

Logs panel data source. See Grafana [documentation](https://grafana.com/docs/grafana/latest/panels-visualizations/visualizations/logs/) for more details.

## Example

```terraform
data "gdashboard_logs" "logs" {
title = "Logs example"
description = "Text description"
graph {
show_time = true
show_unique_labels = true
show_common_labels = true
wrap_lines = true
prettify_json = true
enable_log_details = false
deduplication = "exact"
order = "oldest_first"
}
}
```

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

### Required

- `title` (String) The title of this panel.

### Optional

- `compact_json` (Boolean) Whether to use compat JSON encoding or not.
- `description` (String) The description of this panel.
- `graph` (Block List) The visualization options. (see [below for nested schema](#nestedblock--graph))
- `queries` (Block List) The queries to collect values from data sources. (see [below for nested schema](#nestedblock--queries))

### Read-Only

- `id` (String) The ID of this resource.
- `json` (String) The Grafana-API-compatible JSON of this panel.

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

Optional:

- `deduplication` (String) The layout orientation. The choices are: `none`, `exact`, `numbers`, `signature`.
- `enable_log_details` (Boolean) Whether to show log details view for each log row.
- `order` (String) The order in which to show logs first. The choices are: `newest_first`, `oldest_first`.
- `prettify_json` (Boolean) Set this to true to pretty print all JSON logs. This setting does not affect logs in any format other than JSON.
- `show_common_labels` (Boolean) Whether to show the common labels.
- `show_time` (Boolean) Whether to show the time column. This is the timestamp associated with the log line as reported from the data source.
- `show_unique_labels` (Boolean) Whether to show the unique labels column, which shows only non-common labels.
- `wrap_lines` (Boolean) Whether to wrap the lines.


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

Optional:

- `cloudwatch` (Block List) The CloudWatch query. (see [below for nested schema](#nestedblock--queries--cloudwatch))
- `prometheus` (Block List) The Prometheus query. (see [below for nested schema](#nestedblock--queries--prometheus))

<a id="nestedblock--queries--cloudwatch"></a>
### Nested Schema for `queries.cloudwatch`

Required:

- `metric_name` (String) The name of the metric to query. Example: `CPUUtilization`
- `namespace` (String) The namespace to query the metrics from.
- `statistic` (String) The calculation to apply to the time series.
- `uid` (String) The UID of a CloudWatch DataSource to use in this query.

Optional:

- `dimension` (Block List) The dimension to filter the metric with. (see [below for nested schema](#nestedblock--queries--cloudwatch--dimension))
- `label` (String) The legend name.
- `match_exact` (Boolean) If enabled you also need to specify **all** the dimensions of the metric you’re querying.
- `period` (String) The minimum interval between points in seconds.
- `ref_id` (String) The ID of the query. The ID can be used to reference queries in math expressions.
- `region` (String) The AWS region to query the metrics from.

<a id="nestedblock--queries--cloudwatch--dimension"></a>
### Nested Schema for `queries.cloudwatch.dimension`

Required:

- `name` (String) The name of the dimension.
- `value` (String) The value of the dimension.



<a id="nestedblock--queries--prometheus"></a>
### Nested Schema for `queries.prometheus`

Required:

- `expr` (String) The query expression.
- `uid` (String) The UID of a Prometheus DataSource to use in this query.

Optional:

- `format` (String) The query format. The choices are: `time_series`, `table`, `heatmap`.
- `instant` (Boolean) Whether to return the latest value from the time series or not.
- `legend_format` (String) The legend name.
- `min_interval` (String) The lower bounds on the interval between data points.
- `ref_id` (String) The ID of the query. The ID can be used to reference queries in math expressions.
16 changes: 16 additions & 0 deletions examples/data-sources/gdashboard_logs/data-source.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
data "gdashboard_logs" "logs" {
title = "Logs example"
description = "Text description"

graph {
show_time = true
show_unique_labels = true
show_common_labels = true
wrap_lines = true
prettify_json = true
enable_log_details = false
deduplication = "exact"
order = "oldest_first"
}

}
3 changes: 1 addition & 2 deletions internal/provider/bar_gauge_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,7 @@ func (d *BarGaugeDataSource) Read(ctx context.Context, req datasource.ReadReques
}

if !data.Description.IsNull() {
description := data.Description.ValueString()
panel.CommonPanel.Description = &description
panel.CommonPanel.Description = data.Description.ValueStringPointer()
}

var jsonData []byte
Expand Down
5 changes: 2 additions & 3 deletions internal/provider/gauge_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func (d *GaugeDataSource) Schema(ctx context.Context, req datasource.SchemaReque
resp.Schema = schema.Schema{
// This description is used by the documentation generator and the language server.
Description: "Gauge panel data source.",
MarkdownDescription: "Gauge panel data source. See Grafana [documentation](https://grafana.com/docs/grafana/latest/panels-visualizations/visualizations/gauge/). for more details",
MarkdownDescription: "Gauge panel data source. See Grafana [documentation](https://grafana.com/docs/grafana/latest/panels-visualizations/visualizations/gauge/) for more details.",

Blocks: map[string]schema.Block{
"queries": queryBlock(),
Expand Down Expand Up @@ -210,8 +210,7 @@ func (d *GaugeDataSource) Read(ctx context.Context, req datasource.ReadRequest,
}

if !data.Description.IsNull() {
description := data.Description.ValueString()
panel.CommonPanel.Description = &description
panel.CommonPanel.Description = data.Description.ValueStringPointer()
}

var jsonData []byte
Expand Down
22 changes: 22 additions & 0 deletions internal/provider/grafana/panel.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const (
GaugeType
HeatmapType
TimeseriesType
LogsType
)

type (
Expand All @@ -46,6 +47,7 @@ type (
*HeatmapPanel
*TimeseriesPanel
*CustomPanel
*LogsPanel
}
panelType int8
GridPos struct {
Expand Down Expand Up @@ -180,6 +182,16 @@ type (
TextSize TextSize `json:"text"`
ReduceOptions ReduceOptions `json:"reduceOptions"`
}
LogsOptions struct {
ShowTime *bool `json:"showTime,omitempty"`
ShowLabels *bool `json:"showLabels,omitempty"`
ShowCommonLabels *bool `json:"showCommonLabels,omitempty"`
WrapLogMessage *bool `json:"wrapLogMessage,omitempty"`
PrettifyLogMessage *bool `json:"prettifyLogMessage,omitempty"`
EnableLogDetails *bool `json:"enableLogDetails,omitempty"`
DedupStrategy *string `json:"dedupStrategy,omitempty"`
SortOrder *string `json:"sortOrder,omitempty"`
}
Threshold struct {
// the alert threshold value, we do not omitempty, since 0 is a valid
// threshold
Expand Down Expand Up @@ -260,6 +272,10 @@ type (
Targets []Target `json:"targets,omitempty"`
FieldConfig FieldConfig `json:"fieldConfig"`
}
LogsPanel struct {
Options LogsOptions `json:"options"`
Targets []Target `json:"targets,omitempty"`
}
StatPanel struct {
Colors []string `json:"colors"`
ColorValue bool `json:"colorValue"`
Expand Down Expand Up @@ -789,6 +805,12 @@ func (p *Panel) MarshalJSON() ([]byte, error) {
*p.CustomPanel,
}
return json.Marshal(outCustom)
case LogsType:
var outLogs = struct {
CommonPanel
LogsPanel
}{p.CommonPanel, *p.LogsPanel}
return json.Marshal(outLogs)
}
return nil, errors.New("can't marshal unknown panel type")
}
Expand Down
Loading

0 comments on commit 9dcbbee

Please sign in to comment.