Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add CloudWatch metrics for Lambda behaviour #683

Merged
merged 2 commits into from
Jun 13, 2024

Conversation

patheard
Copy link
Member

Summary

Add CloudWatch metric filters for the following Lambda functions:

  • Form archiver
  • Reliability
  • Response archiver
  • Submission

These will be used to build out dashboards and create health check alarms if success metrics are not observed consistency.

Add success log events and a status property to the form-archiver and response-archiver Lambda functions.

Related

Add CloudWatch metric filters for the following Lambda functions:
- Form archiver
- Reliability
- Response archiver
- Submission
These will be used to build out dashboards and create healthcheck
alarms if success metrics are not observed consistenly.

Add succes log events and a `status` property to the form-archiver
and response-archiver Lambda functions.
@patheard patheard self-assigned this Jun 13, 2024
Copy link

⚠ Terrform update available

Terraform: 1.8.5 (using 1.6.6)
Terragrunt: 0.59.3 (using 0.54.8)

Copy link

Staging: alarms

✅   Terraform Init: success
✅   Terraform Validate: success
✅   Terraform Format: success
✅   Terraform Plan: success
✅   Conftest: success

⚠️   Warning: resources will be destroyed by this change!

Plan: 18 to add, 0 to change, 2 to destroy
Show summary
CHANGE NAME
add aws_cloudwatch_log_metric_filter.healthcheck["ClientSubmitFailed"]
aws_cloudwatch_log_metric_filter.healthcheck["ClientSubmitSuccess"]
aws_cloudwatch_log_metric_filter.healthcheck["FormArchiverFailed"]
aws_cloudwatch_log_metric_filter.healthcheck["FormArchiverSuccess"]
aws_cloudwatch_log_metric_filter.healthcheck["FormArchiverWarn"]
aws_cloudwatch_log_metric_filter.healthcheck["ReliabilityFailed"]
aws_cloudwatch_log_metric_filter.healthcheck["ReliabilityNotifySendFailed"]
aws_cloudwatch_log_metric_filter.healthcheck["ReliabilityNotifySendSuccess"]
aws_cloudwatch_log_metric_filter.healthcheck["ReliabilitySuccess"]
aws_cloudwatch_log_metric_filter.healthcheck["ReliabilityVaultSaveFailed"]
aws_cloudwatch_log_metric_filter.healthcheck["ReliabilityVaultSaveSuccess"]
aws_cloudwatch_log_metric_filter.healthcheck["ReliabilityWarn"]
aws_cloudwatch_log_metric_filter.healthcheck["ResponseArchiverFailed"]
aws_cloudwatch_log_metric_filter.healthcheck["ResponseArchiverSuccess"]
aws_cloudwatch_log_metric_filter.healthcheck["ResponseArchiverWarn"]
aws_cloudwatch_log_metric_filter.healthcheck["SubmissionFailed"]
aws_cloudwatch_log_metric_filter.healthcheck["SubmissionSuccess"]
aws_cloudwatch_log_metric_filter.healthcheck["SubmissionWarn"]
delete aws_cloudwatch_log_metric_filter.healthcheck["FormsClientSubmitFailed"]
aws_cloudwatch_log_metric_filter.healthcheck["FormsClientSubmitSuccess"]
Show plan
Resource actions are indicated with the following symbols:
  + create
  - destroy

