Skip to content

Commit babb286

Browse files
authored
Fix: Set destination_datasource to be a required field in SLO (#1891)
* set destination_datasource to be a required field * update docs
1 parent cf554d4 commit babb286

File tree

3 files changed

+33
-12
lines changed

3 files changed

+33
-12
lines changed

docs/resources/slo.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ resource "grafana_slo" "test" {
131131
### Required
132132

133133
- `description` (String) Description is a free-text field that can provide more context to an SLO.
134+
- `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))
134135
- `name` (String) Name should be a short description of your indicator. Consider names like "API Availability"
135136
- `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))
136137
- `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))
@@ -142,7 +143,6 @@ resource "grafana_slo" "test" {
142143
alerts when the short-term error budget burn is very high, the
143144
long-term error budget burn rate is high, or when the remaining
144145
error budget is below a certain threshold. Annotations and Labels support templating. (see [below for nested schema](#nestedblock--alerting))
145-
- `destination_datasource` (Block List, Max: 1) Destination Datasource sets the datasource defined for an SLO (see [below for nested schema](#nestedblock--destination_datasource))
146146
- `folder_uid` (String) UID for the SLO folder
147147
- `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))
148148
- `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.
@@ -151,6 +151,14 @@ resource "grafana_slo" "test" {
151151

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

154+
<a id="nestedblock--destination_datasource"></a>
155+
### Nested Schema for `destination_datasource`
156+
157+
Required:
158+
159+
- `uid` (String) UID for the Datasource
160+
161+
154162
<a id="nestedblock--objectives"></a>
155163
### Nested Schema for `objectives`
156164

@@ -286,14 +294,6 @@ Required:
286294

287295

288296

289-
<a id="nestedblock--destination_datasource"></a>
290-
### Nested Schema for `destination_datasource`
291-
292-
Optional:
293-
294-
- `uid` (String) UID for the Mimir Datasource
295-
296-
297297
<a id="nestedblock--label"></a>
298298
### Nested Schema for `label`
299299

internal/resources/slo/resource_slo.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@ Resource manages Grafana SLOs.
5959
"destination_datasource": {
6060
Type: schema.TypeList,
6161
MaxItems: 1,
62-
Optional: true,
62+
Required: true,
6363
Description: `Destination Datasource sets the datasource defined for an SLO`,
6464
Elem: &schema.Resource{
6565
Schema: map[string]*schema.Schema{
6666
"uid": {
6767
Type: schema.TypeString,
68-
Description: `UID for the Mimir Datasource`,
69-
Optional: true,
68+
Description: `UID for the Datasource`,
69+
Required: true,
7070
},
7171
},
7272
},

internal/resources/slo/resource_slo_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,23 @@ resource "grafana_slo" "invalid" {
311311
}
312312
`
313313

314+
const sloMissingDestinationDatasource = `
315+
resource "grafana_slo" "invalid" {
316+
name = "Test SLO"
317+
description = "Description Test SLO"
318+
query {
319+
freeform {
320+
query = "sum(rate(apiserver_request_total{code!=\"500\"}[$__rate_interval])) / sum(rate(apiserver_request_total[$__rate_interval]))"
321+
}
322+
type = "freeform"
323+
}
324+
objectives {
325+
value = 1.5
326+
window = "1m"
327+
}
328+
}
329+
`
330+
314331
func emptyAlert(name string) string {
315332
return fmt.Sprintf(`
316333
resource "grafana_slo" "empty_alert" {
@@ -366,6 +383,10 @@ func TestAccResourceInvalidSlo(t *testing.T) {
366383
Config: sloObjectivesInvalid,
367384
ExpectError: regexp.MustCompile("Error:"),
368385
},
386+
{
387+
Config: sloMissingDestinationDatasource,
388+
ExpectError: regexp.MustCompile("Error: Insufficient destination_datasource blocks"),
389+
},
369390
},
370391
})
371392
}

0 commit comments

Comments
 (0)