Skip to content

Commit

Permalink
feat(dashboard): adress review comments-adding support for data forma…
Browse files Browse the repository at this point in the history
…t to newrelic_one_dashboard resource in terraform
  • Loading branch information
vinay-newrelic committed Sep 23, 2024
1 parent 8f75356 commit 8ecf3f0
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 12 deletions.
7 changes: 3 additions & 4 deletions newrelic/resource_newrelic_one_dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,10 +489,9 @@ func dashboardWidgetDataFormatSchemaElem() *schema.Resource {
Description: "The column name to be sorted",
},
"type": {
Type: schema.TypeString,
Required: true,
Description: "Defines the type of the mentioned column",
ValidateFunc: validation.StringInSlice([]string{"decimal", "date", "duration", "recent-relative", "custom", "humanized"}, true),
Type: schema.TypeString,
Required: true,
Description: "Defines the type of the mentioned column",
},
"format": {
Type: schema.TypeString,
Expand Down
1 change: 0 additions & 1 deletion newrelic/structures_newrelic_one_dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -1812,7 +1812,6 @@ func validateWidgetDataFormatterStructure(d *schema.ResourceDiff, errorsList *[]
*errorsList = append(*errorsList, fmt.Sprintf("'format' should not be provided if 'type' has the value %s", dataFormat["type"]))
}
}
fmt.Printf("i am inside dataFormatsOk %v\n", dataFormat["precision"])
if dataFormat["type"] != nil && dataFormat["precision"] != 0 {
if dataFormat["precision"] != "" && slices.Contains(acceptedTypes, dataFormat["type"].(string)) {
*errorsList = append(*errorsList, fmt.Sprintf("'precision' should not be provided if 'type' has the value %s", dataFormat["type"]))
Expand Down
47 changes: 40 additions & 7 deletions website/docs/r/one_dashboard.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -373,11 +373,18 @@ Each widget type supports an additional set of arguments:

### Nested `data_format` blocks

Nested `data_format` specifies the data structure format in the table. It defines how the data is organized and interpreted.This attribute requires specifying the following attributes in a nested block -
Nested `data_format` blocks help specify the format of data displayed by a widget per attribute in the data returned by the NRQL query rendering the widget; thereby defining how the data fetched is best interpreted. This is supported for **billboards** and **tables**, as these are the only widgets in dashboards which return single or multi-faceted data that may be formatted based on the type of data returned.
This attribute requires specifying the following attributes in a nested block -

* `name` - (Required) This attribute mandates the specification of the column name to be formatted. It identifies which column the data format should be applied to.
* `type` - (Required) This attribute sets the format category for your data. Accepted values include `decimal` for numeric values, `date` for date/time values, `duration` for length of time, `recent-relative` for values referencing a relative point in time, `custom` for specific date/time formats and `humanized` to set autoformat as true.
* `format` - (Optional) This attribute is provided when the `type` attribute is set to `date`, defining the specific date format to be applied to your data.
* `type` - (Required) This attribute sets the format category for your data. Accepted values include -
- `decimal` for numeric values
- `date` for date/time values
- `duration` for length of time
- `recent-relative` for values referencing a relative point in time
- `custom` to be used with date/time values, in order to select a specific format the date/time value would need to be rendered as
- `humanized` to be used with numeric values, in order to enable Autoformat
* `format` - (Optional) This attribute is provided when the `name` is that of a column comprising date/time values and the `type` attribute is set to `custom` defining the specific date format to be applied to your data.

| Accepted value | Format |
|---------------------|-------------------------|
Expand All @@ -391,10 +398,11 @@ Nested `data_format` specifies the data structure format in the table. It define
| `%b %d, %Y, %X` | `MMM DD, YYYY,hh:mm:ss` |
| `%X` | `hh:mm:ss` |

-> **IMPORTANT!**
`type` should be set to `custom` inorder to use the formats listed above.
* `precision` - (Optional) This attribute is utilized when the `type` attribute is set to `decimal`, stipulating the precise number of digits after the decimal point for your data.

-> **IMPORTANT!**
Refer below code snippets to identify the correct set of combinations.

```hcl
widget_table {
title = "List of Transactions"
Expand All @@ -409,8 +417,8 @@ Nested `data_format` specifies the data structure format in the table. It define
}
data_format {
name = "Avg duration"
type = "date"
name = "Max duration"
Type = "duration"
}
data_format {
Expand All @@ -424,6 +432,31 @@ Nested `data_format` specifies the data structure format in the table. It define
}
}
```
* `type` should be set to `date` for default date/time values and `custom` inorder to use the formats listed above.
```hcl
data_format {
name = "timestamp"
Type = "date"
}
data_format {
name = "timestamp"
Type = "custom"
Format = "%Y-%m-%dT%X.%L%Z"
}
```
* `type` should be set to `decimal` for numeric values and `humanized` in order to enable Autoformat for numeric values.
```hcl
data_format {
name = "count"
type = "decimal"
Precision = 4
}
data_format {
name = "count"
type = "humanized"
}
```

### Nested `nrql_query` blocks

Expand Down

0 comments on commit 8ecf3f0

Please sign in to comment.