Terraform will perform the following actions:

  # aws_cloudwatch_log_metric_filter.healthcheck["ClientSubmitFailed"] will be created
  + resource "aws_cloudwatch_log_metric_filter" "healthcheck" {
      + id             = (known after apply)
      + log_group_name = "Forms"
      + name           = "ClientSubmitFailed"
      + pattern        = "Attempted response submission for Form ID"

      + metric_transformation {
          + default_value = "0"
          + name          = "ClientSubmitFailed"
          + namespace     = "forms"
          + unit          = "Count"
          + value         = "1"
        }
    }

  # aws_cloudwatch_log_metric_filter.healthcheck["ClientSubmitSuccess"] will be created
  + resource "aws_cloudwatch_log_metric_filter" "healthcheck" {
      + id             = (known after apply)
      + log_group_name = "Forms"
      + name           = "ClientSubmitSuccess"
      + pattern        = "Response submitted for Form ID"

      + metric_transformation {
          + default_value = "0"
          + name          = "ClientSubmitSuccess"
          + namespace     = "forms"
          + unit          = "Count"
          + value         = "1"
        }
    }

  # aws_cloudwatch_log_metric_filter.healthcheck["FormArchiverFailed"] will be created
  + resource "aws_cloudwatch_log_metric_filter" "healthcheck" {
      + id             = (known after apply)
      + log_group_name = "/aws/lambda/Archive_Form_Templates"
      + name           = "FormArchiverFailed"
      + pattern        = "{$.status = \"failed\"}"

      + metric_transformation {
          + default_value = "0"
          + name          = "FormArchiverFailed"
          + namespace     = "forms"
          + unit          = "Count"
          + value         = "1"
        }
    }

  # aws_cloudwatch_log_metric_filter.healthcheck["FormArchiverSuccess"] will be created
  + resource "aws_cloudwatch_log_metric_filter" "healthcheck" {
      + id             = (known after apply)
      + log_group_name = "/aws/lambda/Archive_Form_Templates"
      + name           = "FormArchiverSuccess"
      + pattern        = "{$.status = \"success\"}"

      + metric_transformation {
          + default_value = "0"
          + name          = "FormArchiverSuccess"
          + namespace     = "forms"
          + unit          = "Count"
          + value         = "1"
        }
    }

  # aws_cloudwatch_log_metric_filter.healthcheck["FormArchiverWarn"] will be created
  + resource "aws_cloudwatch_log_metric_filter" "healthcheck" {
      + id             = (known after apply)
      + log_group_name = "/aws/lambda/Archive_Form_Templates"
      + name           = "FormArchiverWarn"
      + pattern        = "{$.level = \"warn\"}"

      + metric_transformation {
          + default_value = "0"
          + name          = "FormArchiverWarn"
          + namespace     = "forms"
          + unit          = "Count"
          + value         = "1"
        }
    }

  # aws_cloudwatch_log_metric_filter.healthcheck["FormsClientSubmitFailed"] will be destroyed
  # (because key ["FormsClientSubmitFailed"] is not in for_each map)
  - resource "aws_cloudwatch_log_metric_filter" "healthcheck" {
      - id             = "FormsClientSubmitFailed" -> null
      - log_group_name = "Forms" -> null
      - name           = "FormsClientSubmitFailed" -> null
      - pattern        = "Attempted response submission for Form ID" -> null

      - metric_transformation {
          - default_value = "0" -> null
          - dimensions    = {} -> null
          - name          = "FormsClientSubmitFailed" -> null
          - namespace     = "forms" -> null
          - unit          = "Count" -> null
          - value         = "1" -> null
        }
    }

  # aws_cloudwatch_log_metric_filter.healthcheck["FormsClientSubmitSuccess"] will be destroyed
  # (because key ["FormsClientSubmitSuccess"] is not in for_each map)
  - resource "aws_cloudwatch_log_metric_filter" "healthcheck" {
      - id             = "FormsClientSubmitSuccess" -> null
      - log_group_name = "Forms" -> null
      - name           = "FormsClientSubmitSuccess" -> null
      - pattern        = "Response submitted for Form ID" -> null

      - metric_transformation {
          - default_value = "0" -> null
          - dimensions    = {} -> null
          - name          = "FormsClientSubmitSuccess" -> null
          - namespace     = "forms" -> null
          - unit          = "Count" -> null
          - value         = "1" -> null
        }
    }

  # aws_cloudwatch_log_metric_filter.healthcheck["ReliabilityFailed"] will be created
  + resource "aws_cloudwatch_log_metric_filter" "healthcheck" {
      + id             = (known after apply)
      + log_group_name = "/aws/lambda/Reliability"
      + name           = "ReliabilityFailed"
      + pattern        = "{$.status = \"failed\"}"

      + metric_transformation {
          + default_value = "0"
          + name          = "ReliabilityFailed"
          + namespace     = "forms"
          + unit          = "Count"
          + value         = "1"
        }
    }

  # aws_cloudwatch_log_metric_filter.healthcheck["ReliabilityNotifySendFailed"] will be created
  + resource "aws_cloudwatch_log_metric_filter" "healthcheck" {
      + id             = (known after apply)
      + log_group_name = "/aws/lambda/Reliability"
      + name           = "ReliabilityNotifySendFailed"
      + pattern        = "Failed to send submission through GC Notify"

      + metric_transformation {
          + default_value = "0"
          + name          = "ReliabilityNotifySendFailed"
          + namespace     = "forms"
          + unit          = "Count"
          + value         = "1"
        }
    }

  # aws_cloudwatch_log_metric_filter.healthcheck["ReliabilityNotifySendSuccess"] will be created
  + resource "aws_cloudwatch_log_metric_filter" "healthcheck" {
      + id             = (known after apply)
      + log_group_name = "/aws/lambda/Reliability"
      + name           = "ReliabilityNotifySendSuccess"
      + pattern        = "Successfully sent submission through GC Notify"

      + metric_transformation {
          + default_value = "0"
          + name          = "ReliabilityNotifySendSuccess"
          + namespace     = "forms"
          + unit          = "Count"
          + value         = "1"
        }
    }

  # aws_cloudwatch_log_metric_filter.healthcheck["ReliabilitySuccess"] will be created
  + resource "aws_cloudwatch_log_metric_filter" "healthcheck" {
      + id             = (known after apply)
      + log_group_name = "/aws/lambda/Reliability"
      + name           = "ReliabilitySuccess"
      + pattern        = "{$.status = \"success\"}"

      + metric_transformation {
          + default_value = "0"
          + name          = "ReliabilitySuccess"
          + namespace     = "forms"
          + unit          = "Count"
          + value         = "1"
        }
    }

  # aws_cloudwatch_log_metric_filter.healthcheck["ReliabilityVaultSaveFailed"] will be created
  + resource "aws_cloudwatch_log_metric_filter" "healthcheck" {
      + id             = (known after apply)
      + log_group_name = "/aws/lambda/Reliability"
      + name           = "ReliabilityVaultSaveFailed"
      + pattern        = "Failed to save submission to Vault"

      + metric_transformation {
          + default_value = "0"
          + name          = "ReliabilityVaultSaveFailed"
          + namespace     = "forms"
          + unit          = "Count"
          + value         = "1"
        }
    }

  # aws_cloudwatch_log_metric_filter.healthcheck["ReliabilityVaultSaveSuccess"] will be created
  + resource "aws_cloudwatch_log_metric_filter" "healthcheck" {
      + id             = (known after apply)
      + log_group_name = "/aws/lambda/Reliability"
      + name           = "ReliabilityVaultSaveSuccess"
      + pattern        = "Successfully saved submission to Vault"

      + metric_transformation {
          + default_value = "0"
          + name          = "ReliabilityVaultSaveSuccess"
          + namespace     = "forms"
          + unit          = "Count"
          + value         = "1"
        }
    }

  # aws_cloudwatch_log_metric_filter.healthcheck["ReliabilityWarn"] will be created
  + resource "aws_cloudwatch_log_metric_filter" "healthcheck" {
      + id             = (known after apply)
      + log_group_name = "/aws/lambda/Reliability"
      + name           = "ReliabilityWarn"
      + pattern        = "{$.level = \"warn\"}"

      + metric_transformation {
          + default_value = "0"
          + name          = "ReliabilityWarn"
          + namespace     = "forms"
          + unit          = "Count"
          + value         = "1"
        }
    }

  # aws_cloudwatch_log_metric_filter.healthcheck["ResponseArchiverFailed"] will be created
  + resource "aws_cloudwatch_log_metric_filter" "healthcheck" {
      + id             = (known after apply)
      + log_group_name = "/aws/lambda/Response_Archiver"
      + name           = "ResponseArchiverFailed"
      + pattern        = "{$.status = \"failed\"}"

      + metric_transformation {
          + default_value = "0"
          + name          = "ResponseArchiverFailed"
          + namespace     = "forms"
          + unit          = "Count"
          + value         = "1"
        }
    }

  # aws_cloudwatch_log_metric_filter.healthcheck["ResponseArchiverSuccess"] will be created
  + resource "aws_cloudwatch_log_metric_filter" "healthcheck" {
      + id             = (known after apply)
      + log_group_name = "/aws/lambda/Response_Archiver"
      + name           = "ResponseArchiverSuccess"
      + pattern        = "{$.status = \"success\"}"

      + metric_transformation {
          + default_value = "0"
          + name          = "ResponseArchiverSuccess"
          + namespace     = "forms"
          + unit          = "Count"
          + value         = "1"
        }
    }

  # aws_cloudwatch_log_metric_filter.healthcheck["ResponseArchiverWarn"] will be created
  + resource "aws_cloudwatch_log_metric_filter" "healthcheck" {
      + id             = (known after apply)
      + log_group_name = "/aws/lambda/Response_Archiver"
      + name           = "ResponseArchiverWarn"
      + pattern        = "{$.level = \"warn\"}"

      + metric_transformation {
          + default_value = "0"
          + name          = "ResponseArchiverWarn"
          + namespace     = "forms"
          + unit          = "Count"
          + value         = "1"
        }
    }

  # aws_cloudwatch_log_metric_filter.healthcheck["SubmissionFailed"] will be created
  + resource "aws_cloudwatch_log_metric_filter" "healthcheck" {
      + id             = (known after apply)
      + log_group_name = "/aws/lambda/Submission"
      + name           = "SubmissionFailed"
      + pattern        = "{$.status = \"failed\"}"

      + metric_transformation {
          + default_value = "0"
          + name          = "SubmissionFailed"
          + namespace     = "forms"
          + unit          = "Count"
          + value         = "1"
        }
    }

  # aws_cloudwatch_log_metric_filter.healthcheck["SubmissionSuccess"] will be created
  + resource "aws_cloudwatch_log_metric_filter" "healthcheck" {
      + id             = (known after apply)
      + log_group_name = "/aws/lambda/Submission"
      + name           = "SubmissionSuccess"
      + pattern        = "{$.status = \"success\"}"

      + metric_transformation {
          + default_value = "0"
          + name          = "SubmissionSuccess"
          + namespace     = "forms"
          + unit          = "Count"
          + value         = "1"
        }
    }

  # aws_cloudwatch_log_metric_filter.healthcheck["SubmissionWarn"] will be created
  + resource "aws_cloudwatch_log_metric_filter" "healthcheck" {
      + id             = (known after apply)
      + log_group_name = "/aws/lambda/Submission"
      + name           = "SubmissionWarn"
      + pattern        = "{$.level = \"warn\"}"

      + metric_transformation {
          + default_value = "0"
          + name          = "SubmissionWarn"
          + namespace     = "forms"
          + unit          = "Count"
          + value         = "1"
        }
    }

