generated from cds-snc/project-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding alarms to the SRE Bot so that we can get alerting when somethi…
…ng is wrong (#333)
- Loading branch information
1 parent
69f238a
commit ca67123
Showing
7 changed files
with
132 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
resource "aws_cloudwatch_log_metric_filter" "sre_bot_error" { | ||
name = local.error_logged | ||
pattern = "?ERROR ?Error" | ||
log_group_name = local.api_cloudwatch_log_group | ||
|
||
metric_transformation { | ||
name = local.error_logged | ||
namespace = local.error_namespace | ||
value = "1" | ||
} | ||
} | ||
|
||
resource "aws_cloudwatch_metric_alarm" "sre_bot_error" { | ||
alarm_name = "SRE Bot Errors" | ||
alarm_description = "Errors logged by the SRE Bot" | ||
comparison_operator = "GreaterThanOrEqualToThreshold" | ||
|
||
metric_name = aws_cloudwatch_log_metric_filter.sre_bot_error.metric_transformation[0].name | ||
namespace = aws_cloudwatch_log_metric_filter.sre_bot_error.metric_transformation[0].namespace | ||
period = "60" | ||
evaluation_periods = "1" | ||
statistic = "Sum" | ||
threshold = var.error_threshold | ||
treat_missing_data = "notBreaching" | ||
|
||
alarm_actions = [aws_sns_topic.cloudwatch_warning.arn] | ||
ok_actions = [aws_sns_topic.cloudwatch_warning.arn] | ||
} | ||
|
||
resource "aws_cloudwatch_log_metric_filter" "sre_bot_warning" { | ||
name = local.warning_logged | ||
pattern = "?WARNING ?Warning" | ||
log_group_name = local.api_cloudwatch_log_group | ||
|
||
metric_transformation { | ||
name = local.warning_logged | ||
namespace = local.error_namespace | ||
value = "1" | ||
} | ||
} | ||
|
||
resource "aws_cloudwatch_metric_alarm" "sre_bot_warning" { | ||
alarm_name = "SRE Bot Warnings" | ||
alarm_description = "Warnings logged by the SRE Bot" | ||
comparison_operator = "GreaterThanOrEqualToThreshold" | ||
|
||
metric_name = aws_cloudwatch_log_metric_filter.sre_bot_warning.metric_transformation[0].name | ||
namespace = aws_cloudwatch_log_metric_filter.sre_bot_warning.metric_transformation[0].namespace | ||
period = "60" | ||
evaluation_periods = "1" | ||
statistic = "Sum" | ||
threshold = var.warning_threshold | ||
treat_missing_data = "notBreaching" | ||
|
||
alarm_actions = [aws_sns_topic.cloudwatch_warning.arn] | ||
ok_actions = [aws_sns_topic.cloudwatch_warning.arn] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
locals { | ||
api_cloudwatch_log_group = "/ecs/sre-bot-app" | ||
error_logged = "SREBotErrorLogged" | ||
error_namespace = "SREBot" | ||
warning_logged = "SREBotWarningLogged" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
resource "aws_cloudwatch_query_definition" "api_errors" { | ||
name = "SRE Bot Errors" | ||
|
||
log_group_names = [ | ||
local.api_cloudwatch_log_group | ||
] | ||
|
||
query_string = <<-QUERY | ||
fields @timestamp, @message, @logStream | ||
| filter @message like /(?i)ERROR|FAILED/ | ||
| sort @timestamp desc | ||
| limit 20 | ||
QUERY | ||
} | ||
|
||
resource "aws_cloudwatch_query_definition" "api_warnings" { | ||
name = "SRE Bot Warnings" | ||
|
||
log_group_names = [ | ||
local.api_cloudwatch_log_group | ||
] | ||
|
||
query_string = <<-QUERY | ||
fields @timestamp, @message, @logStream | ||
| filter @message like /WARNING/ | ||
| sort @timestamp desc | ||
| limit 20 | ||
QUERY | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# | ||
# SNS: topic & subscription | ||
# | ||
resource "aws_sns_topic" "cloudwatch_warning" { | ||
name = "sre-bot-cloudwatch-alarms-warning" | ||
|
||
tags = { | ||
CostCentre = var.billing_code | ||
Terraform = true | ||
} | ||
} | ||
|
||
resource "aws_sns_topic_subscription" "alert_warning" { | ||
topic_arn = aws_sns_topic.cloudwatch_warning.arn | ||
protocol = "https" | ||
endpoint = var.slack_webhook_url | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters