Skip to content

conditions_v2 event frequency value cannot be zero, "ensure all required fields are filled in" #575

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

Open
tedder opened this issue Feb 11, 2025 · 1 comment

Comments

@tedder
Copy link

tedder commented Feb 11, 2025

With conditions_v2, if I set value of event_frequency to zero, it fails:

│ Error: Client error
│ 
│   with sentry_issue_alert.app_staging,
│   on alerts.tf line 13, in resource "sentry_issue_alert" "app_staging":
│   13: resource "sentry_issue_alert" "app_staging" {
│ 
│ Unable to update, got status 400: {"conditions":["Ensure all required fields are filled in."]}

Here's a sample resource. It works if "value" is 1, fails if it's 0 or even "0".

resource "sentry_issue_alert" "app_staging" {
  organization = sentry_organization.org.id
  project      = sentry_project.app.id
  owner        = "team:${local.app_team_id}"
  name         = "alerts-app-staging"
  environment  = "staging"

  action_match = "any"
  filter_match = "all"
  frequency    = 1440

  conditions_v2 = [
    { first_seen_event = {} },
    {
      event_frequency = {
        value           = 0 # must be nonzero
        comparison_type = "count"
        interval        = "1h"
      },
    },
  ]
  actions_v2 = [
    {
      slack_notify_service = {
       ...
    }
  ]
}

If I set the value to zero in the UI and it is set to, say, one in terraform, it properly shows drift:

~ event_frequency = {
  ~ name            = "The issue is seen more than 0 times in 1h" -> (known after apply)
  ~ value           = 0 -> 1
  # (2 unchanged attributes hidden)
}

Using jianyuan/sentry version 0.14.3, terraform v1.9.5.

fajpunk added a commit to fajpunk/terraform-provider-sentry that referenced this issue Apr 8, 2025
fajpunk added a commit to fajpunk/terraform-provider-sentry that referenced this issue Apr 8, 2025
There is [arguably a bug in the Sentry API](https://github.com/getsentry/sentry/blob/7b8d66494904659365bbc0e5b37db029d72ef36d/src/sentry/api/serializers/rest_framework/rule.py#L40-L42) where integer values of 0 will be stripped from submitted payload objects because of Python's implicit bool conversions. These values can successfully be submitted as strings. When these objects are retrieved from the API, the values are integers.

To model this, we have two different schemas in the OpenAPI spec yaml for rule conditions based based on whether we're sending them to the API or retriving them from the API:
* `ProjectRuleCondition`, which is a set of condition schemas where `value`s are `integers`
* `ProjectRuleConditionToApi` which is a set of condition schemas where `value`s are strings

The generated types from these are used in the alert rule resource code in the `Fill` and `ToApi` methods as necessary.

There may be a way to do this without so much duplication, I am definitely open to suggestions!
fajpunk added a commit to fajpunk/terraform-provider-sentry that referenced this issue Apr 8, 2025
There is [arguably a bug in the Sentry API](https://github.com/getsentry/sentry/blob/7b8d66494904659365bbc0e5b37db029d72ef36d/src/sentry/api/serializers/rest_framework/rule.py#L40-L42) where integer values of 0 will be stripped from submitted payload objects because of Python's implicit bool conversions. These values can successfully be submitted as strings. When these objects are retrieved from the API, the values are integers.

To model this, we have two different schemas in the OpenAPI spec yaml for rule conditions based based on whether we're sending them to the API or retriving them from the API:
* `ProjectRuleCondition`, which is a set of condition schemas where `value`s are `integers`
* `ProjectRuleConditionToApi` which is a set of condition schemas where `value`s are strings

The generated types from these are used in the alert rule resource code in the `Fill` and `ToApi` methods as necessary.

There may be a way to do this without so much duplication, I am definitely open to suggestions!
@fajpunk
Copy link

fajpunk commented Apr 11, 2025

Seems like Sentry is not going to allow this in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants