Skip to content
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

Merged
merged 50 commits into from
Mar 11, 2025
Merged
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
97b18b9
feat(bigTent slo): Custom Validate function for big tent SLO schema
Leo-DiCara Jan 31, 2025
ab44728
Merge branch 'main' into ld/big_tent_validate
Leo-DiCara Jan 31, 2025
4231bd0
feat(bigTent slo): Tests for custom validate functions
Leo-DiCara Feb 1, 2025
fa7583a
Merge branch 'ld/big_tent_validate' of github.com:grafana/terraform-p…
Leo-DiCara Feb 1, 2025
f514eb0
feat(bigTent slo): fmt
Leo-DiCara Feb 3, 2025
1efd39b
feat(bigTent slo): removing derpecated reliance
Leo-DiCara Feb 3, 2025
2c6b7c9
feat(bigTent slo): fmt
Leo-DiCara Feb 3, 2025
7da58a2
feat(bigTent slo): fmt
Leo-DiCara Feb 3, 2025
b16d7d6
Merge branch 'main' into ld/big_tent_validate
Leo-DiCara Feb 3, 2025
9697dc6
feat(bigTent slo): fix overzealous id refactor
Leo-DiCara Feb 3, 2025
73ebdf2
Merge branch 'ld/big_tent_validate' of github.com:grafana/terraform-p…
Leo-DiCara Feb 3, 2025
6b77ed8
feat(bigTent slo): ignore http redirect for link checker
Leo-DiCara Feb 4, 2025
964ddd4
Merge branch 'main' into ld/big_tent_validate
Leo-DiCara Feb 4, 2025
9dcb2f6
feat(bigTent slo): Drop warning on Prometheus queries
Leo-DiCara Feb 7, 2025
ffecf7e
Merge branch 'ld/big_tent_validate' of github.com:grafana/terraform-p…
Leo-DiCara Feb 7, 2025
6df417a
Merge branch 'main' into ld/big_tent_validate
Leo-DiCara Feb 7, 2025
e60b741
chore(bigTent slo): WIP update documentation
Leo-DiCara Feb 10, 2025
26d9371
Merge branch 'ld/big_tent_validate' of github.com:grafana/terraform-p…
Leo-DiCara Feb 11, 2025
4881fef
chore(bigTent slo): update documentation
Leo-DiCara Feb 11, 2025
a392c84
chore(bigTent slo): update documentation
Leo-DiCara Feb 11, 2025
ac83149
chore(bigTent slo): update documentation
Leo-DiCara Feb 11, 2025
ffd495b
chore(doc links): fixing terraform provider doc links
Leo-DiCara Feb 11, 2025
6fab993
chore(doc links): fixing terraform provider doc links
Leo-DiCara Feb 11, 2025
7341ebe
chore(doc links): fixing terraform provider doc links
Leo-DiCara Feb 11, 2025
e8877fa
chore(slo provider): update to new query type
Leo-DiCara Feb 18, 2025
ad17b07
Merge branch 'main' into ld/big_tent_validate
Leo-DiCara Feb 18, 2025
c1c19e9
chore(slo provider): fixing grafana_queries for tf format
Leo-DiCara Feb 18, 2025
3c90dc7
chore(slo provider): docs
Leo-DiCara Feb 18, 2025
b0ee9a4
chore(slo provider): update failure for prometheus queries in grafana…
Leo-DiCara Feb 18, 2025
6a566c4
chore(slo provider): fmt
Leo-DiCara Feb 18, 2025
100c49a
chore(slo provider): remove from ratio queries
Leo-DiCara Feb 20, 2025
d87e532
chore(slo provider): fix tf provider
Leo-DiCara Feb 21, 2025
c699182
chore(slo provider): fix plan from state
Leo-DiCara Feb 22, 2025
1826846
chore(slo provider): docs
Leo-DiCara Feb 22, 2025
d876c5e
chore(slo provider): remove println
Leo-DiCara Feb 24, 2025
60500ab
chore(slo provider): name change
Leo-DiCara Feb 25, 2025
112527c
chore(slo provider): PR comments
Leo-DiCara Feb 26, 2025
07f17f0
chore(slo provider): PR comments
Leo-DiCara Feb 26, 2025
3b4c723
Merge branch 'main' into ld/big_tent_validate
Leo-DiCara Feb 26, 2025
f713293
chore(slo provider): fixing fmt
Leo-DiCara Feb 26, 2025
4eeafbc
chore(slo provider): fixing fmt
Leo-DiCara Feb 26, 2025
df4df41
chore(slo provider): add graphite bad format test
Leo-DiCara Feb 26, 2025
4c1c8a9
chore(slo provider): add graphite bad format test
Leo-DiCara Feb 26, 2025
5bf0f28
chore(slo provider): fix graphite uid
Leo-DiCara Feb 26, 2025
26f2a1a
chore(slo provider): fix graphite uid
Leo-DiCara Feb 26, 2025
a5bc2b2
chore(slo provider): fix expected error message.
Leo-DiCara Feb 26, 2025
dc3c477
chore(slo provider): Rewording errors
Leo-DiCara Feb 28, 2025
e240570
chore(slo provider): Rewording errors
Leo-DiCara Feb 28, 2025
60a49ea
chore(slo provider): fmt
Leo-DiCara Feb 28, 2025
6710ea9
chore(slo provider): pr suggestions
Leo-DiCara Feb 28, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions docs/data-sources/slos.md
Original file line number Diff line number Diff line change
@@ -214,6 +214,7 @@ Read-Only:
Read-Only:

