From 08848a9fdb699cfaa7b11d8e59c20850e7b6b382 Mon Sep 17 00:00:00 2001 From: Rafael Romero Carmona Date: Wed, 4 Sep 2019 14:23:39 +0100 Subject: [PATCH 1/4] 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 +} + From 4af3817970a12c1285ea8705e993528a33b60deb Mon Sep 17 00:00:00 2001 From: Rafael Romero Carmona Date: Thu, 5 Sep 2019 09:20:18 +0100 Subject: [PATCH 2/4] MON-472 SQS added at the beginning of the names of all monitors. README.md generated. --- cloud/aws/sqs/README.md | 57 +++++++++++++++++++++++++++++++++++ cloud/aws/sqs/monitors-sqs.tf | 4 +-- 2 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 cloud/aws/sqs/README.md diff --git a/cloud/aws/sqs/README.md b/cloud/aws/sqs/README.md new file mode 100644 index 0000000..424cafa --- /dev/null +++ b/cloud/aws/sqs/README.md @@ -0,0 +1,57 @@ +# CLOUD AWS SQS DataDog monitors + +## How to use this module + +``` +module "datadog-monitors-cloud-aws-sqs" { + source = "git::ssh://git@git.fr.clara.net/claranet/pt-monitoring/projects/datadog/terraform/monitors.git//cloud/aws/sqs?ref={revision}" + + environment = var.environment + message = module.datadog-message-alerting.alerting-message +} + +``` + +## Purpose + +Creates DataDog monitors with the following checks: + +- SQS Age of the oldest message +- SQS Number of messages visible (disabled by default) + +## Inputs + +| Name | Description | Type | Default | Required | +|------|-------------|:----:|:-----:|:-----:| +| age\_of\_oldest\_message\_enabled | Flag to enable Age of Oldest Message monitor | string | `"true"` | no | +| age\_of\_oldest\_message\_extra\_tags | Extra tags for Age of Oldest Message monitor | list(string) | `[]` | no | +| age\_of\_oldest\_message\_message | Custom message for Age of Oldest Message monitor | string | `""` | no | +| age\_of\_oldest\_message\_threshold\_critical | Alerting threshold in seconds | string | `"600"` | no | +| age\_of\_oldest\_message\_threshold\_warning | Warning threshold in seconds | string | `"300"` | no | +| age\_of\_oldest\_message\_time\_aggregator | Monitor aggregator for Age of Oldest Message [available values: min, max or avg] | string | `"min"` | no | +| age\_of\_oldest\_message\_timeframe | 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`] | string | `"last_30m"` | no | +| environment | Architecture environment | string | n/a | yes | +| evaluation\_delay | Delay in seconds for the metric evaluation | string | `"900"` | 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 | +| prefix\_slug | Prefix string to prepend between brackets on every monitors names | string | `""` | no | +| visible\_messages\_enabled | Flag to enable Number of Visible Messages monitor | string | `"false"` | no | +| visible\_messages\_extra\_tags | Extra tags for Number of Visible Messages monitor | list(string) | `[]` | no | +| visible\_messages\_message | Custom message for Number of Visible Messages monitor | string | `""` | no | +| visible\_messages\_threshold\_critical | Alerting threshold in number of messages | string | `"2"` | no | +| visible\_messages\_threshold\_warning | Warning threshold in number of messages | string | `"1"` | no | +| visible\_messages\_time\_aggregator | Monitor aggregator for Number of Visible Messages [available values: min, max or avg] | string | `"min"` | no | +| visible\_messages\_timeframe | 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`] | string | `"last_30m"` | no | + +## Outputs + +| Name | Description | +|------|-------------| +| age\_of\_oldest\_message\_id | id for monitor age_of_oldest_message | +| visible\_messages\_id | id for monitor visible_messages | + +## Related documentation + diff --git a/cloud/aws/sqs/monitors-sqs.tf b/cloud/aws/sqs/monitors-sqs.tf index 3042262..8626099 100644 --- a/cloud/aws/sqs/monitors-sqs.tf +++ b/cloud/aws/sqs/monitors-sqs.tf @@ -1,7 +1,7 @@ # 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}}" + name = "${var.prefix_slug == "" ? "" : "[${var.prefix_slug}]"}[${var.environment}] SQS 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) @@ -36,7 +36,7 @@ EOQ # 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}}" + name = "${var.prefix_slug == "" ? "" : "[${var.prefix_slug}]"}[${var.environment}] SQS 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) From f29736982ad100019547b6cd8654c7c660198f91 Mon Sep 17 00:00:00 2001 From: Rafael Romero Carmona Date: Thu, 5 Sep 2019 16:22:17 +0100 Subject: [PATCH 3/4] MON-472 Related documentation added to the README.md of the module. Name of the monitors improved with units. --- cloud/aws/sqs/README.md | 5 +++-- cloud/aws/sqs/monitors-sqs.tf | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/cloud/aws/sqs/README.md b/cloud/aws/sqs/README.md index 424cafa..d00050d 100644 --- a/cloud/aws/sqs/README.md +++ b/cloud/aws/sqs/README.md @@ -17,7 +17,7 @@ module "datadog-monitors-cloud-aws-sqs" { Creates DataDog monitors with the following checks: - SQS Age of the oldest message -- SQS Number of messages visible (disabled by default) +- SQS Visible Messages (disabled by default) ## Inputs @@ -54,4 +54,5 @@ Creates DataDog monitors with the following checks: | visible\_messages\_id | id for monitor visible_messages | ## Related documentation - +* [Datadog Documentation](https://docs.datadoghq.com/integrations/amazon_sqs/) +* [Service Documentation](https://docs.aws.amazon.com/sqs/index.html) diff --git a/cloud/aws/sqs/monitors-sqs.tf b/cloud/aws/sqs/monitors-sqs.tf index 8626099..a570bf3 100644 --- a/cloud/aws/sqs/monitors-sqs.tf +++ b/cloud/aws/sqs/monitors-sqs.tf @@ -1,7 +1,7 @@ # 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}] SQS Number of messages visible {{#is_alert}}{{{comparator}}} {{threshold}}% ({{value}}%){{/is_alert}}{{#is_warning}}{{{comparator}}} {{warn_threshold}}% ({{value}}%){{/is_warning}}" + name = "${var.prefix_slug == "" ? "" : "[${var.prefix_slug}]"}[${var.environment}] SQS Visible Messages {{#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) @@ -36,7 +36,7 @@ EOQ # 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}] SQS Age of the oldest message {{#is_alert}}{{{comparator}}} {{threshold}} ({{value}}){{/is_alert}}{{#is_warning}}{{{comparator}}} {{warn_threshold}} ({{value}}){{/is_warning}}" + name = "${var.prefix_slug == "" ? "" : "[${var.prefix_slug}]"}[${var.environment}] SQS Age of the oldest message {{#is_alert}}{{{comparator}}} {{threshold}}s ({{value}}s){{/is_alert}}{{#is_warning}}{{{comparator}}} {{warn_threshold}}s ({{value}}s){{/is_warning}}" type = "metric alert" message = coalesce(var.age_of_oldest_message_message, var.message) From d1c8dcf19a2493c61997624d66c25c8481533858 Mon Sep 17 00:00:00 2001 From: Rafael Romero Carmona Date: Thu, 5 Sep 2019 16:37:07 +0100 Subject: [PATCH 4/4] MON-472 Name of the monitor on visible messages corriged. --- cloud/aws/sqs/README.md | 2 +- cloud/aws/sqs/monitors-sqs.tf | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cloud/aws/sqs/README.md b/cloud/aws/sqs/README.md index d00050d..3842630 100644 --- a/cloud/aws/sqs/README.md +++ b/cloud/aws/sqs/README.md @@ -17,7 +17,7 @@ module "datadog-monitors-cloud-aws-sqs" { Creates DataDog monitors with the following checks: - SQS Age of the oldest message -- SQS Visible Messages (disabled by default) +- SQS Visible messages (disabled by default) ## Inputs diff --git a/cloud/aws/sqs/monitors-sqs.tf b/cloud/aws/sqs/monitors-sqs.tf index a570bf3..5ee2ca5 100644 --- a/cloud/aws/sqs/monitors-sqs.tf +++ b/cloud/aws/sqs/monitors-sqs.tf @@ -1,7 +1,7 @@ # 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}] SQS Visible Messages {{#is_alert}}{{{comparator}}} {{threshold}} ({{value}}){{/is_alert}}{{#is_warning}}{{{comparator}}} {{warn_threshold}} ({{value}}){{/is_warning}}" + name = "${var.prefix_slug == "" ? "" : "[${var.prefix_slug}]"}[${var.environment}] SQS Visible messages {{#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)