Skip to content

Improve Issue Alert Resource DSL #529

@jianyuan

Description

@jianyuan

There have been multiple reports highlighting difficulties in configuring issue alert conditions, filters, and actions directly using JSON. The challenges primarily stem from limitations in the way the Sentry API currently functions:

  1. Lack of JSON Validation: JSON inputs provided by users are not validated adequately by the provider, leading to potential errors during configuration.
  2. Type Mismatches: Some inputs require integers to be passed via the API but are returned as strings in the response. This discrepancy necessitates complex and error-prone fuzzy matching logic to ensure compatibility.
  3. Extra Fields in API Responses: The Sentry API often returns additional fields that are not part of the input schema. These fields introduce discrepancies and complicate Terraform's matching logic, making it harder to detect and manage changes effectively.
  4. dynamic_form_fields: Some actions require dynamic_form_fields to be set. They must be set to anything truthy and is not validated.

Proposed Solution:

To address these issues, I propose introducing a new structure for defining issue alerts using a well-defined Terraform resource. This approach leverages Terraform's attribute-based configuration to improve usability, validation, and maintainability. Below is an example of the proposed syntax:

resource "sentry_issue_alert" "test" {
  organization = sentry_project.test.organization
  project      = sentry_project.test.id
  name         = "%[3]s"
  action_match = "any"
  filter_match = "any"
  frequency    = 30

  # Conditions

  condition {
    first_seen_event {}
  }

  condition {
    regression_event {}
  }

  condition {
    event_frequency {
      value    = 500
      interval = "1h"
    }
  }

  condition {
    event_unique_user_frequency {
      value    = 1000
      interval = "15m"
    }
  }

  condition {
    event_frequency_percent {
      value    = 50.0
      interval = "10m"
    }
  }

  # Filters

  filter {
    age_comparison {
      comparison_type = "older"
      value           = 10
      time            = "minute"
    }
  }

  # Actions

  action {
    notify_email {
      target_type      = "IssueOwners"
      fallthrough_type = "ActiveMembers"
    }
  }

  action {
    notify_email {
      target_type       = "Team"
      target_identifier = sentry_team.test.internal_id
      fallthrough_type  = "AllMembers"
    }
  }

  action {
    slack_notify_service {
      workspace = data.sentry_organization_integration.slack.id
      channel   = "#general"
      tags      = "environment,level"
      notes     = "Please <http://example.com|click here> for triage information"
    }
  }

  action {
    github_create_ticket {
      integration = data.sentry_organization_integration.github.id
      repo        = "terraform-provider-sentry"
      title       = "My Test Issue"
      assignee    = "jianyuan"
      labels      = ["bug", "enhancement"]
    }
  }

  action {
    azure_devops_create_ticket {
      integration    = data.sentry_organization_integration.vsts.id
      project        = "123"
      work_item_type = "Microsoft.VSTS.WorkItemTypes.Task"
    }
  }

  action {
    pagerduty_notify_service {
      account  = sentry_integration_pagerduty.pagerduty.integration_id
      service  = sentry_integration_pagerduty.pagerduty.id
      severity = "default"
    }
  }

  action {
    opsgenie_notify_team {
      account  = sentry_integration_opsgenie.opsgenie.integration_id
      team     = sentry_integration_opsgenie.opsgenie.id
      priority = "P1"
    }
  }

  action {
    notify_event {}
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions