# General settings
variable "environment" {
  type        = string
  description = "Name of environment, e.g. dev, qa, prod"
  default     = "dev"
}

variable "teams" {
  type        = set(string)
  description = "A set of Datadog Teams to associate the resources with"
  default     = []
}

variable "host_name" {
  type        = string
  description = "Name of host to monitor"
}

variable "mysql_socket_file" {
  type        = string
  description = "Location of MySQL socket file for connection check"
  default     = "/mnt/data/mysql/mysql.sock"
}

# Booleans to control features and resource creation
variable "mysql_disk_space_monitor_enabled" {
  type        = bool
  description = "Whether or not MySQL host disk space monitor is enabled"
  default     = true
}

variable "mysql_availability_monitor_enabled" {
  type        = bool
  description = "Whether or not MySQL availability monitor is enabled"
  default     = true
}

variable "mysql_memory_monitor_enabled" {
  type        = bool
  description = "Whether or not MySQL host memory monitor is enabled"
  default     = true
}

variable "mysql_cpu_monitor_enabled" {
  type        = bool
  description = "Whether or not MySQL host CPU monitor is enabled"
  default     = true
}

variable "mysql_connection_monitor_enabled" {
  type        = bool
  description = "Whether or not MySQL connection monitor is enabled"
  default     = true
}

variable "mysql_slow_queries_monitor_enabled" {
  type        = bool
  description = "Whether or not MySQL slow queries monitor is enabled"
  default     = true
}

variable "mysql_dashboard_enabled" {
  type        = bool
  description = "Whether or not MySQL dashboard is enabled"
  default     = true
}

variable "ebs_widgets_enabled" {
  type        = bool
  description = "Whether EBS widgets are enabled in dashboard. Set to true when using EBS volumes"
  default     = false
}

variable "mysql_replica_lag_monitor_enabled" {
  type        = bool
  description = "Whether or not MySQL replica lag monitor is enabled"
  default     = false
}

# Disk settings
variable "mysql_data_volume_device_name" {
  type        = string
  description = "Name of device used as MySQL data volume"
  default     = "/dev/sdb1"
}

variable "mysql_system_disk_device_name" {
  type        = string
  description = "Name of device used as host system disk"
  default     = "/dev/sda1"
}

variable "mysql_data_volume_ebs_volume_id" {
  type        = string
  description = "Volume ID for EBS volume used as MySQL data volume. Only applicable when using EBS"
  default     = null
}

# Monitor thresholds

# Disk utilization
variable "measurement_interval_disk_utilization" {
  description = "Measurement interval for disk space utilization percentage alerts"
  default     = "last_5m"
}

variable "critical_number_disk_utilization" {
  description = "Disk space utilization percentage for critical alerts"
  default     = 95
}

variable "critical_recovery_number_disk_utilization" {
  description = "Disk space utilization percentage for critical recovery"
  default     = 90
}

variable "warning_number_disk_utilization" {
  description = "Disk space utilization percentage for warnings"
  default     = 85
}

variable "warning_recovery_number_disk_utilization" {
  description = "Disk space utilization percentage for warning recovery"
  default     = 80
}

variable "ok_number_disk_utilization" {
  description = "Disk space utilization percentage that is ok"
  default     = 75
}

# Availability
variable "critical_number_availability" {
  description = "The number of consecutive connection failures to trigger the availability monitor"
  default     = 1
}

variable "ok_number_availability" {
  description = "The number of consecutive connection successes to resolve the availability monitor"
  default     = 1
}

# Memory
variable "measurement_interval_memory" {
  description = "Measurement interval for memory utilization alerts"
  default     = "last_5m"
}

variable "critical_number_memory" {
  description = "Memory utilization percentage for critical alerts"
  default     = 98
}

variable "critical_recovery_number_memory" {
  description = "Memory utilization percentage for critical recovery"
  default     = 95
}

variable "warning_number_memory" {
  description = "Memory utilization percentage for warnings"
  default     = 92
}

variable "warning_recovery_number_memory" {
  description = "Memory utilization percentage for warning recovery"
  default     = 90
}