Plan: 18 to add, 0 to change, 2 to destroy.

Warning: Argument is deprecated

  with module.athena_bucket.aws_s3_bucket.this,
  on .terraform/modules/athena_bucket/S3/main.tf line 8, in resource "aws_s3_bucket" "this":
   8: resource "aws_s3_bucket" "this" {

Use the aws_s3_bucket_server_side_encryption_configuration resource instead

(and 3 more similar warnings elsewhere)

─────────────────────────────────────────────────────────────────────────────

Saved the plan to: plan.tfplan

To perform exactly these actions, run the following command to apply:
    terraform apply "plan.tfplan"
Show Conftest results
WARN - plan.json - main - Missing Common Tags: ["aws_cloudwatch_event_rule.codedeploy_sns"]
WARN - plan.json - main - Missing Common Tags: ["aws_cloudwatch_log_group.notify_slack"]
WARN - plan.json - main - Missing Common Tags: ["aws_cloudwatch_metric_alarm.ELB_5xx_error_warn"]
WARN - plan.json - main - Missing Common Tags: ["aws_cloudwatch_metric_alarm.UnHealthyHostCount-TargetGroup1"]
WARN - plan.json - main - Missing Common Tags: ["aws_cloudwatch_metric_alarm.UnHealthyHostCount-TargetGroup2"]
WARN - plan.json - main - Missing Common Tags: ["aws_cloudwatch_metric_alarm.alb_ddos"]
WARN - plan.json - main - Missing Common Tags: ["aws_cloudwatch_metric_alarm.audit_log_dead_letter_queue_warn"]
WARN - plan.json - main - Missing Common Tags: ["aws_cloudwatch_metric_alarm.cognito_login_outside_canada_warn"]
WARN - plan.json - main - Missing Common Tags: ["aws_cloudwatch_metric_alarm.cognito_signin_exceeded"]
WARN - plan.json - main - Missing Common Tags: ["aws_cloudwatch_metric_alarm.ddos_detected_forms_warn"]
WARN - plan.json - main - Missing Common Tags: ["aws_cloudwatch_metric_alarm.ddos_detected_route53_warn[0]"]
WARN - plan.json - main - Missing Common Tags: ["aws_cloudwatch_metric_alarm.forms_cpu_utilization_high_warn"]
WARN - plan.json - main - Missing Common Tags: ["aws_cloudwatch_metric_alarm.forms_memory_utilization_high_warn"]
WARN - plan.json - main - Missing Common Tags: ["aws_cloudwatch_metric_alarm.reliability_dead_letter_queue_warn"]
WARN - plan.json - main - Missing Common Tags: ["aws_cloudwatch_metric_alarm.response_time_warn"]
WARN - plan.json - main - Missing Common Tags: ["aws_cloudwatch_metric_alarm.route53_ddos[0]"]
WARN - plan.json - main - Missing Common Tags: ["aws_cloudwatch_metric_alarm.twoFa_verification_exceeded"]
WARN - plan.json - main - Missing Common Tags: ["aws_cloudwatch_metric_alarm.vault_data_integrity_check_lambda_iterator_age"]
WARN - plan.json - main - Missing Common Tags: ["aws_iam_role.notify_slack_lambda"]
WARN - plan.json -...

Copy link
Contributor

@craigzour craigzour left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@patheard patheard merged commit 489db64 into develop Jun 13, 2024
12 checks passed
@patheard patheard deleted the feat/lambda-metrics branch June 13, 2024 18:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants