From d3bbb3ced5c4309f5b71622c79ff754d6bdd487a Mon Sep 17 00:00:00 2001 From: Laurent Piroelle Date: Fri, 24 Nov 2017 16:53:25 +0100 Subject: [PATCH] MON-90 Azure API Management monitors --- cloud/azure/apimanagement/README.md | 43 +++++ cloud/azure/apimanagement/inputs.tf | 46 +++++ .../monitors-azure-apimanagement.tf | 160 ++++++++++++++++++ 3 files changed, 249 insertions(+) create mode 100644 cloud/azure/apimanagement/README.md create mode 100644 cloud/azure/apimanagement/inputs.tf create mode 100644 cloud/azure/apimanagement/monitors-azure-apimanagement.tf diff --git a/cloud/azure/apimanagement/README.md b/cloud/azure/apimanagement/README.md new file mode 100644 index 0000000..e59e81a --- /dev/null +++ b/cloud/azure/apimanagement/README.md @@ -0,0 +1,43 @@ +Azure API Management Datadog monitors +===================================== + +How to use this module +---------------------- +``` +module "datadog-monitors-azure-apimanagement" { + source = "git::ssh://git@bitbucket.org/morea/terraform.feature.datadog.git//cloud/azure/apimanagement?ref={revision}" + + message = "${module.datadog-message-alerting.alerting-message}" + environment = "${var.environment}" +} +``` + +Purpose +------- +Creates Datadog monitors with the following checks : + +* Service status +* Failed requests ratio +* Other requests ratio +* Unauthorized requests ratio +* Successful requests ratio + +Inputs +------ + +| Name | Description | Type | Default | Required | +|------|-------------|:----:|:-----:|:-----:| +| delay | Delay in seconds for the metric evaluation | string | `600` | no | +| environment | Architecture environment | string | - | yes | +| failed_requests_threshold_critical | Maximum acceptable percent of failed requests | string | `5` | no | +| filter_tags_custom | Tags used 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 Redis monitor is triggered | string | - | yes | +| other_requests_threshold_critical | Maximum acceptable percent of other requests | string | `5` | no | +| successful_requests_threshold_critical | Minimum acceptable percent of successful requests | string | `90` | no | +| unauthorized_requests_threshold_critical | Maximum acceptable percent of unauthorized requests | string | `5` | no | + +Related documentation +--------------------- + +Azure API Management metrics documentation: [https://docs.microsoft.com/en-us/azure/api-management/api-management-howto-use-azure-monitor](https://docs.microsoft.com/en-us/azure/api-management/api-management-howto-use-azure-monitor) diff --git a/cloud/azure/apimanagement/inputs.tf b/cloud/azure/apimanagement/inputs.tf new file mode 100644 index 0000000..002593e --- /dev/null +++ b/cloud/azure/apimanagement/inputs.tf @@ -0,0 +1,46 @@ +# Global Terraform +variable "environment" { + description = "Architecture environment" + type = "string" +} + +# Global DataDog +variable "message" { + description = "Message sent when a Redis monitor is triggered" +} + +variable "delay" { + description = "Delay in seconds for the metric evaluation" + default = 600 +} + +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 = "*" +} + +# Azure API Management specific +variable "failed_requests_threshold_critical" { + description = "Maximum acceptable percent of failed requests" + default = 5 +} + +variable "other_requests_threshold_critical" { + description = "Maximum acceptable percent of other requests" + default = 5 +} + +variable "unauthorized_requests_threshold_critical" { + description = "Maximum acceptable percent of unauthorized requests" + default = 5 +} + +variable "successful_requests_threshold_critical" { + description = "Minimum acceptable percent of successful requests" + default = 90 +} diff --git a/cloud/azure/apimanagement/monitors-azure-apimanagement.tf b/cloud/azure/apimanagement/monitors-azure-apimanagement.tf new file mode 100644 index 0000000..f7a55b1 --- /dev/null +++ b/cloud/azure/apimanagement/monitors-azure-apimanagement.tf @@ -0,0 +1,160 @@ +data "template_file" "filter" { + template = "$${filter}" + + vars { + filter = "${var.filter_tags_use_defaults == "true" ? + format("dd_monitoring:enabled,dd_azure_apimanagement:enabled,env:%s", var.environment) : + "${var.filter_tags_custom}"}" + } +} + +resource "datadog_monitor" "apimgt_status" { + name = "[${var.environment}] API Management status is not ok on {{name}}" + message = "${var.message}" + + query = < ${var.failed_requests_threshold_critical} + EOF + + thresholds { + critical = "${var.failed_requests_threshold_critical}" + } + + type = "metric alert" + notify_no_data = false + notify_audit = false + timeout_h = 0 + include_tags = true + locked = false + require_full_window = true + new_host_delay = "${var.delay}" + evaluation_delay = "${var.delay}" + renotify_interval = 0 + no_data_timeframe = 20 + + tags = ["env:${var.environment}", "resource:apimanagement", "team:azure", "provider:azure"] +} + +resource "datadog_monitor" "apimgt_other_requests" { + name = "[${var.environment}] API Management {{name}} too much other requests" + message = "${var.message}" + + query = < ${var.other_requests_threshold_critical} + EOF + + thresholds { + critical = "${var.other_requests_threshold_critical}" + } + + type = "metric alert" + notify_no_data = false + notify_audit = false + timeout_h = 0 + include_tags = true + locked = false + require_full_window = true + new_host_delay = "${var.delay}" + evaluation_delay = "${var.delay}" + renotify_interval = 0 + no_data_timeframe = 20 + + tags = ["env:${var.environment}", "resource:apimanagement", "team:azure", "provider:azure"] +} + +resource "datadog_monitor" "apimgt_unauthorized_requests" { + name = "[${var.environment}] API Management {{name}} too much unauthorized requests" + message = "${var.message}" + + query = < ${var.unauthorized_requests_threshold_critical} + EOF + + thresholds { + critical = "${var.unauthorized_requests_threshold_critical}" + } + + type = "metric alert" + notify_no_data = false + notify_audit = false + timeout_h = 0 + include_tags = true + locked = false + require_full_window = true + new_host_delay = "${var.delay}" + evaluation_delay = "${var.delay}" + renotify_interval = 0 + no_data_timeframe = 20 + + tags = ["env:${var.environment}", "resource:apimanagement", "team:azure", "provider:azure"] +} + +resource "datadog_monitor" "apimgt_successful_requests" { + name = "[${var.environment}] API Management {{name}} successful requests rate too low" + message = "${var.message}" + + query = <