Merged in MON-226-gcp-pubsub (pull request #120)

MON-226 monitors for GCP Pub/Sub

Approved-by: Rafael Romero Carmona <rafael.romero.carmona@fr.clara.net>
Approved-by: Quentin Manfroi <quentin.manfroi@yahoo.fr>
Approved-by: Alexandre Gaillet <alexandre.gaillet@fr.clara.net>
This commit is contained in:
Rafael Romero Carmona 2018-08-30 11:04:10 +00:00 committed by Quentin Manfroi
commit 57aa98fa1b
5 changed files with 246 additions and 0 deletions

View File

@ -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/)

View File

@ -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 | `<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 | `<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 | `<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 | `<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/)

110
cloud/gcp/pubsub/inputs.tf Normal file
View File

@ -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 = []
}

View File

@ -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 = <<EOF
${var.sending_operations_count_time_aggregator}(${var.sending_operations_count_timeframe}):
default(avg:gcp.pubsub.topic.send_message_operation_count{${var.filter_tags}} by {topic_id}.as_count(), 0)
<= ${var.sending_operations_count_threshold_critical}
EOF
thresholds {
critical = "${var.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.sending_operations_count_silenced}"
tags = ["env:${var.environment}", "type:cloud", "provider:gcp", "resource:pubsub", "team:claranet", "created-by:terraform", "${var.sending_operations_count_extra_tags}"]
}
#
# Unavailable Sending Operations Count
#
resource "datadog_monitor" "unavailable_sending_operations_count" {
name = "[${var.environment}] GCP pubsub sending messages with result unavailable {{#is_alert}}{{{comparator}}} {{threshold}} ({{value}}){{/is_alert}}{{#is_warning}}{{{comparator}}} {{warn_threshold}} ({{value}}){{/is_warning}}"
message = "${coalesce(var.unavailable_sending_operations_count_message, var.message)}"
type = "query alert"
query = <<EOF
${var.unavailable_sending_operations_count_time_aggregator}(${var.unavailable_sending_operations_count_timeframe}):
default(avg:gcp.pubsub.topic.send_message_operation_count{${var.filter_tags},response_code:unavailable} by {topic_id}.as_count(), 0)
>= ${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}"]
}

View File

@ -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}"
}