resource "datadog_monitor" "snowflake_sync_failures" {
  name    = "[${var.environment}] Neo4j <-> Snowflake sync check failures"
  type    = "log alert"
  message = "Neo4j <-> Snowflake row-level sync check detected issues. Check logs for details.\n\nNotify: ${var.kdh_notification_endpoints}"

  # Catch any type of inconsistency between Neo4j and Snowflake
  query = "logs(\"service_name:${local.full_service_name} env:${var.environment} status:warn (missing_in_neo4j OR missing_in_snowflake OR field_mismatches OR mismatches OR mismatched)\").index(\"*\").rollup(\"count\").last(\"1h\") >= 100"

  # Threshold is set of sending Warning alert instead of Error
  monitor_thresholds {
    warning  = 1
    critical = 100
  }

  include_tags        = true
  notify_audit        = false
  notify_no_data      = false
  require_full_window = false
  renotify_interval   = 0
  timeout_h           = 24
}
