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

DR2-1668 Use RATE for DLQ alarms. #44

Merged
merged 5 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 34 additions & 12 deletions sqs/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,42 @@ resource "aws_sqs_queue" "dlq_with_sse" {
sqs_managed_sse_enabled = true
}

module "dlq_cloudwatch_alarm" {
source = "../cloudwatch_alarms"
metric_name = "ApproximateNumberOfMessagesVisible"
namespace = "AWS/SQS"
name = "${var.queue_name}-messages-visible--dlq-alarm"
threshold = var.dlq_cloudwatch_alarm_visible_messages_threshold
resource "aws_cloudwatch_metric_alarm" "dlq_metric_alarm" {
alarm_name = "${var.queue_name}-messages-visible--dlq-alarm"
comparison_operator = "GreaterThanThreshold"
statistic = "Sum"
treat_missing_data = "ignore"
datapoints_to_alarm = 1
dimensions = {
QueueName = local.sqs_dlq.name
evaluation_periods = 60
metric_query {
id = "m1"
metric {
dimensions = {
QueueName = "${var.queue_name}-dlq"
}
metric_name = "ApproximateNumberOfMessagesVisible"
period = 60
Copy link
Contributor

Choose a reason for hiding this comment

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

Just to add, should/could these periods be added to a variable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, can do. I've added a single variable as I can't see why we'd want different evaluation periods for the different metrics. I've defaulted them to 60 as this seems sensible.

stat = "Maximum"
namespace = "AWS/SQS"
}
}
metric_query {
id = "m2"
metric {
dimensions = {
QueueName = "${var.queue_name}-dlq"
}
metric_name = "ApproximateNumberOfMessagesVisible"
period = 60
stat = "Maximum"
namespace = "AWS/SQS"
}
}
notification_topic = var.dlq_notification_topic
metric_query {
expression = "RATE(m1+m2)"
id = "e1"
label = "AllMessagesInQueue"
period = 60
return_data = true
}

}

module "queue_cloudwatch_alarm" {
Expand Down
2 changes: 1 addition & 1 deletion sqs/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ output "dlq_sqs_url" {
}

output "dlq_cloudwatch_alarm_arn" {
value = var.dlq_notification_topic == "" ? "" : module.dlq_cloudwatch_alarm.*.cloudwatch_alarm_arn[0]
value = aws_cloudwatch_metric_alarm.dlq_metric_alarm.arn
}