From efaa611202c8835813d997b34bdfade54ed26ccb Mon Sep 17 00:00:00 2001 From: Quentin Manfroi Date: Fri, 31 Aug 2018 13:25:34 +0200 Subject: [PATCH] MON-248 add 4xx monitor --- caas/kubernetes/ingress/README.md | 15 +++++-- caas/kubernetes/ingress/inputs.tf | 43 ++++++++++++++++++++- caas/kubernetes/ingress/modules.tf | 10 +++++ caas/kubernetes/ingress/monitors-ingress.tf | 38 +++++++++++++++++- caas/kubernetes/ingress/outputs.tf | 11 ++++-- 5 files changed, 108 insertions(+), 9 deletions(-) diff --git a/caas/kubernetes/ingress/README.md b/caas/kubernetes/ingress/README.md index 7ba4994..0a7ba2a 100644 --- a/caas/kubernetes/ingress/README.md +++ b/caas/kubernetes/ingress/README.md @@ -16,6 +16,7 @@ module "datadog-monitors-caas-kubernetes-ingress" { Creates DataDog monitors with the following checks: +- Nginx Ingress 4xx errors - Nginx Ingress 5xx errors ## Inputs @@ -27,12 +28,19 @@ Creates DataDog monitors with the following checks: | 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_use_defaults | Use default filter tags convention | string | `true` | no | +| ingress_4xx_enabled | Flag to enable Ingress 4xx errors monitor | string | `true` | no | +| ingress_4xx_extra_tags | Extra tags for Ingress 4xx errors monitor | list | `` | no | +| ingress_4xx_message | Message sent when an alert is triggered | string | `` | no | +| ingress_4xx_silenced | Groups to mute for Ingress 4xx errors monitor | map | `` | no | +| ingress_4xx_threshold_critical | | string | `40` | no | +| ingress_4xx_threshold_warning | | string | `20` | no | +| ingress_4xx_timeframe | Monitor timeframe for Ingress 4xx errors [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`] | string | `last_5m` | no | | ingress_5xx_enabled | Flag to enable Ingress 5xx errors monitor | string | `true` | no | | ingress_5xx_extra_tags | Extra tags for Ingress 5xx errors monitor | list | `` | no | | ingress_5xx_message | Message sent when an alert is triggered | string | `` | no | | ingress_5xx_silenced | Groups to mute for Ingress 5xx errors monitor | map | `` | no | -| ingress_5xx_threshold_critical | | string | `10` | no | -| ingress_5xx_threshold_warning | | string | `5` | no | +| ingress_5xx_threshold_critical | | string | `20` | no | +| ingress_5xx_threshold_warning | | string | `10` | no | | ingress_5xx_timeframe | Monitor timeframe for Ingress 5xx errors [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`] | string | `last_5m` | no | | message | Message sent when an alert is triggered | string | - | yes | | new_host_delay | Delay in seconds before monitor new resource | string | `300` | no | @@ -41,7 +49,8 @@ Creates DataDog monitors with the following checks: | Name | Description | |------|-------------| -| Nginx_ingress_too_many_5xx_id | id for monitor Nginx_ingress_too_many_5xx | +| nginx_ingress_too_many_4xx_id | id for monitor nginx_ingress_too_many_4xx | +| nginx_ingress_too_many_5xx_id | id for monitor nginx_ingress_too_many_5xx | Related documentation --------------------- diff --git a/caas/kubernetes/ingress/inputs.tf b/caas/kubernetes/ingress/inputs.tf index 65ed192..7be1590 100644 --- a/caas/kubernetes/ingress/inputs.tf +++ b/caas/kubernetes/ingress/inputs.tf @@ -61,12 +61,51 @@ variable "ingress_5xx_timeframe" { variable "ingress_5xx_threshold_critical" { type = "string" - default = "10" + default = "20" } variable "ingress_5xx_threshold_warning" { type = "string" - default = "5" + default = "10" +} + +variable "ingress_4xx_silenced" { + description = "Groups to mute for Ingress 4xx errors monitor" + type = "map" + default = {} +} + +variable "ingress_4xx_enabled" { + description = "Flag to enable Ingress 4xx errors monitor" + type = "string" + default = "true" +} + +variable "ingress_4xx_extra_tags" { + description = "Extra tags for Ingress 4xx errors monitor" + type = "list" + default = [] +} + +variable "ingress_4xx_message" { + description = "Message sent when an alert is triggered" + default = "" +} + +variable "ingress_4xx_timeframe" { + description = "Monitor timeframe for Ingress 4xx errors [available values: `last_#m` (1, 5, 10, 15, or 30), `last_#h` (1, 2, or 4), or `last_1d`]" + type = "string" + default = "last_5m" +} + +variable "ingress_4xx_threshold_critical" { + type = "string" + default = "40" +} + +variable "ingress_4xx_threshold_warning" { + type = "string" + default = "20" } variable "artificial_requests_count" { diff --git a/caas/kubernetes/ingress/modules.tf b/caas/kubernetes/ingress/modules.tf index 8cf5cd7..ee1e148 100644 --- a/caas/kubernetes/ingress/modules.tf +++ b/caas/kubernetes/ingress/modules.tf @@ -17,3 +17,13 @@ module "filter-tags-5xx" { filter_tags_custom = "${var.filter_tags_custom}" extra_tags = ["!upstream:upstream-default-backend,status_code:5xx"] } + +module "filter-tags-4xx" { + source = "../../../common/filter-tags" + + environment = "${var.environment}" + resource = "ingress" + filter_tags_use_defaults = "${var.filter_tags_use_defaults}" + filter_tags_custom = "${var.filter_tags_custom}" + extra_tags = ["!upstream:upstream-default-backend,status_code:4xx"] +} diff --git a/caas/kubernetes/ingress/monitors-ingress.tf b/caas/kubernetes/ingress/monitors-ingress.tf index 2cce3c3..ab44196 100644 --- a/caas/kubernetes/ingress/monitors-ingress.tf +++ b/caas/kubernetes/ingress/monitors-ingress.tf @@ -1,4 +1,4 @@ -resource "datadog_monitor" "Nginx_ingress_too_many_5xx" { +resource "datadog_monitor" "nginx_ingress_too_many_5xx" { count = "${var.ingress_5xx_enabled ? 1 : 0}" name = "[${var.environment}] Nginx Ingress 5xx errors {{#is_alert}}{{{comparator}}} {{threshold}}% ({{value}}%){{/is_alert}}{{#is_warning}}{{{comparator}}} {{warn_threshold}}% ({{value}}%){{/is_warning}}" message = "${coalesce(var.ingress_5xx_message, var.message)}" @@ -33,3 +33,39 @@ resource "datadog_monitor" "Nginx_ingress_too_many_5xx" { tags = ["env:${var.environment}", "type:caas", "provider:prometheus", "resource:nginx-ingress-controller", "team:claranet", "created-by:terraform", "${var.ingress_5xx_extra_tags}"] } + +resource "datadog_monitor" "nginx_ingress_too_many_4xx" { + count = "${var.ingress_4xx_enabled ? 1 : 0}" + name = "[${var.environment}] Nginx Ingress 4xx errors {{#is_alert}}{{{comparator}}} {{threshold}}% ({{value}}%){{/is_alert}}{{#is_warning}}{{{comparator}}} {{warn_threshold}}% ({{value}}%){{/is_warning}}" + message = "${coalesce(var.ingress_4xx_message, var.message)}" + + query = < ${var.ingress_4xx_threshold_critical} + EOF + + type = "metric alert" + + thresholds { + warning = "${var.ingress_4xx_threshold_warning}" + critical = "${var.ingress_4xx_threshold_critical}" + } + + notify_no_data = false + evaluation_delay = "${var.evaluation_delay}" + new_host_delay = "${var.new_host_delay}" + renotify_interval = 0 + notify_audit = false + timeout_h = 0 + include_tags = true + locked = false + require_full_window = true + + silenced = "${var.ingress_4xx_silenced}" + + tags = ["env:${var.environment}", "type:caas", "provider:prometheus", "resource:nginx-ingress-controller", "team:claranet", "created-by:terraform", "${var.ingress_4xx_extra_tags}"] +} diff --git a/caas/kubernetes/ingress/outputs.tf b/caas/kubernetes/ingress/outputs.tf index cacbec3..28582f8 100644 --- a/caas/kubernetes/ingress/outputs.tf +++ b/caas/kubernetes/ingress/outputs.tf @@ -1,4 +1,9 @@ -output "Nginx_ingress_too_many_5xx_id" { - description = "id for monitor Nginx_ingress_too_many_5xx" - value = "${datadog_monitor.Nginx_ingress_too_many_5xx.*.id}" +output "nginx_ingress_too_many_5xx_id" { + description = "id for monitor nginx_ingress_too_many_5xx" + value = "${datadog_monitor.nginx_ingress_too_many_5xx.*.id}" +} + +output "nginx_ingress_too_many_4xx_id" { + description = "id for monitor nginx_ingress_too_many_4xx" + value = "${datadog_monitor.nginx_ingress_too_many_4xx.*.id}" }