From 39e81c3776da42854991f9c57fa6ed28558da588 Mon Sep 17 00:00:00 2001 From: Rafael Romero Carmona Date: Tue, 20 Aug 2019 09:32:05 +0100 Subject: [PATCH 1/3] MON-498 Kong monitors: service check and treatment limit --- README.md | 1 + middleware/kong/README.md | 26 +++++++ middleware/kong/inputs.tf | 127 +++++++++++++++++++++++++++++++ middleware/kong/modules.tf | 9 +++ middleware/kong/monitors-kong.tf | 69 +++++++++++++++++ middleware/kong/outputs.tf | 10 +++ 6 files changed, 242 insertions(+) create mode 100644 middleware/kong/README.md create mode 100644 middleware/kong/inputs.tf create mode 100644 middleware/kong/modules.tf create mode 100644 middleware/kong/monitors-kong.tf create mode 100644 middleware/kong/outputs.tf diff --git a/README.md b/README.md index 65884d7..a0b4c68 100644 --- a/README.md +++ b/README.md @@ -201,6 +201,7 @@ The `//` is very important, it's a terraform specific syntax used to separate gi - [redis](https://git.fr.clara.net/claranet/pt-monitoring/projects/datadog/terraform/monitors/tree/master/database/redis/) - [middleware](https://git.fr.clara.net/claranet/pt-monitoring/projects/datadog/terraform/monitors/tree/master/middleware/) - [apache](https://git.fr.clara.net/claranet/pt-monitoring/projects/datadog/terraform/monitors/tree/master/middleware/apache/) + - [kong](https://git.fr.clara.net/claranet/pt-monitoring/projects/datadog/terraform/monitors/tree/master/middleware/kong/) - [nginx](https://git.fr.clara.net/claranet/pt-monitoring/projects/datadog/terraform/monitors/tree/master/middleware/nginx/) - [php-fpm](https://git.fr.clara.net/claranet/pt-monitoring/projects/datadog/terraform/monitors/tree/master/middleware/php-fpm/) - [system](https://git.fr.clara.net/claranet/pt-monitoring/projects/datadog/terraform/monitors/tree/master/system/) diff --git a/middleware/kong/README.md b/middleware/kong/README.md new file mode 100644 index 0000000..b83bcf7 --- /dev/null +++ b/middleware/kong/README.md @@ -0,0 +1,26 @@ +# MIDDLEWARE KONG DataDog monitors + +## How to use this module + +``` +module "datadog-monitors-middleware-kong" { + source = "git::ssh://git@git.fr.clara.net/claranet/pt-monitoring/projects/datadog/terraform/monitors.git//middleware/kong?ref={revision}" + + environment = var.environment + message = module.datadog-message-alerting.alerting-message +} + +``` + +## Purpose + +Creates DataDog monitors with the following checks: + +- Kong does not respond +- Kong exceeded its treatment limit + + +## Related documentation + +Datadog Documentation https://docs.datadoghq.com/integrations/kong/ + diff --git a/middleware/kong/inputs.tf b/middleware/kong/inputs.tf new file mode 100644 index 0000000..524983a --- /dev/null +++ b/middleware/kong/inputs.tf @@ -0,0 +1,127 @@ +# Global Terraform +variable "environment" { + description = "Architecture Environment" + type = string +} + +# Global DataDog +variable "evaluation_delay" { + description = "Delay in seconds for the metric evaluation" + default = 15 +} + +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 = "" +} + +variable "message" { + description = "Message sent when an alert is triggered" +} + +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 = "" +} + +# +# Not Responding +# + +variable "not_responding_enabled" { + description = "Flag to enable Kong does not respond monitor" + type = string + default = "true" +} + +variable "not_responding_message" { + description = "Custom message for Kong does not respond monitor" + type = string + default = "" +} + +variable "not_responding_last" { + description = "Parameter 'last' for the service check" + type = string + default = 6 +} + +variable "not_responding_threshold_critical" { + description = "Parameter 'last' for the service check" + type = string + default = 5 +} + +variable "not_responding_no_data_timeframe" { + description = "Kong does not respond monitor no data timeframe" + type = string + default = 10 +} + +variable "not_responding_extra_tags" { + description = "Extra tags for Kong does not respond monitor" + type = list(string) + default = [] +} + +# +# treatment Limit +# +variable "treatment_limit_enabled" { + description = "Flag to enable Kong Treatment Limit monitor" + type = string + default = "true" +} + +variable "treatment_limit_message" { + description = "Custom message for the Kong Treatment Limit monitor" + type = string + default = "" +} + +variable "treatment_limit_time_aggregator" { + description = "Time aggregator for the Kong Treatment Limit monitor" + type = string + default = "min" +} + +variable "treatment_limit_timeframe" { + description = "Timeframe for the Kong Treatment Limit monitor" + type = string + default = "last_15m" +} + +variable "treatment_limit_threshold_warning" { + description = "Docker Container Memory Usage warning threshold" + type = string + default = 0 +} + +variable "treatment_limit_threshold_critical" { + description = "Docker Container Memory Usage critical threshold" + type = string + default = 20 +} + +variable "treatment_limit_extra_tags" { + description = "Extra tags for Kong Treatment Limit monitor" + type = list(string) + default = [] +} + + diff --git a/middleware/kong/modules.tf b/middleware/kong/modules.tf new file mode 100644 index 0000000..ff44bcb --- /dev/null +++ b/middleware/kong/modules.tf @@ -0,0 +1,9 @@ +module "filter-tags" { + source = "../../common/filter-tags" + + environment = var.environment + resource = "kong" + 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/middleware/kong/monitors-kong.tf b/middleware/kong/monitors-kong.tf new file mode 100644 index 0000000..99676f6 --- /dev/null +++ b/middleware/kong/monitors-kong.tf @@ -0,0 +1,69 @@ +# +# Service Check +# +resource "datadog_monitor" "not_responding" { + count = var.not_responding_enabled == "true" ? 1 : 0 + name = "${var.prefix_slug == "" ? "" : "[${var.prefix_slug}]"}[${var.environment}] Kong does not respond" + message = coalesce(var.not_responding_message, var.message) + type = "service check" + + query = < ${var.treatment_limit_threshold_critical} +EOQ + + thresholds = { + warning = var.treatment_limit_threshold_warning + critical = var.treatment_limit_threshold_critical + } + + 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 = true + + tags = concat(["env:${var.environment}", "type:middleware", "provider:kong", "resource:kong", "team:claranet", "created-by:terraform"], var.treatment_limit_extra_tags) + + lifecycle { + ignore_changes = ["silenced"] + } +} + diff --git a/middleware/kong/outputs.tf b/middleware/kong/outputs.tf new file mode 100644 index 0000000..cbf2df8 --- /dev/null +++ b/middleware/kong/outputs.tf @@ -0,0 +1,10 @@ +output "not_responding_id" { + description = "id for monitor not_responding" + value = datadog_monitor.not_responding.*.id +} + +output "treatment_limit_id" { + description = "id for monitor treatment_limit" + value = datadog_monitor.treatment_limit.*.id +} + From cdb3a284dc2fd0f017ec1d6c3a7778b523586e3a Mon Sep 17 00:00:00 2001 From: Rafael Romero Carmona Date: Tue, 20 Aug 2019 12:17:54 +0100 Subject: [PATCH 2/3] MON-498 Readme ready --- middleware/kong/README.md | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/middleware/kong/README.md b/middleware/kong/README.md index b83bcf7..ecc7e99 100644 --- a/middleware/kong/README.md +++ b/middleware/kong/README.md @@ -19,8 +19,40 @@ Creates DataDog monitors with the following checks: - Kong does not respond - Kong exceeded its treatment limit +## Inputs + +| Name | Description | Type | Default | Required | +|------|-------------|:----:|:-----:|:-----:| +| environment | Architecture Environment | string | n/a | yes | +| evaluation\_delay | Delay in seconds for the metric evaluation | string | `"15"` | 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 an alert is triggered | string | n/a | yes | +| new\_host\_delay | Delay in seconds before monitor new resource | string | `"300"` | no | +| not\_responding\_enabled | Flag to enable Kong does not respond monitor | string | `"true"` | no | +| not\_responding\_extra\_tags | Extra tags for Kong does not respond monitor | list(string) | `[]` | no | +| not\_responding\_last | Parameter 'last' for the service check | string | `"6"` | no | +| not\_responding\_message | Custom message for Kong does not respond monitor | string | `""` | no | +| not\_responding\_no\_data\_timeframe | Kong does not respond monitor no data timeframe | string | `"10"` | no | +| not\_responding\_threshold\_critical | Parameter 'last' for the service check | string | `"5"` | no | +| prefix\_slug | Prefix string to prepend between brackets on every monitors names | string | `""` | no | +| treatment\_limit\_enabled | Flag to enable Kong Treatment Limit monitor | string | `"true"` | no | +| treatment\_limit\_extra\_tags | Extra tags for Kong Treatment Limit monitor | list(string) | `[]` | no | +| treatment\_limit\_message | Custom message for the Kong Treatment Limit monitor | string | `""` | no | +| treatment\_limit\_threshold\_critical | Docker Container Memory Usage critical threshold | string | `"20"` | no | +| treatment\_limit\_threshold\_warning | Docker Container Memory Usage warning threshold | string | `"0"` | no | +| treatment\_limit\_time\_aggregator | Time aggregator for the Kong Treatment Limit monitor | string | `"min"` | no | +| treatment\_limit\_timeframe | Timeframe for the Kong Treatment Limit monitor | string | `"last_15m"` | no | + +## Outputs + +| Name | Description | +|------|-------------| +| not\_responding\_id | id for monitor not_responding | +| treatment\_limit\_id | id for monitor treatment_limit | ## Related documentation -Datadog Documentation https://docs.datadoghq.com/integrations/kong/ +* [Datadog Kong integration](https://docs.datadoghq.com/integrations/kong/) From 4ec5bbab0df2ad12a328e2110f679aa6e91fee7d Mon Sep 17 00:00:00 2001 From: Rafael Romero Carmona Date: Thu, 29 Aug 2019 13:27:44 +0100 Subject: [PATCH 3/3] MON-498 Parameters last and critical threshold removed for the service check. Warning threshold added as parameter. --- middleware/kong/README.md | 3 +-- middleware/kong/inputs.tf | 14 ++++---------- middleware/kong/monitors-kong.tf | 5 +++-- 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/middleware/kong/README.md b/middleware/kong/README.md index ecc7e99..8667d9a 100644 --- a/middleware/kong/README.md +++ b/middleware/kong/README.md @@ -32,10 +32,9 @@ Creates DataDog monitors with the following checks: | new\_host\_delay | Delay in seconds before monitor new resource | string | `"300"` | no | | not\_responding\_enabled | Flag to enable Kong does not respond monitor | string | `"true"` | no | | not\_responding\_extra\_tags | Extra tags for Kong does not respond monitor | list(string) | `[]` | no | -| not\_responding\_last | Parameter 'last' for the service check | string | `"6"` | no | | not\_responding\_message | Custom message for Kong does not respond monitor | string | `""` | no | | not\_responding\_no\_data\_timeframe | Kong does not respond monitor no data timeframe | string | `"10"` | no | -| not\_responding\_threshold\_critical | Parameter 'last' for the service check | string | `"5"` | no | +| not\_responding\_threshold\_warning | Warning threshold for the service check | string | `"3"` | no | | prefix\_slug | Prefix string to prepend between brackets on every monitors names | string | `""` | no | | treatment\_limit\_enabled | Flag to enable Kong Treatment Limit monitor | string | `"true"` | no | | treatment\_limit\_extra\_tags | Extra tags for Kong Treatment Limit monitor | list(string) | `[]` | no | diff --git a/middleware/kong/inputs.tf b/middleware/kong/inputs.tf index 524983a..a36d026 100644 --- a/middleware/kong/inputs.tf +++ b/middleware/kong/inputs.tf @@ -55,16 +55,10 @@ variable "not_responding_message" { default = "" } -variable "not_responding_last" { - description = "Parameter 'last' for the service check" +variable "not_responding_threshold_warning" { + description = "Warning threshold for the service check" type = string - default = 6 -} - -variable "not_responding_threshold_critical" { - description = "Parameter 'last' for the service check" - type = string - default = 5 + default = 3 } variable "not_responding_no_data_timeframe" { @@ -80,7 +74,7 @@ variable "not_responding_extra_tags" { } # -# treatment Limit +# Treatment Limit # variable "treatment_limit_enabled" { description = "Flag to enable Kong Treatment Limit monitor" diff --git a/middleware/kong/monitors-kong.tf b/middleware/kong/monitors-kong.tf index 99676f6..5052294 100644 --- a/middleware/kong/monitors-kong.tf +++ b/middleware/kong/monitors-kong.tf @@ -8,11 +8,12 @@ resource "datadog_monitor" "not_responding" { type = "service check" query = <