resource "datadog_monitor" "lambda_iterator_age_monitor" {
  name    = "${var.environment}-${var.lambda_name}-iterator-age-monitor"
  type    = "query alert"
  message = "Monitor triggered. Notify: ${var.notification_endpoints}"

  query = "max(last_30m):max:aws.lambda.iterator_age.maximum{environment:${var.environment},service_name:${var.lambda_name}} >= 600000"

  monitor_thresholds {
    ok       = 5000
    warning = 300000  # 5 min
    critical = 600000 # 10 min
  }

  include_tags        = true
  notify_no_data      = false
  notify_audit        = false
  priority            = 2
  renotify_interval = 60  # 3 hrs
  timeout_h = 1
  # automatically resolves from a triggered state if there is no data for 1 hr
  require_full_window = false
  no_data_timeframe   = 0

  tags = [
    "environment:${var.environment}",
    "service_name:${var.lambda_name}",
    "application_family:${var.application_family}",
    "team:${var.team}",
  ]
}
