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

Add resources for creating ML managed alerts #1670

Merged
merged 8 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
64 changes: 64 additions & 0 deletions docs/resources/machine_learning_alert.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "grafana_machine_learning_alert Resource - terraform-provider-grafana"
subcategory: "Machine Learning"
description: |-

---

# grafana_machine_learning_alert (Resource)



## Example Usage

```terraform
resource "grafana_machine_learning_job" "test_alert_job" {
name = "Test Job"
metric = "tf_test_alert_job"
datasource_type = "prometheus"
datasource_uid = "abcd12345"
query_params = {
expr = "grafanacloud_grafana_instance_active_user_count"
}
}

resource "grafana_machine_learning_alert" "test_job_alert" {
job_id = grafana_machine_learning_job.test_alert_job.id
title = "Test Alert"
anomaly_condition = "any"
threshold = ">0.8"
window = "15m"
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `title` (String) The title of the alert.

### Optional

- `annotations` (Map of String) Annotations to add to the alert generated in Grafana.
- `anomaly_condition` (String) The condition for when to consider a point as anomalous.
- `for` (String) How long values must be anomalous before firing an alert.
- `job_id` (String) The forecast this alert belongs to.
- `labels` (Map of String) Labels to add to the alert generated in Grafana.
- `no_data_state` (String) How the alert should be processed when no data is returned by the underlying series
- `outlier_id` (String) The forecast this alert belongs to.
- `threshold` (String) The threshold of points over the window that need to be anomalous to alert.
- `window` (String) How much time to average values over

### Read-Only

- `id` (String) The ID of the alert.

## Import

Import is supported using the following syntax:

```shell
terraform import grafana_machine_learning_alert.name "{{ id }}"
```
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
terraform import grafana_machine_learning_alert.name "{{ id }}"
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
resource "grafana_machine_learning_outlier_detector" "test_alert_outlier_detector" {
name = "Test Outlier"

metric = "tf_test_alert_outlier"
datasource_type = "prometheus"
datasource_uid = "AbCd12345"
query_params = {
expr = "grafanacloud_grafana_instance_active_user_count"
}
interval = 300

algorithm {
name = "dbscan"
sensitivity = 0.5
config {
epsilon = 1.0
}
}
}

resource "grafana_machine_learning_alert" "test_outlier_alert" {
outlier_id = grafana_machine_learning_outlier_detector.test_alert_outlier_detector.id
title = "Test Alert"
window = "1h"
}
17 changes: 17 additions & 0 deletions examples/resources/grafana_machine_learning_alert/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
resource "grafana_machine_learning_job" "test_alert_job" {
name = "Test Job"
metric = "tf_test_alert_job"
datasource_type = "prometheus"
datasource_uid = "abcd12345"
query_params = {
expr = "grafanacloud_grafana_instance_active_user_count"
}
}

resource "grafana_machine_learning_alert" "test_job_alert" {
job_id = grafana_machine_learning_job.test_alert_job.id
title = "Test Alert"
anomaly_condition = "any"
threshold = ">0.8"
window = "15m"
}
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/grafana/amixr-api-go-client v0.0.12 // main branch
github.com/grafana/grafana-com-public-clients/go/gcom v0.0.0-20240322153219-42c6a1d2bcab
github.com/grafana/grafana-openapi-client-go v0.0.0-20240523010106-657d101fcbd9
github.com/grafana/machine-learning-go-client v0.7.0
github.com/grafana/machine-learning-go-client v0.8.0
github.com/grafana/slo-openapi-client/go v0.0.0-20240626093634-e6741482b090
github.com/grafana/synthetic-monitoring-agent v0.24.3
github.com/grafana/synthetic-monitoring-api-go-client v0.8.0
Expand All @@ -30,6 +30,7 @@ require (
github.com/hashicorp/terraform-plugin-go v0.23.0
github.com/hashicorp/terraform-plugin-mux v0.16.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.34.0
github.com/prometheus/common v0.53.0
github.com/stretchr/testify v1.9.0
github.com/tmccombs/hcl2json v0.6.3
github.com/urfave/cli/v2 v2.27.2
Expand Down Expand Up @@ -129,7 +130,6 @@ require (
github.com/posener/complete v1.2.3 // indirect
github.com/prometheus/client_golang v1.19.1 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.53.0 // indirect
github.com/prometheus/procfs v0.14.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/shopspring/decimal v1.3.1 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ github.com/grafana/grafana-openapi-client-go v0.0.0-20240523010106-657d101fcbd9
github.com/grafana/grafana-openapi-client-go v0.0.0-20240523010106-657d101fcbd9/go.mod h1:hiZnMmXc9KXNUlvkV2BKFsiWuIFF/fF4wGgYWEjBitI=
github.com/grafana/grafana-plugin-sdk-go v0.235.0 h1:UnZ/iBDvCkfDgwR94opi8trAWJXv4V8Qr1ocJKRRmqA=
github.com/grafana/grafana-plugin-sdk-go v0.235.0/go.mod h1:6n9LbrjGL3xAATntYVNcIi90G9BVHRJjzHKz5FXVfWw=
github.com/grafana/machine-learning-go-client v0.7.0 h1:yiRBg8rCNbHh9BURa+vtZ8ItRYvabbdYAtsAOfxoFPI=
github.com/grafana/machine-learning-go-client v0.7.0/go.mod h1:bKsLSJTreH7HXaL2FJnnrliMuP0L8XwMkXte6AgwFFg=
github.com/grafana/machine-learning-go-client v0.8.0 h1:N8+0f5aFM/umVJWvlJkJy9McVIp9MIBUtuNruug94II=
github.com/grafana/machine-learning-go-client v0.8.0/go.mod h1:9xRIoH6Y6RubuCPNjLfpckE/fLVe9dazg3HSLI1ARAU=
github.com/grafana/otel-profiling-go v0.5.1 h1:stVPKAFZSa7eGiqbYuG25VcqYksR6iWvF3YH66t4qL8=
github.com/grafana/otel-profiling-go v0.5.1/go.mod h1:ftN/t5A/4gQI19/8MoWurBEtC6gFw8Dns1sJZ9W4Tls=
github.com/grafana/pyroscope-go/godeltaprof v0.1.7 h1:C11j63y7gymiW8VugJ9ZW0pWfxTZugdSJyC48olk5KY=
Expand Down
Loading
Loading