variable "environment" {
  description = "Name of the environment, e.g. dev, qa, prod"
  default     = "dev"
}

variable "service_name" {
  description = "Name of service"
  default     = "service name"
}

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

variable "process_name" {
  description = "Name of process inside of service to monitor"
}

variable "multi_alert_enabled" {
  description = "Set to true, to enable alerts for the process across all hosts in environment"
  default     = false
}

variable "tag_based_alert_enabled" {
  description = "Set to true to enable alerts for process based on a specific tag"
  default     = false
}

variable "hostname" {
  description = "Hostname for datadog to monitor"
  default     = ""
}

variable "monitor_measurement_interval" {
  type        = string
  description = "Measurement interval for monitor query"
  default     = "5m"
}

variable "host_multi_alert_query" {
  description = "Query string for process monitoring across hosts in environment"
  default     = "processes('%s').over('environment:%s').by('host').rollup('count').last('%s') < %s"
}

variable "host_simple_alert_query" {
  description = "Query string for process monitoring on one host"
  default     = "processes('%s').over('environment:%s,host:%s').rollup('count').last('%s') < %s"
}

variable "tag_based_alert_query" {
  description = "Query string for process monitoring based on tags"
  default     = "processes('%s').over('%s').rollup('count').last('%s') < %s"
}

variable "process_query_tags" {
  type        = string
  description = "Key-value pairs, separated by commas, of tags to restrict process queries. "
  default     = "service_name:ows-service,environment:dev"
}

variable "threshold_warning" {
  description = "Sets threshold for when to alert warning"
  default     = 2
}

variable "threshold_critical" {
  description = "Sets threshold for when to alert critical"
  default     = 1
}

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

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

locals {
  tags = flatten([
    "env:${var.environment}",
    "environment:${var.environment}",
    "service:${var.service_name}",
    "service_name:${var.service_name}",
    "process_name:${replace(var.process_name, "/\\.[a-z]+/", "")}",
    [for team in var.teams : "team:${team}"],
  ])
}
