Skip to content

Commit

Permalink
Fix: Set destination_datasource to be a required field in SLO (#1891)
Browse files Browse the repository at this point in the history
* set destination_datasource to be a required field

* update docs
  • Loading branch information
elainevuong authored Nov 7, 2024
1 parent cf554d4 commit babb286
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 12 deletions.
18 changes: 9 additions & 9 deletions docs/resources/slo.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ resource "grafana_slo" "test" {
### Required

- `description` (String) Description is a free-text field that can provide more context to an SLO.
- `destination_datasource` (Block List, Min: 1, Max: 1) Destination Datasource sets the datasource defined for an SLO (see [below for nested schema](#nestedblock--destination_datasource))
- `name` (String) Name should be a short description of your indicator. Consider names like "API Availability"
- `objectives` (Block List, Min: 1) Over each rolling time window, the remaining error budget will be calculated, and separate alerts can be generated for each time window based on the SLO burn rate or remaining error budget. (see [below for nested schema](#nestedblock--objectives))
- `query` (Block List, Min: 1) Query describes the indicator that will be measured against the objective. Freeform Query types are currently supported. (see [below for nested schema](#nestedblock--query))
Expand All @@ -142,7 +143,6 @@ resource "grafana_slo" "test" {
alerts when the short-term error budget burn is very high, the
long-term error budget burn rate is high, or when the remaining
error budget is below a certain threshold. Annotations and Labels support templating. (see [below for nested schema](#nestedblock--alerting))
- `destination_datasource` (Block List, Max: 1) Destination Datasource sets the datasource defined for an SLO (see [below for nested schema](#nestedblock--destination_datasource))
- `folder_uid` (String) UID for the SLO folder
- `label` (Block List) Additional labels that will be attached to all metrics generated from the query. These labels are useful for grouping SLOs in dashboard views that you create by hand. Labels must adhere to Prometheus label name schema - "^[a-zA-Z_][a-zA-Z0-9_]*$" (see [below for nested schema](#nestedblock--label))
- `search_expression` (String) The name of a search expression in Grafana Asserts. This is used in the SLO UI to open the Asserts RCA workbench and in alerts to link to the RCA workbench.
Expand All @@ -151,6 +151,14 @@ resource "grafana_slo" "test" {

- `id` (String) The ID of this resource.

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

Required:

- `uid` (String) UID for the Datasource


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

Expand Down Expand Up @@ -286,14 +294,6 @@ Required:



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

Optional:

- `uid` (String) UID for the Mimir Datasource


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

Expand Down
6 changes: 3 additions & 3 deletions internal/resources/slo/resource_slo.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ Resource manages Grafana SLOs.
"destination_datasource": {
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
Required: true,
Description: `Destination Datasource sets the datasource defined for an SLO`,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"uid": {
Type: schema.TypeString,
Description: `UID for the Mimir Datasource`,
Optional: true,
Description: `UID for the Datasource`,
Required: true,
},
},
},
Expand Down
21 changes: 21 additions & 0 deletions internal/resources/slo/resource_slo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,23 @@ resource "grafana_slo" "invalid" {
}
`

const sloMissingDestinationDatasource = `
resource "grafana_slo" "invalid" {
name = "Test SLO"
description = "Description Test SLO"
query {
freeform {
query = "sum(rate(apiserver_request_total{code!=\"500\"}[$__rate_interval])) / sum(rate(apiserver_request_total[$__rate_interval]))"
}
type = "freeform"
}
objectives {
value = 1.5
window = "1m"
}
}
`

func emptyAlert(name string) string {
return fmt.Sprintf(`
resource "grafana_slo" "empty_alert" {
Expand Down Expand Up @@ -366,6 +383,10 @@ func TestAccResourceInvalidSlo(t *testing.T) {
Config: sloObjectivesInvalid,
ExpectError: regexp.MustCompile("Error:"),
},
{
Config: sloMissingDestinationDatasource,
ExpectError: regexp.MustCompile("Error: Insufficient destination_datasource blocks"),
},
},
})
}

0 comments on commit babb286

Please sign in to comment.