From 303fffc00c10238a2c3778575d7bbea152973b48 Mon Sep 17 00:00:00 2001 From: Jean-Philippe LAINE Date: Tue, 14 Jan 2020 16:00:31 +0100 Subject: [PATCH] MON-554 - Add first version of Velero monitors --- caas/kubernetes/velero/inputs.tf | 206 ++++++++++++++++++++++ caas/kubernetes/velero/modules.tf | 19 ++ caas/kubernetes/velero/monitors-velero.tf | 169 ++++++++++++++++++ caas/kubernetes/velero/outputs.tf | 24 +++ 4 files changed, 418 insertions(+) create mode 100644 caas/kubernetes/velero/inputs.tf create mode 100644 caas/kubernetes/velero/modules.tf create mode 100644 caas/kubernetes/velero/monitors-velero.tf create mode 100644 caas/kubernetes/velero/outputs.tf diff --git a/caas/kubernetes/velero/inputs.tf b/caas/kubernetes/velero/inputs.tf new file mode 100644 index 0000000..185744d --- /dev/null +++ b/caas/kubernetes/velero/inputs.tf @@ -0,0 +1,206 @@ +# Datadog global variables + +variable "environment" { + description = "Architecture environment" +} + +variable "filter_tags_use_defaults" { + description = "Use default filter tags convention" + default = "true" +} + +variable "filter_tags_custom" { + description = "Tags used for custom filtering when filter_tags_use_defaults is false" + default = "*" +} + +variable "filter_tags_custom_excluded" { + description = "Tags excluded for custom filtering when filter_tags_use_defaults is false" + default = "" +} + +variable "filter_tags_scheduled_backup_use_defaults" { + description = "Use default filter tags scheduled backup convention" + default = null +} + +variable "filter_tags_scheduled_backup_custom" { + description = "Tags used for scheduled backup custom filtering when filter_tags_scheduled_backup_use_defaults is false" + default = null +} + +variable "filter_tags_scheduled_backup_custom_excluded" { + description = "Tags excluded for scheduled backup custom filtering when filter_tags_scheduled_backup_use_defaults is false" + default = null +} + +variable "message" { + description = "Message sent when a monitor is triggered" +} + +variable "evaluation_delay" { + description = "Delay in seconds for the metric evaluation" + default = 15 +} + +variable "new_host_delay" { + description = "Delay in seconds before monitor new resource" + default = 300 +} + +variable "prefix_slug" { + description = "Prefix string to prepend between brackets on every monitors names" + default = "" +} + +variable "notify_no_data" { + description = "Will raise no data alert if set to true" + default = true +} + +# Datadog monitors variables + +variable "velero_scheduled_backup_missing_monitor_message" { + description = "Custom message for Velero scheduled backup missing monitor" + type = string + default = "" +} + +variable "velero_scheduled_backup_missing_monitor_timeframe" { + description = "Monitor timeframe for Velero scheduled backup missing monitor [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`]" + type = string + default = "last_1d" +} + +variable "velero_scheduled_backup_missing_enabled" { + description = "Flag to enable Velero scheduled backup missing monitor" + type = string + default = "true" +} + +variable "velero_scheduled_backup_missing_extra_tags" { + description = "Extra tags for Velero scheduled backup missing monitor" + type = list(string) + default = [] +} + +variable "velero_scheduled_backup_missing_monitor_no_data_timeframe" { + description = "No data timeframe in minutes" + default = 1440 +} + +variable "velero_backup_failure_monitor_message" { + description = "Custom message for Velero backup failure monitor" + type = string + default = "" +} + +variable "velero_backup_failure_monitor_timeframe" { + description = "Monitor timeframe for Velero backup failure monitor [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`]" + type = string + default = "last_1d" +} + +variable "velero_backup_failure_enabled" { + description = "Flag to enable Velero backup failure monitor" + type = string + default = "true" +} + +variable "velero_backup_failure_extra_tags" { + description = "Extra tags for Velero backup failure monitor" + type = list(string) + default = [] +} + +variable "velero_backup_failure_monitor_no_data_timeframe" { + description = "No data timeframe in minutes" + default = 1440 +} + +variable "velero_backup_partial_failure_monitor_message" { + description = "Custom message for Velero backup partial failure monitor" + type = string + default = "" +} + +variable "velero_backup_partial_failure_monitor_timeframe" { + description = "Monitor timeframe for Velero backup partial failure monitor [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`]" + type = string + default = "last_1d" +} + +variable "velero_backup_partial_failure_enabled" { + description = "Flag to enable Velero backup partial failure monitor" + type = string + default = "true" +} + +variable "velero_backup_partial_failure_extra_tags" { + description = "Extra tags for Velero backup partial failure monitor" + type = list(string) + default = [] +} + +variable "velero_backup_partial_failure_monitor_no_data_timeframe" { + description = "No data timeframe in minutes" + default = 1440 +} + +variable "velero_backup_deletion_failure_monitor_message" { + description = "Custom message for Velero backup deletion failure monitor" + type = string + default = "" +} + +variable "velero_backup_deletion_failure_monitor_timeframe" { + description = "Monitor timeframe for Velero backup deletion failure monitor [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`]" + type = string + default = "last_1d" +} + +variable "velero_backup_deletion_failure_enabled" { + description = "Flag to enable Velero backup deletion failure monitor" + type = string + default = "true" +} + +variable "velero_backup_deletion_failure_extra_tags" { + description = "Extra tags for Velero backup deletion failure monitor" + type = list(string) + default = [] +} + +variable "velero_backup_deletion_failure_monitor_no_data_timeframe" { + description = "No data timeframe in minutes" + default = 1440 +} + +variable "velero_volume_snapshot_failure_monitor_message" { + description = "Custom message for Velero volume snapshot failure monitor" + type = string + default = "" +} + +variable "velero_volume_snapshot_failure_monitor_timeframe" { + description = "Monitor timeframe for Velero volume snapshot failure monitor [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`]" + type = string + default = "last_1d" +} + +variable "velero_volume_snapshot_failure_enabled" { + description = "Flag to enable Velero volume snapshot failure monitor" + type = string + default = "true" +} + +variable "velero_volume_snapshot_failure_extra_tags" { + description = "Extra tags for Velero volume snapshot failure monitor" + type = list(string) + default = [] +} + +variable "velero_volume_snapshot_failure_monitor_no_data_timeframe" { + description = "No data timeframe in minutes" + default = 1440 +} diff --git a/caas/kubernetes/velero/modules.tf b/caas/kubernetes/velero/modules.tf new file mode 100644 index 0000000..106f227 --- /dev/null +++ b/caas/kubernetes/velero/modules.tf @@ -0,0 +1,19 @@ +module "filter-tags" { + source = "../../../common/filter-tags" + + environment = var.environment + resource = "velero" + filter_tags_use_defaults = var.filter_tags_use_defaults + filter_tags_custom = var.filter_tags_custom + filter_tags_custom_excluded = var.filter_tags_custom_excluded +} + +module "filter-tags-scheduled-backup" { + source = "../../../common/filter-tags" + + environment = var.environment + resource = "velero" + filter_tags_use_defaults = var.filter_tags_scheduled_backup_use_defaults != null ? var.filter_tags_scheduled_backup_use_defaults : var.filter_tags_use_defaults + filter_tags_custom = var.filter_tags_scheduled_backup_custom != null ? var.filter_tags_scheduled_backup_custom : var.filter_tags_custom + filter_tags_custom_excluded = var.filter_tags_scheduled_backup_custom_excluded != null ? var.filter_tags_scheduled_backup_custom_excluded : var.filter_tags_custom_excluded +} diff --git a/caas/kubernetes/velero/monitors-velero.tf b/caas/kubernetes/velero/monitors-velero.tf new file mode 100644 index 0000000..b341ac5 --- /dev/null +++ b/caas/kubernetes/velero/monitors-velero.tf @@ -0,0 +1,169 @@ +resource "datadog_monitor" "velero_scheduled_backup_missing" { + count = var.velero_scheduled_backup_missing_enabled == "true" ? 1 : 0 + name = "${var.prefix_slug == "" ? "" : "[${var.prefix_slug}]"}[${var.environment}] Velero scheduled backup missing" + type = "query alert" + message = coalesce(var.velero_scheduled_backup_missing_monitor_message, var.message) + + query = < 1 +EOQ + + thresholds = { + critical = 1 + warning = 0 + } + + evaluation_delay = var.evaluation_delay + new_host_delay = var.new_host_delay + no_data_timeframe = var.velero_backup_failure_monitor_no_data_timeframe + + notify_no_data = var.notify_no_data + renotify_interval = 0 + notify_audit = false + timeout_h = 0 + include_tags = true + locked = false + require_full_window = false + + tags = concat(["env:${var.environment}", "type:caas", "provider:prometheus", "resource:velero", "team:claranet", "created-by:terraform"], var.velero_backup_failure_extra_tags) + + lifecycle { + ignore_changes = [silenced] + } +} + +resource "datadog_monitor" "velero_backup_partial_failure" { + count = var.velero_backup_partial_failure_enabled == "true" ? 1 : 0 + name = "${var.prefix_slug == "" ? "" : "[${var.prefix_slug}]"}[${var.environment}] Velero backup partial failure" + type = "query alert" + message = coalesce(var.velero_backup_partial_failure_monitor_message, var.message) + + query = < 1 +EOQ + + thresholds = { + critical = 1 + warning = 0 + } + + evaluation_delay = var.evaluation_delay + new_host_delay = var.new_host_delay + no_data_timeframe = var.velero_backup_partial_failure_monitor_no_data_timeframe + + notify_no_data = var.notify_no_data + renotify_interval = 0 + notify_audit = false + timeout_h = 0 + include_tags = true + locked = false + require_full_window = false + + tags = concat(["env:${var.environment}", "type:caas", "provider:prometheus", "resource:velero", "team:claranet", "created-by:terraform"], var.velero_backup_partial_failure_extra_tags) + + lifecycle { + ignore_changes = [silenced] + } +} + +resource "datadog_monitor" "velero_backup_deletion_failure" { + count = var.velero_backup_deletion_failure_enabled == "true" ? 1 : 0 + name = "${var.prefix_slug == "" ? "" : "[${var.prefix_slug}]"}[${var.environment}] Velero backup deletion failure" + type = "query alert" + message = coalesce(var.velero_backup_deletion_failure_monitor_message, var.message) + + query = < 1 +EOQ + + thresholds = { + critical = 1 + warning = 0 + } + + evaluation_delay = var.evaluation_delay + new_host_delay = var.new_host_delay + no_data_timeframe = var.velero_backup_deletion_failure_monitor_no_data_timeframe + + notify_no_data = var.notify_no_data + renotify_interval = 0 + notify_audit = false + timeout_h = 0 + include_tags = true + locked = false + require_full_window = false + + tags = concat(["env:${var.environment}", "type:caas", "provider:prometheus", "resource:velero", "team:claranet", "created-by:terraform"], var.velero_backup_deletion_failure_extra_tags) + + lifecycle { + ignore_changes = [silenced] + } +} + +resource "datadog_monitor" "velero_volume_snapshot_failure" { + count = var.velero_volume_snapshot_failure_enabled == "true" ? 1 : 0 + name = "${var.prefix_slug == "" ? "" : "[${var.prefix_slug}]"}[${var.environment}] Velero volume snapshot failure" + type = "query alert" + message = coalesce(var.velero_volume_snapshot_failure_monitor_message, var.message) + + query = < 1 +EOQ + + thresholds = { + critical = 1 + warning = 0 + } + + evaluation_delay = var.evaluation_delay + new_host_delay = var.new_host_delay + no_data_timeframe = var.velero_volume_snapshot_failure_monitor_no_data_timeframe + + notify_no_data = var.notify_no_data + renotify_interval = 0 + notify_audit = false + timeout_h = 0 + include_tags = true + locked = false + require_full_window = false + + tags = concat(["env:${var.environment}", "type:caas", "provider:prometheus", "resource:velero", "team:claranet", "created-by:terraform"], var.velero_volume_snapshot_failure_extra_tags) + + lifecycle { + ignore_changes = [silenced] + } +} + diff --git a/caas/kubernetes/velero/outputs.tf b/caas/kubernetes/velero/outputs.tf new file mode 100644 index 0000000..1534cc9 --- /dev/null +++ b/caas/kubernetes/velero/outputs.tf @@ -0,0 +1,24 @@ +output "velero_scheduled_backup_missing_id" { + description = "id for monitor velero_scheduled_backup_missing" + value = datadog_monitor.velero_scheduled_backup_missing.*.id +} + +output "velero_backup_failure_id" { + description = "id for monitor velero_backup_failure" + value = datadog_monitor.velero_backup_failure.*.id +} + +output "velero_backup_partial_failure_id" { + description = "id for monitor velero_backup_partial_failure" + value = datadog_monitor.velero_backup_partial_failure.*.id +} + +output "velero_backup_deletion_failure_id" { + description = "id for monitor velero_backup_deletion_failure" + value = datadog_monitor.velero_backup_deletion_failure.*.id +} + +output "velero_volume_snapshot_failure_id" { + description = "id for monitor velero_volume_snapshot_failure" + value = datadog_monitor.velero_volume_snapshot_failure.*.id +}