-
Notifications
You must be signed in to change notification settings - Fork 251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(bigTent slo): Custom Validate function for big tent SLO schema #2016
Changes from all commits
97b18b9
ab44728
4231bd0
fa7583a
f514eb0
1efd39b
2c6b7c9
7da58a2
b16d7d6
9697dc6
73ebdf2
6b77ed8
964ddd4
9dcb2f6
ffecf7e
6df417a
e60b741
26d9371
4881fef
a392c84
ac83149
ffd495b
6fab993
7341ebe
e8877fa
ad17b07
c1c19e9
3c90dc7
b0ee9a4
6a566c4
100c49a
d87e532
c699182
1826846
d876c5e
60500ab
112527c
07f17f0
3b4c723
f713293
4eeafbc
df4df41
4c1c8a9
5bf0f28
26f2a1a
a5bc2b2
dc3c477
e240570
60a49ea
6710ea9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,58 @@ Resource manages Grafana SLOs. | |
|
||
## Example Usage | ||
|
||
### Basic | ||
### Ratio | ||
|
||
```terraform | ||
resource "grafana_slo" "ratio" { | ||
name = "Terraform Testing - Ratio Query" | ||
description = "Terraform Description - Ratio Query" | ||
query { | ||
ratio { | ||
success_metric = "kubelet_http_requests_total{status!~\"5..\"}" | ||
total_metric = "kubelet_http_requests_total" | ||
group_by_labels = ["job", "instance"] | ||
} | ||
type = "ratio" | ||
} | ||
objectives { | ||
value = 0.995 | ||
window = "30d" | ||
} | ||
destination_datasource { | ||
uid = "grafanacloud-prom" | ||
} | ||
label { | ||
key = "slo" | ||
value = "terraform" | ||
} | ||
alerting { | ||
fastburn { | ||
annotation { | ||
key = "name" | ||
value = "SLO Burn Rate Very High" | ||
} | ||
annotation { | ||
key = "description" | ||
value = "Error budget is burning too fast" | ||
} | ||
} | ||
|
||
slowburn { | ||
annotation { | ||
key = "name" | ||
value = "SLO Burn Rate High" | ||
} | ||
annotation { | ||
key = "description" | ||
value = "Error budget is burning too fast" | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
### Advanced | ||
|
||
```terraform | ||
resource "grafana_slo" "test" { | ||
|
@@ -66,27 +117,54 @@ resource "grafana_slo" "test" { | |
} | ||
``` | ||
|
||
### Advanced | ||
### Grafana Queries - Any supported datasource | ||
|
||
Grafana Queries use the grafana_queries field. It expects a JSON string list of valid grafana query JSON objects, the same as you'll find assigned to a Grafana Dashboard panel `targets` field. | ||
|
||
```terraform | ||
resource "grafana_slo" "test" { | ||
name = "Complex Resource - Terraform Ratio Query Example" | ||
description = "Complex Resource - Terraform Ratio Query Description" | ||
name = "Terraform Testing" | ||
description = "Terraform Description" | ||
query { | ||
ratio { | ||
success_metric = "kubelet_http_requests_total{status!~\"5..\"}" | ||
total_metric = "kubelet_http_requests_total" | ||
group_by_labels = ["job", "instance"] | ||
grafana_queries { | ||
grafana_queries = jsonencode([ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue: can we use a Big Tent SLO example that matches the format and RefID of how the frontend generates it? i.e. using the maybe something like this
|
||
{ | ||
datasource : { | ||
"type" : "graphite", | ||
"uid" : "datasource-uid" | ||
}, | ||
refId : "Success", | ||
target : "groupByNode(perSecond(web.*.http.2xx_success.*.*), 3, 'avg')" | ||
}, | ||
{ | ||
datasource : { | ||
"type" : "graphite", | ||
"uid" : "datasource-uid" | ||
}, | ||
refId : "Total", | ||
target : "groupByNode(perSecond(web.*.http.5xx_errors.*.*), 3, 'avg')" | ||
Comment on lines
+144
to
+145
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion - 5xx errors isn't really a great "total" query, we should give a better example ... but I think we may have used this one on website too, so need to fix both There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah this is the exact same query. |
||
}, | ||
{ | ||
datasource : { | ||
"type" : "__expr__", | ||
"uid" : "__expr__" | ||
}, | ||
expression : "$Success / $Total", | ||
refId : "Expression", | ||
type : "math" | ||
} | ||
]) | ||
} | ||
type = "ratio" | ||
type = "grafana_queries" | ||
} | ||
destination_datasource { | ||
uid = "grafanacloud-prom" | ||
} | ||
objectives { | ||
value = 0.995 | ||
window = "30d" | ||
} | ||
destination_datasource { | ||
uid = "grafanacloud-prom" | ||
} | ||
|
||
label { | ||
key = "slo" | ||
value = "terraform" | ||
|
@@ -101,10 +179,6 @@ resource "grafana_slo" "test" { | |
key = "description" | ||
value = "Error budget is burning too fast" | ||
} | ||
label { | ||
key = "type" | ||
value = "slo" | ||
} | ||
} | ||
|
||
slowburn { | ||
|
@@ -116,15 +190,15 @@ resource "grafana_slo" "test" { | |
key = "description" | ||
value = "Error budget is burning too fast" | ||
} | ||
label { | ||
key = "type" | ||
value = "slo" | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
For a complete list, see [supported data sources](https://grafana.com/docs/grafana-cloud/alerting-and-irm/slo/set-up/additionaldatasources/#supported-data-sources). | ||
|
||
For additional help with SLOs, view our [documentation](https://grafana.com/docs/grafana-cloud/alerting-and-irm/slo/). | ||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
|
@@ -173,19 +247,28 @@ Required: | |
|
||
Required: | ||
|
||
- `type` (String) Query type must be one of: "freeform", "query", "ratio", or "threshold" | ||
- `type` (String) Query type must be one of: "freeform", "query", "ratio", "grafana_queries" or "threshold" | ||
|
||
Optional: | ||
|
||
- `freeform` (Block List, Max: 1) (see [below for nested schema](#nestedblock--query--freeform)) | ||
- `grafana_queries` (Block List, Max: 1) Array for holding a set of grafana queries (see [below for nested schema](#nestedblock--query--grafana_queries)) | ||
- `ratio` (Block List, Max: 1) (see [below for nested schema](#nestedblock--query--ratio)) | ||
|
||
<a id="nestedblock--query--freeform"></a> | ||
### Nested Schema for `query.freeform` | ||
|
||
Required: | ||
|
||
- `query` (String) Freeform Query Field | ||
- `query` (String) Freeform Query Field - valid promQl | ||
|
||
|
||
<a id="nestedblock--query--grafana_queries"></a> | ||
### Nested Schema for `query.grafana_queries` | ||
|
||
Required: | ||
|
||
- `grafana_queries` (String) Query Object - Array of Grafana Query JSON objects | ||
|
||
|
||
<a id="nestedblock--query--ratio"></a> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
resource "grafana_slo" "test" { | ||
name = "Terraform Testing" | ||
description = "Terraform Description" | ||
query { | ||
grafana_queries { | ||
grafana_queries = jsonencode([ | ||
{ | ||
aggregation : "Sum", | ||
alias : "", | ||
application : "57831", | ||
applicationName : "petclinic", | ||
datasource : { | ||
type : "dlopes7-appdynamics-datasource", | ||
uid : "appdynamics_localdev" | ||
}, | ||
delimiter : "|", | ||
isRawQuery : false, | ||
metric : "Service Endpoints|PetClinicEastTier1|/petclinic/api_SERVLET|Errors per Minute", | ||
queryType : "metrics", | ||
refId : "errors", | ||
rollUp : true, | ||
schemaVersion : "3.9.5", | ||
transformLegend : "Segments", | ||
transformLegendText : "" | ||
}, | ||
{ | ||
aggregation : "Sum", | ||
alias : "", | ||
application : "57831", | ||
applicationName : "petclinic", | ||
datasource : { | ||
type : "dlopes7-appdynamics-datasource", | ||
uid : "appdynamics_localdev" | ||
}, | ||
intervalMs : 1000, | ||
maxDataPoints : 43200, | ||
delimiter : "|", | ||
isRawQuery : false, | ||
metric : "Service Endpoints|PetClinicEastTier1|/petclinic/api_SERVLET|Calls per Minute", | ||
queryType : "metrics", | ||
refId : "total", | ||
rollUp : true, | ||
schemaVersion : "3.9.5", | ||
transformLegend : "Segments", | ||
transformLegendText : "" | ||
}, | ||
{ | ||
datasource : { | ||
type : "__expr__", | ||
uid : "__expr__" | ||
}, | ||
expression : "($total - $errors) / $total", | ||
intervalMs : 1000, | ||
maxDataPoints : 43200, | ||
refId : "C", | ||
type : "math" | ||
} | ||
]) | ||
} | ||
type = "grafana_queries" | ||
} | ||
objectives { | ||
value = 0.995 | ||
window = "30d" | ||
} | ||
destination_datasource { | ||
uid = "grafanacloud-prom" | ||
} | ||
label { | ||
key = "slo" | ||
value = "terraform" | ||
} | ||
alerting { | ||
fastburn { | ||
annotation { | ||
key = "name" | ||
value = "SLO Burn Rate Very High" | ||
} | ||
annotation { | ||
key = "description" | ||
value = "Error budget is burning too fast" | ||
} | ||
} | ||
|
||
slowburn { | ||
annotation { | ||
key = "name" | ||
value = "SLO Burn Rate High" | ||
} | ||
annotation { | ||
key = "description" | ||
value = "Error budget is burning too fast" | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
resource "grafana_slo" "test" { | ||
name = "Terraform Testing" | ||
description = "Terraform Description" | ||
query { | ||
grafana_queries { | ||
grafana_queries = jsonencode([ | ||
{ | ||
datasource : { | ||
"type" : "graphite", | ||
"uid" : "datasource-uid" | ||
}, | ||
refId : "Success", | ||
target : "groupByNode(perSecond(web.*.http.2xx_success.*.*), 3, 'avg')" | ||
}, | ||
{ | ||
datasource : { | ||
"type" : "graphite", | ||
"uid" : "datasource-uid" | ||
}, | ||
refId : "Total", | ||
target : "groupByNode(perSecond(web.*.http.5xx_errors.*.*), 3, 'avg')" | ||
}, | ||
{ | ||
datasource : { | ||
"type" : "__expr__", | ||
"uid" : "__expr__" | ||
}, | ||
expression : "$Success / $Total", | ||
refId : "Expression", | ||
type : "math" | ||
} | ||
]) | ||
} | ||
type = "grafana_queries" | ||
} | ||
destination_datasource { | ||
uid = "grafanacloud-prom" | ||
} | ||
objectives { | ||
value = 0.995 | ||
window = "30d" | ||
} | ||
|
||
label { | ||
key = "slo" | ||
value = "terraform" | ||
} | ||
alerting { | ||
fastburn { | ||
annotation { | ||
key = "name" | ||
value = "SLO Burn Rate Very High" | ||
} | ||
annotation { | ||
key = "description" | ||
value = "Error budget is burning too fast" | ||
} | ||
} | ||
|
||
slowburn { | ||
annotation { | ||
key = "name" | ||
value = "SLO Burn Rate High" | ||
} | ||
annotation { | ||
key = "description" | ||
value = "Error budget is burning too fast" | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
praise: we've been meaning to swap / fix this for awhile. Not part of big-tent, but a good improvement