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

variable "service_name" {
  description = "Service name, without environment prefix"
  default     = "lambda-name"
}

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

# AWS variables
variable "aws_region" {
  description = "AWS region from which to pull metrics"
  default     = "us-east-1"
}

# Error monitor variables
variable "lambda_error_monitor_enabled" {
  description = "Whether or not to enable error monitor"
  default     = true
}

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"
}

variable "lambda_error_ok_number" {
  description = "Number representing OK status"
  default     = 0
}

variable "lambda_error_warning_number" {
  description = "Number representing warning status"
  default     = 8
}

variable "lambda_error_warning_recovery_number" {
  description = "Number representing warning recovery status"
  default     = 5
}

variable "lambda_error_critical_number" {
  description = "Number representing critical status"
  default     = 10
}

variable "lambda_error_critical_recovery_number" {
  description = "Number representing critical recovery status"
  default     = 7
}

variable "lambda_error_critical_operator" {
  description = "Representing operator to generate lambda error"
  default     = ">="
}

# Error invocation variables
variable "lambda_invocation_monitor_enabled" {
  description = "Whether or not to enable invocation monitor"
  default     = true
}

# Throttle variables
variable "lambda_throttle_monitor_enabled" {
  description = "Whether or not to enable throttle monitor"
  default     = false
}

variable "lambda_throttle_time" {
  description = "Represent the lambda throttle time"
  default     = "last_1h"
}

variable "lambda_throttle_warning_number" {
  description = "Number of throttle warning alerts"
  default     = 0.5
}

variable "lambda_throttle_warning_recovery_number" {
  description = "Number representing throttle warning recovery status"
  default     = 0.3
}

variable "lambda_throttle_critical_number" {
  description = "Number of throttle critical alerts"
  default     = 1
}

variable "lambda_throttle_critical_recovery_number" {
  description = "Number of throttle critical recovery alerts"
  default     = 0.1
}

variable "lambda_throttle_ok_number" {
  description = "Number of throttle that are ok"
  default     = 0
}

variable "lambda_invocation_time" {
  description = "Represent the lambda invocation time"
  default     = "last_15m"
}

variable "lambda_invocation_operator" {
  description = "Representing operator to compare lambda invocations"
  default     = "<"
}

variable "lambda_invocation_count" {
  description = "Representing count of lambda invocation"
  default     = 1
}

variable "ok_invocation_number" {
  description = "Number of invocations that are ok"
  default     = 1
}

variable "critical_invocation_number" {
  description = "Number of critical alerts"
  default     = 0.5
}

variable "critical_recovery_invocation_number" {
  description = "Number for critical recovery"
  default     = 0.6
}

variable "invocation_warning_number" {
  description = "Number for warnings"
  default     = 0.7
}

variable "invocation_warning_recovery_number" {
  description = "Number for warning recovery"
  default     = 0.8
}

#Anomoly monitor
variable "lambda_anomaly_monitor_enabled" {
  description = "Whether or not to enable throttle monitor"
  default     = "false"
}

variable "lambda_anomaly_time" {
  description = "Represent the lambda throttle time"
  default     = "last_1h"
}

variable "lambda_duration_pxx" {
  description = "Measures the pxx(p50) elapsed wall clock time from when the function code starts executing as a result of an invocation to when it stops executing"
  default     = "50"
}

variable "lambda_anomaly_algorithm" {
  description = "The anomaly detection algorithm (basic, agile, or robust)"
  default     = "basic"
}

variable "lambda_anomaly_deviations" {
  description = "Controls the sensitivity of the anomaly detection."
  default     = "3"
}

variable "lambda_anomaly_direction" {
  description = "Represent the directionality (above, below, both) of anomalies that should trigger an alert"
  default     = "both"
}

variable "lambda_anomaly_rollup_interval" {
  description = "Represents the interval of time your data is aggregated over"
  default     = "60"
}

variable "lambda_anomaly_alert_window" {
  description = "The timeframe to be checked for anomalies"
  default     = "last_1h"
}

variable "lambda_anomaly_seasonality" {
  description = "Represent the hostorical data time. A weekly seasonality requires at least two weeks of data"
  default     = "weekly"
}

variable "lambda_anomaly_critical_number" {
  description = "Number of critical alerts"
  default     = "1"
}

variable "lambda_anomaly_operator" {
  description = "Representing operator to compare anomalies"
  default     = ">="
}

variable "lambda_anomaly_ok_number" {
  default = "0"
}

variable "lambda_anomaly_warning_number" {
  default = "0.7"
}

variable "lambda_anomaly_warning_recovery_number" {
  default = "0.5"
}

variable "lambda_anomaly_critical_recovery_number" {
  default = "0.8"
}

#Max Memory Usage monitor
variable "lambda_max_memory_used_enabled" {
  description = "Whether or not to enable max memory used monitor"
  default     = "false"
}

variable "lambda_max_memory_usage_ok_number" {
  description = "Percentage of max memory size used over last 15m that are ok"
  default     = 30
}

variable "lambda_max_memory_usage_critical_number" {
  description = "Percentage of max memory size used over last 15m that are critical"
  default     = 85
}

variable "lambda_max_memory_usage_warning_number" {
  description = "Percentage of max memory size used over last 15m that represents warning status"
  default     = 50
}

variable "lambda_max_memory_usage_warning_recovery_number" {
  description = "Percentage of max memory size used over last 15m that represents warning recovery status"
  default     = 40
}

variable "lambda_max_memory_usage_critical_recovery_number" {
  description = "Percentage of max memory size used over last 15m that represents critical recovery status"
  default     = 65
}

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:${var.service_name}",
    "service_name:${var.service_name}",
    [for team in var.teams : "team:${team}"],
  ])
}

variable "lambda_no_data_notification" {
    description = "enable/disable notification when there is no data available"
    default = false
}

variable "lambda_no_data_timeframe" {
    description = "timeframe for missing data"
    default = 10
}
