Skip to content

Commit 2c9cf62

Browse files
PRMT-466- cleaned code
1 parent c77e995 commit 2c9cf62

File tree

1 file changed

+5
-30
lines changed

1 file changed

+5
-30
lines changed

infrastructure/sqs_alarms.tf

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,11 @@ locals {
1313
"stitching_dlq" = "${terraform.workspace}-deadletter-stitching-queue"
1414
"mns_dlq" = "${terraform.workspace}-deadletter-mns-notification-queue"
1515
}
16-
# days_until_alarm = [6, 10]
1716
days_until_alarm = [
1817
[6, "medium"],
1918
[10, "high"]
2019
]
2120

22-
# default_alarm_threshold_seconds = 6 #6 * 24 * 60 * 60 # 6 days
23-
# using a list instead of map
24-
2521
flat_list = flatten([
2622
for queue_key in keys(local.monitored_queues) : [
2723
for day in local.days_until_alarm : [
@@ -80,7 +76,6 @@ module "global_sqs_age_alarm_topic" {
8076

8177
resource "aws_cloudwatch_metric_alarm" "sqs_oldest_message" {
8278
count = local.is_test_sandbox ? 0 : length(local.monitored_queue_day_list) # TODO:change is_test_sandbox to is_sandbox
83-
# alarm_name = "${terraform.workspace}_${local.monitored_queue_day_list[count.index][0]}_oldest_message_alarm"
8479

8580
alarm_name = "${terraform.workspace}_${local.monitored_queue_day_list[count.index][0]}_oldest_message_alarm_${local.monitored_queue_day_list[count.index][2]}d"
8681
comparison_operator = "GreaterThanThreshold"
@@ -89,46 +84,30 @@ resource "aws_cloudwatch_metric_alarm" "sqs_oldest_message" {
8984
namespace = "AWS/SQS"
9085
period = 60 # TODO: change to 86400 (24h))
9186
statistic = "Maximum"
92-
# threshold = each.value.days # TODO: change to each.value.days*24*60*60
93-
threshold = local.monitored_queue_day_list[count.index][2] # TODO: change to each.value.days*24*60*60
94-
# threshold = local.default_alarm_threshold_seconds
95-
treat_missing_data = "notBreaching"
87+
threshold = local.monitored_queue_day_list[count.index][2] # TODO: change to local.monitored_queue_day_list[count.index][2]*24*60*60
88+
treat_missing_data = "notBreaching"
9689

9790
dimensions = {
98-
# QueueName = each.value.queue_name
9991
QueueName = local.monitored_queue_day_list[count.index][1]
100-
# QueueName = each.value
10192
}
10293

103-
# alarm_description = "Alarm when a message in queue '${each.value.queue_name}' is older than '${each.value.days}' days."
10494
alarm_description = "Alarm when a message in queue '${local.monitored_queue_day_list[count.index][1]}' is older than '${local.monitored_queue_day_list[count.index][2]}' days."
10595

106-
# alarm_actions = [module.global_sqs_age_alarm_topic[0].arn]
10796
alarm_actions = [module.sqs_alarm_lambda_topic.arn]
97+
ok_actions = [module.sqs_alarm_lambda_topic.arn]
10898

10999
tags = {
110-
# Name = "${terraform.workspace}_${each.value.queue_key}_oldest_message_alarm_${each.value.days}d"
111-
Name = "${terraform.workspace}_${local.monitored_queue_day_list[count.index][0]}_oldest_message_alarm_${local.monitored_queue_day_list[count.index][2]}d"
112-
# Name = "${terraform.workspace}_${local.monitored_queue_day_list[count.index][0]}_oldest_message_alarm"
100+
Name = "${terraform.workspace}_${local.monitored_queue_day_list[count.index][0]}_oldest_message_alarm_${local.monitored_queue_day_list[count.index][2]}d"
113101
Owner = var.owner
114102
Environment = var.environment
115103
Workspace = terraform.workspace
116104
severity = local.monitored_queue_day_list[count.index][3]
117105
alarm_group = local.monitored_queue_day_list[count.index][1]
118-
# alarm_group =each.value
119106
# alarm_metric = "Has messages older than ${local.monitored_queue_day_list[count.index][2]} days"
120-
# alarm_metric = "${local.monitored_queue_day_list[count.index][2]}d"
121107
alarm_metric = "ApproximateAgeOfOldestMessage"
122108
is_kpi = "true"
123109
}
124110
}
125-
# resource "aws_sns_topic_subscription" "sqs_oldest_message_alarm" {
126-
# for_each = local.is_test_sandbox ? toset([]) : toset(nonsensitive(split(",", data.aws_ssm_parameter.cloud_security_notification_email_list.value))) # TODO:change is_test_sandbox to is_sandbox
127-
# endpoint = each.value
128-
# protocol = "email"
129-
# topic_arn = module.global_sqs_age_alarm_topic[0].arn
130-
# }
131-
132111

133112
module "sqs_alarm_lambda_topic" {
134113
source = "../infrastructure/modules/sns"
@@ -164,8 +143,4 @@ resource "aws_lambda_permission" "sqs_alerting_lambda_permission" {
164143
function_name = module.im-alerting-lambda.lambda_arn
165144
principal = "sns.amazonaws.com"
166145
source_arn = module.sqs_alarm_lambda_topic.arn
167-
}
168-
169-
170-
171-
146+
}

0 commit comments

Comments
 (0)