diff --git a/README.md b/README.md index c6cf645..9c77a72 100644 --- a/README.md +++ b/README.md @@ -131,6 +131,7 @@ module "datadog-monitors-system-generic" { - [vts](https://github.com/claranet/terraform-datadog-monitors/tree/master/caas/kubernetes/ingress/vts/) - [node](https://github.com/claranet/terraform-datadog-monitors/tree/master/caas/kubernetes/node/) - [pod](https://github.com/claranet/terraform-datadog-monitors/tree/master/caas/kubernetes/pod/) + - [velero](https://github.com/claranet/terraform-datadog-monitors/tree/master/caas/kubernetes/velero/) - [workload](https://github.com/claranet/terraform-datadog-monitors/tree/master/caas/kubernetes/workload/) - [cloud](https://github.com/claranet/terraform-datadog-monitors/tree/master/cloud/) - [aws](https://github.com/claranet/terraform-datadog-monitors/tree/master/cloud/aws/) diff --git a/caas/kubernetes/velero/README.md b/caas/kubernetes/velero/README.md new file mode 100644 index 0000000..c638926 --- /dev/null +++ b/caas/kubernetes/velero/README.md @@ -0,0 +1,134 @@ +# CAAS KUBERNETES VELERO DataDog monitors + +## How to use this module + +``` +module "datadog-monitors-caas-kubernetes-velero" { + source = "claranet/monitors/datadog//caas/kubernetes/velero" + version = "{revision}" + + environment = var.environment + message = module.datadog-message-alerting.alerting-message +} + +``` + +## Purpose + +Creates DataDog monitors with the following checks: + +- Velero backup deletion failure +- Velero backup failure +- Velero backup partial failure +- Velero scheduled backup missing +- Velero volume snapshot failure + +## Inputs + +| Name | Description | Type | Default | Required | +|------|-------------|:----:|:-----:|:-----:| +| environment | Architecture environment | string | n/a | yes | +| evaluation\_delay | Delay in seconds for the metric evaluation | string | `"15"` | no | +| filter\_tags\_custom | Tags used for custom filtering when filter_tags_use_defaults is false | string | `"*"` | no | +| filter\_tags\_custom\_excluded | Tags excluded for custom filtering when filter_tags_use_defaults is false | string | `""` | no | +| filter\_tags\_use\_defaults | Use default filter tags convention | string | `"true"` | no | +| message | Message sent when a monitor is triggered | string | n/a | yes | +| new\_host\_delay | Delay in seconds before monitor new resource | string | `"300"` | no | +| notify\_no\_data | Will raise no data alert if set to true | string | `"true"` | no | +| prefix\_slug | Prefix string to prepend between brackets on every monitors names | string | `""` | no | +| velero\_backup\_deletion\_failure\_enabled | Flag to enable Velero backup deletion failure monitor | string | `"true"` | no | +| velero\_backup\_deletion\_failure\_extra\_tags | Extra tags for Velero backup deletion failure monitor | list(string) | `[]` | no | +| velero\_backup\_deletion\_failure\_monitor\_message | Custom message for Velero backup deletion failure monitor | string | `""` | no | +| velero\_backup\_deletion\_failure\_monitor\_timeframe | 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`] | string | `"last_1d"` | no | +| velero\_backup\_failure\_enabled | Flag to enable Velero backup failure monitor | string | `"true"` | no | +| velero\_backup\_failure\_extra\_tags | Extra tags for Velero backup failure monitor | list(string) | `[]` | no | +| velero\_backup\_failure\_monitor\_message | Custom message for Velero backup failure monitor | string | `""` | no | +| velero\_backup\_failure\_monitor\_timeframe | 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`] | string | `"last_1d"` | no | +| velero\_backup\_partial\_failure\_enabled | Flag to enable Velero backup partial failure monitor | string | `"true"` | no | +| velero\_backup\_partial\_failure\_extra\_tags | Extra tags for Velero backup partial failure monitor | list(string) | `[]` | no | +| velero\_backup\_partial\_failure\_monitor\_message | Custom message for Velero backup partial failure monitor | string | `""` | no | +| velero\_backup\_partial\_failure\_monitor\_timeframe | 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`] | string | `"last_1d"` | no | +| velero\_scheduled\_backup\_missing\_enabled | Flag to enable Velero scheduled backup missing monitor | string | `"true"` | no | +| velero\_scheduled\_backup\_missing\_extra\_tags | Extra tags for Velero scheduled backup missing monitor | list(string) | `[]` | no | +| velero\_scheduled\_backup\_missing\_monitor\_message | Custom message for Velero scheduled backup missing monitor | string | `""` | no | +| velero\_scheduled\_backup\_missing\_monitor\_no\_data\_timeframe | No data timeframe in minutes | string | `"2880"` | no | +| velero\_scheduled\_backup\_missing\_monitor\_timeframe | 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`] | string | `"last_1d"` | no | +| velero\_volume\_snapshot\_failure\_enabled | Flag to enable Velero volume snapshot failure monitor | string | `"true"` | no | +| velero\_volume\_snapshot\_failure\_extra\_tags | Extra tags for Velero volume snapshot failure monitor | list(string) | `[]` | no | +| velero\_volume\_snapshot\_failure\_monitor\_message | Custom message for Velero volume snapshot failure monitor | string | `""` | no | +| velero\_volume\_snapshot\_failure\_monitor\_timeframe | 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`] | string | `"last_1d"` | no | + +## Outputs + +| Name | Description | +|------|-------------| +| velero\_backup\_deletion\_failure\_id | id for monitor velero_backup_deletion_failure | +| velero\_backup\_failure\_id | id for monitor velero_backup_failure | +| velero\_backup\_partial\_failure\_id | id for monitor velero_backup_partial_failure | +| velero\_scheduled\_backup\_missing\_id | id for monitor velero_scheduled_backup_missing | +| velero\_volume\_snapshot\_failure\_id | id for monitor velero_volume_snapshot_failure | + +## Related documentation + +Documentation for Datadog prometheus intergration: https://docs.datadoghq.com/integrations/prometheus/ +Documentation for Datadog OpenMetrics integration: https://docs.datadoghq.com/integrations/openmetrics/ +Documentation for Datadog autodiscovery: https://docs.datadoghq.com/agent/autodiscovery/clusterchecks/ + +### How to configure Datadog agent for these monitors ? +You can configure Datadog agent by autodiscovery pod annotations or by configuration file. + +#### Configuration by autodiscovery pod annotations +Add these annotations to Velero pods: + +``` +podAnnotations: { + "ad.datadoghq.com/velero.check_names": '["openmetrics"]', + "ad.datadoghq.com/velero.init_configs": '[{}]', + "ad.datadoghq.com/velero.instances": '[{"prometheus_url": "http://%%host%%:8085/metrics", "namespace": "velero", "metrics": ["velero*"]}]' +} +``` + +#### Configuration by configuration file +Example of `openmetrics.d/conf.yaml`: + +``` +init_config: + +instances: + + ## @param prometheus_url - string - required + ## The URL where your application metrics are exposed by Prometheus. + # + - prometheus_url: http://velero.velero.svc.cluster.local:8085/metrics + + ## @param namespace - string - required + ## The namespace to be prepended to all metrics. + # + namespace: "velero" + + ## @param metrics - list of strings - required + ## List of metrics to be fetched from the prometheus endpoint, if there's a + ## value it'll be renamed. This list should contain at least one metric + # + metrics: + - velero* +``` + +### How to monitor multiple schedule witch have different frequencies ? + +If you have multiple Velero schedules with different frequencies, you must duplicate this module and disable common monitors in the others instance of module. + +``` +module "datadog-monitors-caas-kubernetes-velero" { + source = "claranet/monitors/datadog//caas/kubernetes/velero" + version = "{revision}" + + environment = var.environment + message = module.datadog-message-alerting.alerting-message + + velero_backup_failure_enabled = false + velero_backup_partial_failure_enabled = false + velero_backup_deletion_failure_enabled = false + velero_volume_snapshot_failure_enabled = false +} + diff --git a/caas/kubernetes/velero/inputs.tf b/caas/kubernetes/velero/inputs.tf new file mode 100644 index 0000000..755cd6a --- /dev/null +++ b/caas/kubernetes/velero/inputs.tf @@ -0,0 +1,171 @@ +# 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 "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 = 2880 +} + +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_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_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_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 = [] +} diff --git a/caas/kubernetes/velero/modules.tf b/caas/kubernetes/velero/modules.tf new file mode 100644 index 0000000..c1cb2b3 --- /dev/null +++ b/caas/kubernetes/velero/modules.tf @@ -0,0 +1,20 @@ +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_use_defaults + filter_tags_custom = var.filter_tags_custom + filter_tags_custom_excluded = var.filter_tags_custom_excluded + extra_tags_excluded = ["schedule:"] +} diff --git a/caas/kubernetes/velero/monitors-velero.tf b/caas/kubernetes/velero/monitors-velero.tf new file mode 100644 index 0000000..9a4260c --- /dev/null +++ b/caas/kubernetes/velero/monitors-velero.tf @@ -0,0 +1,165 @@ +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 + + notify_no_data = false + renotify_interval = 0 + notify_audit = false + timeout_h = 0 + include_tags = true + locked = false + require_full_window = true + + tags = concat(["env:${var.environment}", "type:caas", "provider:openmetrics", "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 + + notify_no_data = false + renotify_interval = 0 + notify_audit = false + timeout_h = 0 + include_tags = true + locked = false + require_full_window = true + + tags = concat(["env:${var.environment}", "type:caas", "provider:openmetrics", "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 + + notify_no_data = false + renotify_interval = 0 + notify_audit = false + timeout_h = 0 + include_tags = true + locked = false + require_full_window = true + + tags = concat(["env:${var.environment}", "type:caas", "provider:openmetrics", "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 + + notify_no_data = false + renotify_interval = 0 + notify_audit = false + timeout_h = 0 + include_tags = true + locked = false + require_full_window = true + + tags = concat(["env:${var.environment}", "type:caas", "provider:openmetrics", "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..992a26b --- /dev/null +++ b/caas/kubernetes/velero/outputs.tf @@ -0,0 +1,25 @@ +output "velero_backup_deletion_failure_id" { + description = "id for monitor velero_backup_deletion_failure" + value = datadog_monitor.velero_backup_deletion_failure.*.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_scheduled_backup_missing_id" { + description = "id for monitor velero_scheduled_backup_missing" + value = datadog_monitor.velero_scheduled_backup_missing.*.id +} + +output "velero_volume_snapshot_failure_id" { + description = "id for monitor velero_volume_snapshot_failure" + value = datadog_monitor.velero_volume_snapshot_failure.*.id +} +