- `freeform` (List of Object) (see [below for nested schema](#nestedobjatt--slos--query--freeform))
- `grafana_queries` (List of Object) (see [below for nested schema](#nestedobjatt--slos--query--grafana_queries))
- `ratio` (List of Object) (see [below for nested schema](#nestedobjatt--slos--query--ratio))
- `type` (String)

@@ -225,6 +226,14 @@ Read-Only:
- `query` (String)


<a id="nestedobjatt--slos--query--grafana_queries"></a>
### Nested Schema for `slos.query.grafana_queries`

Read-Only:

- `grafana_queries` (String)


<a id="nestedobjatt--slos--query--ratio"></a>
### Nested Schema for `slos.query.ratio`

127 changes: 105 additions & 22 deletions docs/resources/slo.md
Original file line number Diff line number Diff line change
@@ -17,7 +17,58 @@ Resource manages Grafana SLOs.

## Example Usage

### Basic
### Ratio

```terraform
Copy link
Contributor

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

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([
Copy link
Contributor

@elainevuong elainevuong Feb 25, 2025

Choose a reason for hiding this comment

The 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 Success and Total RefIDs, so it's easier for users to follow along? the example currently used looks to be a non-standard SLO that we had used for initial testing

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')"
  },
  {
    "datasource": {
      "type": "__expr__",
      "uid": "__expr__"
    },
    "expression": "$Success / $Total",
    "refId": "Expression",
    "type": "math"
  }
]

{
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
Copy link
Contributor

Choose a reason for hiding this comment

The 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

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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>
96 changes: 96 additions & 0 deletions examples/resources/grafana_slo/resource_appDynamics.tf
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"
}
}
}
}
71 changes: 71 additions & 0 deletions examples/resources/grafana_slo/resource_graphite.tf
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"
}
}
}
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ require (
github.com/grafana/grafana-openapi-client-go v0.0.0-20241113095943-9cb2bbfeb8a3
github.com/grafana/machine-learning-go-client v0.8.2
github.com/grafana/river v0.3.0
github.com/grafana/slo-openapi-client/go/slo v0.0.0-20240807172758-1b7d00838fc7
github.com/grafana/slo-openapi-client/go/slo v0.0.0-20250218172929-ab9cae090da6
github.com/grafana/synthetic-monitoring-agent v0.34.2
github.com/grafana/synthetic-monitoring-api-go-client v0.11.0
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
Loading