Skip to content

Commit 9201368

Browse files
authored
Additional information on annotations and labels for the SLO provider (#952)
* Changes for additional information on annotations and labels for the SLO provider * Changes for annotation info. * Adding a template file. * Revert "Changes for additional information on annotations and labels for the SLO provider" This reverts commit a31bd54. * A little templating for the advanced version. * Generating matching .tf files
1 parent 1326a83 commit 9201368

File tree

6 files changed

+95
-7
lines changed

6 files changed

+95
-7
lines changed

docs/data-sources/slos.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ page_title: "grafana_slos Data Source - terraform-provider-grafana"
44
subcategory: "SLO"
55
description: |-
66
Datasource for retrieving all SLOs.
7-
Official documentation https://grafana.com/docs/grafana-cloud/slo/API documentation https://grafana.com/docs/grafana-cloud/slo/api/
7+
Official documentation https://grafana.com/docs/grafana-cloud/slo/API documentation https://grafana.com/docs/grafana-cloud/slo/api/Additional Information On Alerting Rule Annotations and Labels https://prometheus.io/docs/prometheus/latest/configuration/alerting_rules/#templating/
88
---
99

1010
# grafana_slos (Data Source)
@@ -13,6 +13,7 @@ Datasource for retrieving all SLOs.
1313

1414
* [Official documentation](https://grafana.com/docs/grafana-cloud/slo/)
1515
* [API documentation](https://grafana.com/docs/grafana-cloud/slo/api/)
16+
* [Additional Information On Alerting Rule Annotations and Labels](https://prometheus.io/docs/prometheus/latest/configuration/alerting_rules/#templating/)
1617

1718
## Example Usage
1819

docs/resources/slo.md

Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ page_title: "grafana_slo Resource - terraform-provider-grafana"
44
subcategory: "SLO"
55
description: |-
66
Resource manages Grafana SLOs.
7-
Official documentation https://grafana.com/docs/grafana-cloud/slo/API documentation https://grafana.com/docs/grafana-cloud/slo/api/
7+
Official documentation https://grafana.com/docs/grafana-cloud/slo/API documentation https://grafana.com/docs/grafana-cloud/slo/api/Additional Information On Alerting Rule Annotations and Labels https://prometheus.io/docs/prometheus/latest/configuration/alerting_rules/#templating/
88
---
99

1010
# grafana_slo (Resource)
@@ -13,9 +13,12 @@ Resource manages Grafana SLOs.
1313

1414
* [Official documentation](https://grafana.com/docs/grafana-cloud/slo/)
1515
* [API documentation](https://grafana.com/docs/grafana-cloud/slo/api/)
16+
* [Additional Information On Alerting Rule Annotations and Labels](https://prometheus.io/docs/prometheus/latest/configuration/alerting_rules/#templating/)
1617

1718
## Example Usage
1819

20+
### Basic
21+
1922
```terraform
2023
resource "grafana_slo" "test" {
2124
name = "Terraform Testing"
@@ -60,6 +63,65 @@ resource "grafana_slo" "test" {
6063
}
6164
```
6265

66+
### Advanced
67+
68+
```terraform
69+
resource "grafana_slo" "test" {
70+
name = "Complex Resource - Terraform Testing"
71+
description = "Complex Resource - Terraform Description"
72+
query {
73+
freeform {
74+
query = "sum(rate(apiserver_request_total{code!=\"500\"}[$__rate_interval])) / sum(rate(apiserver_request_total[$__rate_interval]))"
75+
}
76+
type = "freeform"
77+
}
78+
objectives {
79+
value = 0.995
80+
window = "30d"
81+
}
82+
label {
83+
key = "slokey"
84+
value = "slokey"
85+
}
86+
alerting {
87+
label {
88+
key = "alertingkey"
89+
value = "alertingvalue"
90+
}
91+
92+
fastburn {
93+
annotation {
94+
key = "name"
95+
value = "Critical - SLO Burn Rate Alert - {{$labels.instance}}"
96+
}
97+
annotation {
98+
key = "description"
99+
value = "Error Budget is burning at a rate greater than 14.4x."
100+
}
101+
label {
102+
key = "type"
103+
value = "slo"
104+
}
105+
}
106+
107+
slowburn {
108+
annotation {
109+
key = "name"
110+
value = "Warning - SLO Burn Rate Alert - {{$labels.instance}}"
111+
}
112+
annotation {
113+
key = "description"
114+
value = "Error Budget is burning at a rate greater than 1x."
115+
}
116+
label {
117+
key = "type"
118+
value = "slo"
119+
}
120+
}
121+
}
122+
}
123+
```
124+
63125
<!-- schema generated by tfplugindocs -->
64126
## Schema
65127

@@ -76,7 +138,7 @@ resource "grafana_slo" "test" {
76138
time window associated with the SLO. Grafana SLOs can generate
77139
alerts when the short-term error budget burn is very high, the
78140
long-term error budget burn rate is high, or when the remaining
79-
error budget is below a certain threshold. (see [below for nested schema](#nestedblock--alerting))
141+
error budget is below a certain threshold. Annotations and Labels support templating. (see [below for nested schema](#nestedblock--alerting))
80142
- `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. (see [below for nested schema](#nestedblock--label))
81143

82144
### Read-Only
@@ -198,4 +260,4 @@ Required:
198260
Required:
199261

200262
- `key` (String)
201-
- `value` (String)
263+
- `value` (String)

examples/resources/grafana_slo/resource_complex.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ resource "grafana_slo" "test" {
2424
fastburn {
2525
annotation {
2626
key = "name"
27-
value = "Critical - SLO Burn Rate Alert"
27+
value = "Critical - SLO Burn Rate Alert - {{$labels.instance}}"
2828
}
2929
annotation {
3030
key = "description"
@@ -39,7 +39,7 @@ resource "grafana_slo" "test" {
3939
slowburn {
4040
annotation {
4141
key = "name"
42-
value = "Warning - SLO Burn Rate Alert"
42+
value = "Warning - SLO Burn Rate Alert - {{$labels.instance}}"
4343
}
4444
annotation {
4545
key = "description"

internal/resources/slo/data_source_slo.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Datasource for retrieving all SLOs.
1616
1717
* [Official documentation](https://grafana.com/docs/grafana-cloud/slo/)
1818
* [API documentation](https://grafana.com/docs/grafana-cloud/slo/api/)
19+
* [Additional Information On Alerting Rule Annotations and Labels](https://prometheus.io/docs/prometheus/latest/configuration/alerting_rules/#templating/)
1920
`,
2021
ReadContext: datasourceSloRead,
2122
Schema: map[string]*schema.Schema{

internal/resources/slo/resource_slo.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Resource manages Grafana SLOs.
2020
2121
* [Official documentation](https://grafana.com/docs/grafana-cloud/slo/)
2222
* [API documentation](https://grafana.com/docs/grafana-cloud/slo/api/)
23+
* [Additional Information On Alerting Rule Annotations and Labels](https://prometheus.io/docs/prometheus/latest/configuration/alerting_rules/#templating/)
2324
`,
2425
CreateContext: resourceSloCreate,
2526
ReadContext: resourceSloRead,
@@ -104,7 +105,7 @@ Resource manages Grafana SLOs.
104105
time window associated with the SLO. Grafana SLOs can generate
105106
alerts when the short-term error budget burn is very high, the
106107
long-term error budget burn rate is high, or when the remaining
107-
error budget is below a certain threshold.`,
108+
error budget is below a certain threshold. Annotations and Labels support templating.`,
108109
Elem: &schema.Resource{
109110
Schema: map[string]*schema.Schema{
110111
"label": &schema.Schema{

templates/resources/slo.md.tmpl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "{{.Name}} {{.Type}} - {{.ProviderName}}"
4+
subcategory: ""
5+
description: |-
6+
{{ .Description | plainmarkdown | trimspace | prefixlines " " }}
7+
---
8+
9+
# {{.Name}} ({{.Type}})
10+
11+
{{ .Description | trimspace }}
12+
13+
## Example Usage
14+
15+
### Basic
16+
17+
{{ tffile "examples/resources/grafana_slo/resource.tf" }}
18+
19+
### Advanced
20+
21+
{{ tffile "examples/resources/grafana_slo/resource_complex.tf" }}
22+
23+
{{ .SchemaMarkdown | trimspace }}

0 commit comments

Comments
 (0)