From 08848a9fdb699cfaa7b11d8e59c20850e7b6b382 Mon Sep 17 00:00:00 2001 From: Rafael Romero Carmona Date: Wed, 4 Sep 2019 14:23:39 +0100 Subject: [PATCH] MON-472 AWS SQS module with two monitors: number of visible messages (disabled by default) and age of the oldest message. --- README.md | 1 + cloud/aws/sqs/inputs.tf | 124 ++++++++++++++++++++++++++++++++++ cloud/aws/sqs/modules.tf | 9 +++ cloud/aws/sqs/monitors-sqs.tf | 69 +++++++++++++++++++ cloud/aws/sqs/outputs.tf | 10 +++ 5 files changed, 213 insertions(+) create mode 100644 cloud/aws/sqs/inputs.tf create mode 100644 cloud/aws/sqs/modules.tf create mode 100644 cloud/aws/sqs/monitors-sqs.tf create mode 100644 cloud/aws/sqs/outputs.tf diff --git a/README.md b/README.md index 411f5f4..0df7bc4 100644 --- a/README.md +++ b/README.md @@ -152,6 +152,7 @@ The `//` is very important, it's a terraform specific syntax used to separate gi - [mysql](https://git.fr.clara.net/claranet/pt-monitoring/projects/datadog/terraform/monitors/tree/master/cloud/aws/rds/aurora/mysql/) - [postgresql](https://git.fr.clara.net/claranet/pt-monitoring/projects/datadog/terraform/monitors/tree/master/cloud/aws/rds/aurora/postgresql/) - [common](https://git.fr.clara.net/claranet/pt-monitoring/projects/datadog/terraform/monitors/tree/master/cloud/aws/rds/common/) + - [sqs](https://git.fr.clara.net/claranet/pt-monitoring/projects/datadog/terraform/monitors/tree/master/cloud/aws/sqs/) - [vpn](https://git.fr.clara.net/claranet/pt-monitoring/projects/datadog/terraform/monitors/tree/master/cloud/aws/vpn/) - [azure](https://git.fr.clara.net/claranet/pt-monitoring/projects/datadog/terraform/monitors/tree/master/cloud/azure/) - [apimanagement](https://git.fr.clara.net/claranet/pt-monitoring/projects/datadog/terraform/monitors/tree/master/cloud/azure/apimanagement/) diff --git a/cloud/aws/sqs/inputs.tf b/cloud/aws/sqs/inputs.tf new file mode 100644 index 0000000..bd3559f --- /dev/null +++ b/cloud/aws/sqs/inputs.tf @@ -0,0 +1,124 @@ +# Datadog global variables + +variable "environment" { + description = "Architecture environment" + type = string +} + +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 = 900 +} + +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 = "" +} + +# Datadog monitors variables + +# Approximate Number of Visible Messages +variable "visible_messages_enabled" { + description = "Flag to enable Number of Visible Messages monitor" + type = string + default = "false" +} + +variable "visible_messages_extra_tags" { + description = "Extra tags for Number of Visible Messages monitor" + type = list(string) + default = [] +} + +variable "visible_messages_message" { + description = "Custom message for Number of Visible Messages monitor" + type = string + default = "" +} + +variable "visible_messages_time_aggregator" { + description = "Monitor aggregator for Number of Visible Messages [available values: min, max or avg]" + type = string + default = "min" +} + +variable "visible_messages_timeframe" { + description = "Monitor timeframe for Number of Visible Messages [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`]" + type = string + default = "last_30m" +} + +variable "visible_messages_threshold_critical" { + default = 2 + description = "Alerting threshold in number of messages" +} + +variable "visible_messages_threshold_warning" { + default = 1 + description = "Warning threshold in number of messages" +} + +# Age of the Oldest Message +variable "age_of_oldest_message_enabled" { + description = "Flag to enable Age of Oldest Message monitor" + type = string + default = "true" +} + +variable "age_of_oldest_message_extra_tags" { + description = "Extra tags for Age of Oldest Message monitor" + type = list(string) + default = [] +} + +variable "age_of_oldest_message_message" { + description = "Custom message for Age of Oldest Message monitor" + type = string + default = "" +} + +variable "age_of_oldest_message_time_aggregator" { + description = "Monitor aggregator for Age of Oldest Message [available values: min, max or avg]" + type = string + default = "min" +} + +variable "age_of_oldest_message_timeframe" { + description = "Monitor timeframe for Age of Oldest Message [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`]" + type = string + default = "last_30m" +} + +variable "age_of_oldest_message_threshold_critical" { + default = 600 + description = "Alerting threshold in seconds" +} + +variable "age_of_oldest_message_threshold_warning" { + default = 300 + description = "Warning threshold in seconds" +} diff --git a/cloud/aws/sqs/modules.tf b/cloud/aws/sqs/modules.tf new file mode 100644 index 0000000..291a7a5 --- /dev/null +++ b/cloud/aws/sqs/modules.tf @@ -0,0 +1,9 @@ +module "filter-tags" { + source = "../../../common/filter-tags" + + environment = var.environment + resource = "aws_sqs" + 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 +} diff --git a/cloud/aws/sqs/monitors-sqs.tf b/cloud/aws/sqs/monitors-sqs.tf new file mode 100644 index 0000000..3042262 --- /dev/null +++ b/cloud/aws/sqs/monitors-sqs.tf @@ -0,0 +1,69 @@ +# Approximate Number of Visible Messages +resource "datadog_monitor" "visible_messages" { + count = var.visible_messages_enabled == "true" ? 1 : 0 + name = "${var.prefix_slug == "" ? "" : "[${var.prefix_slug}]"}[${var.environment}] Number of messages visible {{#is_alert}}{{{comparator}}} {{threshold}}% ({{value}}%){{/is_alert}}{{#is_warning}}{{{comparator}}} {{warn_threshold}}% ({{value}}%){{/is_warning}}" + type = "metric alert" + message = coalesce(var.visible_messages_message, var.message) + + query = < ${var.visible_messages_threshold_critical} +EOQ + + thresholds = { + critical = var.visible_messages_threshold_critical + warning = var.visible_messages_threshold_warning + } + + 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 = false + + tags = concat(["env:${var.environment}", "type:cloud", "provider:aws", "resource:sqs", "team:claranet", "created-by:terraform"], var.visible_messages_extra_tags) + + lifecycle { + ignore_changes = ["silenced"] + } +} + +# Age of the Oldest Message +resource "datadog_monitor" "age_of_oldest_message" { + count = var.age_of_oldest_message_enabled == "true" ? 1 : 0 + name = "${var.prefix_slug == "" ? "" : "[${var.prefix_slug}]"}[${var.environment}] Age of the oldest message {{#is_alert}}{{{comparator}}} {{threshold}} ({{value}}){{/is_alert}}{{#is_warning}}{{{comparator}}} {{warn_threshold}} ({{value}}){{/is_warning}}" + type = "metric alert" + message = coalesce(var.age_of_oldest_message_message, var.message) + + query = < ${var.age_of_oldest_message_threshold_critical} +EOQ + + thresholds = { + critical = var.age_of_oldest_message_threshold_critical + warning = var.age_of_oldest_message_threshold_warning + } + + 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 = false + + tags = concat(["env:${var.environment}", "type:cloud", "provider:aws", "resource:sqs", "team:claranet", "created-by:terraform"], var.age_of_oldest_message_extra_tags) + + lifecycle { + ignore_changes = ["silenced"] + } +} diff --git a/cloud/aws/sqs/outputs.tf b/cloud/aws/sqs/outputs.tf new file mode 100644 index 0000000..566853e --- /dev/null +++ b/cloud/aws/sqs/outputs.tf @@ -0,0 +1,10 @@ +output "age_of_oldest_message_id" { + description = "id for monitor age_of_oldest_message" + value = datadog_monitor.age_of_oldest_message.*.id +} + +output "visible_messages_id" { + description = "id for monitor visible_messages" + value = datadog_monitor.visible_messages.*.id +} +