variable "ok_number_memory" {
  description = "Memory utilization percentage that is ok"
  default     = 89
}

# CPU
variable "measurement_interval_cpu" {
  description = "Measurement interval for CPU utilization alerts"
  default     = "last_5m"
}

variable "critical_number_cpu" {
  description = "CPU utilization percentage for critical alerts"
  default     = 95
}

variable "critical_recovery_number_cpu" {
  description = "CPU utilization percentage for critical recovery"
  default     = 90
}

variable "warning_number_cpu" {
  description = "CPU utilization percentage for warnings"
  default     = 85
}

variable "warning_recovery_number_cpu" {
  description = "CPU utilization percentage for warning recovery"
  default     = 80
}

variable "ok_number_cpu" {
  description = "CPU utilization percentage that is ok"
  default     = 75
}

# MySQL connections
variable "measurement_interval_connections" {
  description = "Measurement interval for connection utilization percentage alerts"
  default     = "last_5m"
}

variable "critical_number_connections" {
  description = "Connection utilization percentage for critical alerts"
  default     = 95
}

variable "critical_recovery_number_connections" {
  description = "Connection utilization percentage for critical recovery"
  default     = 90
}

variable "warning_number_connections" {
  description = "Connection utilization percentage for warnings"
  default     = 85
}

variable "warning_recovery_number_connections" {
  description = "Connection utilization percentage for warning recovery"
  default     = 80
}

variable "ok_number_connections" {
  description = "Connection utilization percentage that is ok"
  default     = 75
}

# Slow queries
variable "measurement_interval_slow_queries" {
  description = "Measurement interval for slow queries count alerts"
  default     = "last_5m"
}

variable "critical_number_slow_queries" {
  description = "Slow query count for critical alerts"
  default     = 25
}

variable "critical_recovery_number_slow_queries" {
  description = "Slow query count for critical recovery"
  default     = 20
}

variable "warning_number_slow_queries" {
  description = "Slow query count for warnings"
  default     = 15
}

variable "warning_recovery_number_slow_queries" {
  description = "Slow query count for warning recovery"
  default     = 10
}

variable "ok_number_slow_queries" {
  description = "Slow query count that is ok"
  default     = 5
}

# Replication lag
 variable "measurement_interval_replica_lag" {
   description = "Measurement interval for replica lag alerts"
   default     = "last_5m"
 }

variable "critical_seconds_replica_lag" {
  description = "Replica lag seconds for critical alerts"
  default     = 1800
}

variable "critical_recovery_seconds_replica_lag" {
  description = "Replica lag seconds for critical recovery"
  default     = 900
}

variable "warning_seconds_replica_lag" {
  description = "Replica lag seconds for warnings"
  default     = 900
}

variable "warning_recovery_seconds_replica_lag" {
  description = "Replica lag seconds for warning recovery"
  default     = 60
}

variable "ok_seconds_replica_lag" {
  description = "Replica lag seconds that is ok"
  default     = 5
}


# Notification settings
variable "notification_endpoints" {
  type        = string
  description = "Endpoints to send all notifications to. Can be email, slack, pagerduty, etc"
  default     = "@slack-monitoring"
}

variable "escalation_notification_endpoints" {
  type        = string
  description = "Endpoints for escalation alerts. Can be email, slack, pagerduty, etc"
  default     = "@slack-monitoring"
}

variable "alert_notification_endpoints" {
  type        = string
  description = "Additional endpoints to send only alert notifications to. Can be email, slack, pagerduty, etc."
  default     = ""
}

variable "no_data_notification_endpoints" {
  type        = string
  description = "Additional endpoints to send only no data notifications to. Can be email, slack, pagerduty, etc."
  default     = ""
}

locals {
  # Only team tags are supported for dashboards
  dashboard_tags = [for team in var.teams : "team:${team}"]

  tags = flatten([
    "env:${var.environment}",
    "environment:${var.environment}",
    "service:mysql",
    "service_name:mysql",
    [for team in var.teams : "team:${team}"],
  ])
}
