diff --git a/README.md b/README.md index 72455ee..db806cc 100644 --- a/README.md +++ b/README.md @@ -96,6 +96,7 @@ The `//` is very important, it's a terraform specific syntax used to separate gi - [cloud-sql](https://bitbucket.org/morea/terraform.feature.datadog/src/master/cloud/gcp/cloud-sql/) - [common](https://bitbucket.org/morea/terraform.feature.datadog/src/master/cloud/gcp/cloud-sql/common/) - [mysql](https://bitbucket.org/morea/terraform.feature.datadog/src/master/cloud/gcp/cloud-sql/mysql/) + - [pubsub](https://bitbucket.org/morea/terraform.feature.datadog/src/master/cloud/gcp/pubsub/) - [common](https://bitbucket.org/morea/terraform.feature.datadog/src/master/common/) - [alerting-message](https://bitbucket.org/morea/terraform.feature.datadog/src/master/common/alerting-message/) - [filter-tags](https://bitbucket.org/morea/terraform.feature.datadog/src/master/common/filter-tags/) diff --git a/cloud/gcp/pubsub/README.md b/cloud/gcp/pubsub/README.md new file mode 100644 index 0000000..3ca819c --- /dev/null +++ b/cloud/gcp/pubsub/README.md @@ -0,0 +1,56 @@ +# CLOUD GCP PUBSUB DataDog monitors + +## How to use this module + +``` +module "datadog-monitors-cloud-gcp-pubsub" { + source = "git::ssh://git@bitbucket.org/morea/terraform.feature.datadog.git//cloud/gcp/pubsub?ref={revision}" + + environment = "${var.environment}" + message = "${module.datadog-message-alerting.alerting-message}" +} + +``` + +## Purpose + +Creates DataDog monitors with the following checks: + +- GCP pubsub sending messages operations +- GCP pubsub sending messages with result unavailable + +## Inputs + +| Name | Description | Type | Default | Required | +|------|-------------|:----:|:-----:|:-----:| +| environment | Architecture environment | string | - | yes | +| evaluation_delay | Delay in seconds for the metric evaluation | string | `900` | no | +| filter_tags | Tags used for filtering | string | `*` | no | +| message | Message sent when a monitor is triggered | string | - | yes | +| new_host_delay | Delay in seconds for the new host evaluation | string | `300` | no | +| sending_operations_count_extra_tags | Extra tags for GCP Pub/Sub Sending Operations Count monitor | list | `` | no | +| sending_operations_count_message | Custom message for the GCP Pub/Sub Sending Operations Count monitor | string | `` | no | +| sending_operations_count_silenced | Groups to mute for GCP Pub/Sub Sending Operations Count monitor | map | `` | no | +| sending_operations_count_threshold_critical | Critical threshold for the number of sending operations. | string | `0` | no | +| sending_operations_count_time_aggregator | Timeframe for the GCP Pub/Sub Sending Operations Count monitor | string | `sum` | no | +| sending_operations_count_timeframe | Timeframe for the GCP Pub/Sub Sending Operations Count monitor | string | `last_30m` | no | +| unavailable_sending_operations_count_extra_tags | Extra tags for GCP Pub/Sub Unavailable Sending Operations Count monitor | list | `` | no | +| unavailable_sending_operations_count_message | Custom message for the GCP Pub/Sub Unavailable Sending Operations Count monitor | string | `` | no | +| unavailable_sending_operations_count_silenced | Groups to mute for GCP Pub/Sub Unavailable Sending Operations Count monitor | map | `` | no | +| unavailable_sending_operations_count_threshold_critical | Critical threshold for the number of unavailable sending operations | string | `4` | no | +| unavailable_sending_operations_count_threshold_warning | Warning threshold for the number of unavailable sending operations | string | `2` | no | +| unavailable_sending_operations_count_time_aggregator | Timeframe for the GCP Pub/Sub Unavailable Sending Operations Count monitor | string | `sum` | no | +| unavailable_sending_operations_count_timeframe | Timeframe for the GCP Pub/Sub Unavailable Sending Operations Count monitor | string | `last_10m` | no | + +## Outputs + +| Name | Description | +|------|-------------| +| sending_operations_count_id | id for monitor sending_operations_count | +| unavailable_sending_operations_count_id | id for monitor unavailable_sending_operations_count | + +Related documentation +------------ + +* [GCP Pub/Sub Metrics](https://cloud.google.com/monitoring/api/metrics_gcp#gcp-pubsub) +* [Datadog GCP Pub/Sub integration](https://docs.datadoghq.com/integrations/google_cloud_pubsub/) diff --git a/cloud/gcp/pubsub/inputs.tf b/cloud/gcp/pubsub/inputs.tf new file mode 100644 index 0000000..eb86ff4 --- /dev/null +++ b/cloud/gcp/pubsub/inputs.tf @@ -0,0 +1,110 @@ +# +# Datadog global variables +# +variable "environment" { + description = "Architecture environment" + type = "string" +} + +variable "filter_tags" { + description = "Tags used for filtering" + 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 for the new host evaluation" + default = 300 +} + +# +# Sending Operations Count +# +variable "sending_operations_count_message" { + description = "Custom message for the GCP Pub/Sub Sending Operations Count monitor" + type = "string" + default = "" +} + +variable "sending_operations_count_time_aggregator" { + description = "Timeframe for the GCP Pub/Sub Sending Operations Count monitor" + type = "string" + default = "sum" +} + +variable "sending_operations_count_timeframe" { + description = "Timeframe for the GCP Pub/Sub Sending Operations Count monitor" + type = "string" + default = "last_30m" +} + +variable "sending_operations_count_threshold_critical" { + description = "Critical threshold for the number of sending operations." + type = "string" + default = 0 +} + +variable "sending_operations_count_silenced" { + description = "Groups to mute for GCP Pub/Sub Sending Operations Count monitor" + type = "map" + default = {} +} + +variable "sending_operations_count_extra_tags" { + description = "Extra tags for GCP Pub/Sub Sending Operations Count monitor" + type = "list" + default = [] +} + +# +# Unavailable Sending Operations Count +# +variable "unavailable_sending_operations_count_message" { + description = "Custom message for the GCP Pub/Sub Unavailable Sending Operations Count monitor" + type = "string" + default = "" +} + +variable "unavailable_sending_operations_count_time_aggregator" { + description = "Timeframe for the GCP Pub/Sub Unavailable Sending Operations Count monitor" + type = "string" + default = "sum" +} + +variable "unavailable_sending_operations_count_timeframe" { + description = "Timeframe for the GCP Pub/Sub Unavailable Sending Operations Count monitor" + type = "string" + default = "last_10m" +} + +variable "unavailable_sending_operations_count_threshold_warning" { + description = "Warning threshold for the number of unavailable sending operations" + type = "string" + default = 2 +} + +variable "unavailable_sending_operations_count_threshold_critical" { + description = "Critical threshold for the number of unavailable sending operations" + type = "string" + default = 4 +} + +variable "unavailable_sending_operations_count_silenced" { + description = "Groups to mute for GCP Pub/Sub Unavailable Sending Operations Count monitor" + type = "map" + default = {} +} + +variable "unavailable_sending_operations_count_extra_tags" { + description = "Extra tags for GCP Pub/Sub Unavailable Sending Operations Count monitor" + type = "list" + default = [] +} diff --git a/cloud/gcp/pubsub/monitors-pubsub.tf b/cloud/gcp/pubsub/monitors-pubsub.tf new file mode 100644 index 0000000..6189794 --- /dev/null +++ b/cloud/gcp/pubsub/monitors-pubsub.tf @@ -0,0 +1,70 @@ +# +# Sending Operations Count +# +resource "datadog_monitor" "sending_operations_count" { + name = "[${var.environment}] GCP pubsub sending messages operations {{#is_alert}}{{{comparator}}} {{threshold}} ({{value}}){{/is_alert}}{{#is_warning}}{{{comparator}}} {{warn_threshold}} ({{value}}){{/is_warning}}" + message = "${coalesce(var.sending_operations_count_message, var.message)}" + + type = "query alert" + + query = <= ${var.unavailable_sending_operations_count_threshold_critical} +EOF + + thresholds { + warning = "${var.unavailable_sending_operations_count_threshold_warning}" + critical = "${var.unavailable_sending_operations_count_threshold_critical}" + } + + notify_audit = false + locked = false + timeout_h = 0 + include_tags = true + require_full_window = false + notify_no_data = true + renotify_interval = 0 + + evaluation_delay = "${var.evaluation_delay}" + new_host_delay = "${var.new_host_delay}" + + silenced = "${var.unavailable_sending_operations_count_silenced}" + + tags = ["env:${var.environment}", "type:cloud", "provider:gcp", "resource:pubsub", "team:claranet", "created-by:terraform", "${var.unavailable_sending_operations_count_extra_tags}"] +} diff --git a/cloud/gcp/pubsub/outputs.tf b/cloud/gcp/pubsub/outputs.tf new file mode 100644 index 0000000..869f4b8 --- /dev/null +++ b/cloud/gcp/pubsub/outputs.tf @@ -0,0 +1,9 @@ +output "sending_operations_count_id" { + description = "id for monitor sending_operations_count" + value = "${datadog_monitor.sending_operations_count.*.id}" +} + +output "unavailable_sending_operations_count_id" { + description = "id for monitor unavailable_sending_operations_count" + value = "${datadog_monitor.unavailable_sending_operations_count.*.id}" +}