From a11615b35b5a1c2b70c74aa72a9e214ac42f461b Mon Sep 17 00:00:00 2001 From: saquino0827 Date: Wed, 23 Oct 2024 16:55:03 -0500 Subject: [PATCH 1/4] new branch to add the new 4xx alerts but remove alert slack email secret Co-authored-by: pluckyswan <96704946+pluckyswan@users.noreply.github.com> Co-authored-by: Sylvie Co-authored-by: halprin --- operations/template/alert.tf | 45 ++++++++++++++++++++++++++++++++++++ operations/template/main.tf | 1 + src/cmd/main.go | 10 ++++++++ 3 files changed, 56 insertions(+) create mode 100644 operations/template/alert.tf diff --git a/operations/template/alert.tf b/operations/template/alert.tf new file mode 100644 index 00000000..06775414 --- /dev/null +++ b/operations/template/alert.tf @@ -0,0 +1,45 @@ +data "azurerm_monitor_action_group" "notify_slack_email" { + count = local.non_pr_environment ? 1 : 0 + resource_group_name = data.azurerm_resource_group.group.name + name = "cdcti${var.environment}-actiongroup" +} + +resource "azurerm_monitor_metric_alert" "azure_4XX_alert" { + count = local.non_pr_environment ? 1 : 0 + name = "cdc-rs-sftp-${var.environment}-azure-http-4XX-alert" + resource_group_name = data.azurerm_resource_group.group.name + scopes = [azurerm_linux_web_app.sftp.id] + description = "Action will be triggered when Http Status Code 4XX is greater than or equal to 3" + frequency = "PT1M" // Checks every 1 minute + window_size = "PT1H" // Every Check looks back 1 hour for 4xx errors + + criteria { + metric_namespace = "Microsoft.Web/sites" + metric_name = "Http4xx" + aggregation = "Count" + operator = "GreaterThanOrEqual" + threshold = 3 + } + + action { + action_group_id = data.azurerm_monitor_action_group.notify_slack_email[count.index].id + } + + lifecycle { + # Ignore changes to tags because the CDC sets these automagically + ignore_changes = [ + tags["business_steward"], + tags["center"], + tags["environment"], + tags["escid"], + tags["funding_source"], + tags["pii_data"], + tags["security_compliance"], + tags["security_steward"], + tags["support_group"], + tags["system"], + tags["technical_steward"], + tags["zone"] + ] + } +} \ No newline at end of file diff --git a/operations/template/main.tf b/operations/template/main.tf index db673d5d..3bdfdd0e 100644 --- a/operations/template/main.tf +++ b/operations/template/main.tf @@ -8,6 +8,7 @@ locals { rs_domain_prefix = "${local.selected_rs_environment_prefix}${length(local.selected_rs_environment_prefix) == 0 ? "" : "."}" higher_environment_level = var.environment == "stg" || var.environment == "prd" cdc_domain_environment = var.environment == "dev" || var.environment == "stg" || var.environment == "prd" + non_pr_environment = length(regexall("^pr\\d+", var.environment)) == 0 } data "azurerm_resource_group" "group" { diff --git a/src/cmd/main.go b/src/cmd/main.go index c7640356..d503ba16 100644 --- a/src/cmd/main.go +++ b/src/cmd/main.go @@ -77,6 +77,16 @@ func setupLogging() { func setupHealthCheck() { slog.Info("Bootstrapping health check") + http.HandleFunc("/test400", func(response http.ResponseWriter, request *http.Request) { + slog.Info("4xx ping", slog.String("method", request.Method), slog.String("path", request.URL.String())) + + response.WriteHeader(400) + _, err := io.WriteString(response, "400 Peters are Great") + if err != nil { + slog.Error("Failed to respond to health check", slog.Any(utils.ErrorKey, err)) + } + }) + http.HandleFunc("/", func(response http.ResponseWriter, request *http.Request) { slog.Info("Health check ping", slog.String("method", request.Method), slog.String("path", request.URL.String())) From 5edce31fb009f7c20fd89b0a821f702f8cf6b76a Mon Sep 17 00:00:00 2001 From: saquino0827 Date: Wed, 23 Oct 2024 17:00:38 -0500 Subject: [PATCH 2/4] Terraform linting Co-authored-by: Sylvie Co-authored-by: pluckyswan <96704946+pluckyswan@users.noreply.github.com> Co-authored-by: halprin --- operations/template/main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/operations/template/main.tf b/operations/template/main.tf index 3bdfdd0e..156ca066 100644 --- a/operations/template/main.tf +++ b/operations/template/main.tf @@ -8,7 +8,7 @@ locals { rs_domain_prefix = "${local.selected_rs_environment_prefix}${length(local.selected_rs_environment_prefix) == 0 ? "" : "."}" higher_environment_level = var.environment == "stg" || var.environment == "prd" cdc_domain_environment = var.environment == "dev" || var.environment == "stg" || var.environment == "prd" - non_pr_environment = length(regexall("^pr\\d+", var.environment)) == 0 + non_pr_environment = length(regexall("^pr\\d+", var.environment)) == 0 } data "azurerm_resource_group" "group" { From a5c7963aeedfe620c1e8fa8cf8b0d5dc5237ab58 Mon Sep 17 00:00:00 2001 From: saquino0827 Date: Thu, 24 Oct 2024 11:38:27 -0500 Subject: [PATCH 3/4] Change Count to Total to follow the proper aggregation type Co-authored-by: halprin Co-authored-by: James Herr --- operations/template/alert.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/operations/template/alert.tf b/operations/template/alert.tf index 06775414..32642eb2 100644 --- a/operations/template/alert.tf +++ b/operations/template/alert.tf @@ -16,7 +16,7 @@ resource "azurerm_monitor_metric_alert" "azure_4XX_alert" { criteria { metric_namespace = "Microsoft.Web/sites" metric_name = "Http4xx" - aggregation = "Count" + aggregation = "Total" operator = "GreaterThanOrEqual" threshold = 3 } @@ -42,4 +42,4 @@ resource "azurerm_monitor_metric_alert" "azure_4XX_alert" { tags["zone"] ] } -} \ No newline at end of file +} From 62271b056bc9d2cabd1a000fc8d1c1253b9438c6 Mon Sep 17 00:00:00 2001 From: Bella Luz Quintero Date: Thu, 24 Oct 2024 12:16:32 -0600 Subject: [PATCH 4/4] remove temp bad heath check Co-authored-by: Sylvie --- src/cmd/main.go | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/cmd/main.go b/src/cmd/main.go index d503ba16..c7640356 100644 --- a/src/cmd/main.go +++ b/src/cmd/main.go @@ -77,16 +77,6 @@ func setupLogging() { func setupHealthCheck() { slog.Info("Bootstrapping health check") - http.HandleFunc("/test400", func(response http.ResponseWriter, request *http.Request) { - slog.Info("4xx ping", slog.String("method", request.Method), slog.String("path", request.URL.String())) - - response.WriteHeader(400) - _, err := io.WriteString(response, "400 Peters are Great") - if err != nil { - slog.Error("Failed to respond to health check", slog.Any(utils.ErrorKey, err)) - } - }) - http.HandleFunc("/", func(response http.ResponseWriter, request *http.Request) { slog.Info("Health check ping", slog.String("method", request.Method), slog.String("path", request.URL.String()))