resource "datadog_monitor" "ows-grass-public-5xx-anomaly-detection" {
  message             = <<-EOT
{{#is_alert}}The ows-grass-public 5xx monitor warning and critical alerts are to noisy. This monitor is to add anomaly detection instead of threshold based alerts{{/is_alert}}
EOT
  name                = "prod-ows-grass-public anomaly detection monitor"
  type                = "query alert"
  escalation_message  = "Escalation to ${var.application_alert_channel}"
  query               = "sum(last_1h):anomalies(sum:aws.applicationelb.httpcode_target_5xx{service_name:ows-grass-public, environment:prod}, 'robust', 2, direction='above', interval=3600, alert_window='last_1h', count_default_zero='true') >= ${var.datadog_monitor_threshold}"
  notify_no_data      = false
  renotify_interval   = 60
  evaluation_delay    = "300"
  timeout_h           = "0"
  include_tags        = true
  require_full_window = true
  notify_audit        = false
  monitor_thresholds {
    critical = var.datadog_monitor_threshold
    warning  = 0
  }

  tags = [
    "environment  = ${var.environment}",
    "service_name = ${var.service_name}",
    "application_family:user-platform"
  ]
}
