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

docs: Clarify alerts override #3

Merged
merged 1 commit into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
37 changes: 36 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,42 @@ module "cert_manager_rules" {

## Overriding definitions of Prometheus Alerting file

TODO
The alerts defined as [Prometheus Alerting rules] can be overridden without changing the input file.
If your Prometheus Alerting rules YAML contains an alert `alert: TooManyWriteErrors`, you can override it like this:

```hcl
module "cert_manager_rules" {
source = "github.com/mkilchhofer/terraform-grafana-prometheus-alerts"

prometheus_alerts_file_path = file("/path/to/alerts/cert-manager.yaml")
folder_uid = grafana_folder.test.uid
datasource_uid = grafana_data_source.prometheus.uid

# Overrides per alert
overrides = {
"TooManyWriteErrors" = {
alert_threshold = 1
is_paused = true

labels = {
mycustomlabel = "foobar" # Add an extra label
severity = "notify" # Override severity
}
}
}
}
```

Every alert supports the following overrides:

| Override parameter | Type | Description |
|--------------------|---------------|-------------|
| `alert_threshold` | `number` | Threshold of the Grafana alert. Defaults to `0` |
| `exec_err_state` | `string` | Describes what state to enter when the rule's query is invalid and the rule cannot be executed. Options are `OK`, `Error`, `KeepLast`, and `Alerting`. Defaults to `Error`. |
| `is_paused` | `bool` | Sets whether the alert should be paused or not. Defaults to `false`. |
| `no_data_state` | `string` | Describes what state to enter when the rule's query returns No Data. Options are `OK`, `NoData`, `KeepLast`, and `Alerting`. Defaults to `OK`. |
| `labels` | `map(string)` | Extra labels to add. It is also possible to override already defined labels like `severity`. |


## TF module documentation

Expand Down
4 changes: 2 additions & 2 deletions grafana_alert.tf
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ resource "grafana_rule_group" "this" {
annotations = {for k, v in rule.value.annotations : k => replace(v, "$value", "$values.QUERY_RESULT.Value")}
labels = merge(rule.value.labels, try(var.overrides[rule.value.alert].labels, {}))

exec_err_state = try(var.overrides[rule.value.alert].exec_err_state, null)
exec_err_state = try(var.overrides[rule.value.alert].exec_err_state, "Error")
is_paused = try(var.overrides[rule.value.alert].is_paused, null)
no_data_state = try(var.overrides[rule.value.alert].no_data_state, null)
no_data_state = try(var.overrides[rule.value.alert].no_data_state, "OK")

data {
ref_id = "QUERY"
Expand Down
Loading