Skip to content

Commit

Permalink
feat: Support events type on alerts. (#237)
Browse files Browse the repository at this point in the history
  • Loading branch information
eugeniykurasov authored Dec 9, 2022
1 parent 1d8d875 commit 341bc70
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/resources/metric_alert.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ resource "sentry_metric_alert" "main" {

- `dataset` (String) The Sentry Alert category
- `environment` (String) Perform Alert rule in a specific environment
- `event_types` (List of String) The events type of dataset.
- `owner` (String) Specifies the owner id of this Alert rule
- `resolve_threshold` (Number) The value at which the Alert rule resolves

Expand Down
14 changes: 14 additions & 0 deletions sentry/resource_sentry_metric_alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ func resourceSentryMetricAlert() *schema.Resource {
Optional: true,
Description: "The Sentry Alert category",
},
"event_types": {
Description: "The events type of dataset.",
Type: schema.TypeList,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"query": {
Type: schema.TypeString,
Required: true,
Expand Down Expand Up @@ -175,6 +183,12 @@ func resourceSentryMetricAlertObject(d *schema.ResourceData) *sentry.MetricAlert
if v, ok := d.GetOk("project"); ok {
alert.Projects = []string{v.(string)}
}
if v, ok := d.GetOk("event_types"); ok {
eventTypes := expandStringList(v.([]interface{}))
if len(eventTypes) > 0 {
alert.EventTypes = eventTypes
}
}

triggersIn := d.Get("trigger").([]interface{})
alert.Triggers = expandMetricAlertTriggers(triggersIn)
Expand Down
2 changes: 2 additions & 0 deletions sentry/resource_sentry_metric_alert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func TestAccSentryMetricAlert_basic(t *testing.T) {
resource.TestCheckResourceAttr(rn, "name", alertName),
resource.TestCheckResourceAttr(rn, "environment", ""),
resource.TestCheckResourceAttr(rn, "dataset", "transactions"),
resource.TestCheckTypeSetElemNestedAttrs(rn, "event_types", map[string]string{"*": "transaction"}),
resource.TestCheckResourceAttr(rn, "query", "http.url:http://testservice.com/stats"),
resource.TestCheckResourceAttr(rn, "aggregate", "p50(transaction.duration)"),
resource.TestCheckResourceAttr(rn, "time_window", "50"),
Expand Down Expand Up @@ -121,6 +122,7 @@ resource "sentry_metric_alert" "test" {
project = sentry_project.test.id
name = "%[1]s"
dataset = "transactions"
event_types = ["transaction"]
query = "http.url:http://testservice.com/stats"
aggregate = "p50(transaction.duration)"
time_window = 50.0
Expand Down

0 comments on commit 341bc70

Please sign in to comment.