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

fix: publish Glue job failures to SNS #24

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
20 changes: 0 additions & 20 deletions terragrunt/aws/alarms/alarms.tf
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,6 @@ resource "aws_cloudwatch_metric_alarm" "glue_crawler_error" {
ok_actions = [aws_sns_topic.cloudwatch_ok_action.arn]
}

resource "aws_cloudwatch_metric_alarm" "glue_job_failures" {
alarm_name = "glue-job-failures"
alarm_description = "Failed Glue jobs in a 1 minute period."
comparison_operator = "GreaterThanThreshold"
evaluation_periods = "1"
metric_name = local.glue_job_failure_metric_name
namespace = local.data_lake_namespace
period = "60"
statistic = "Sum"
threshold = "0"
treat_missing_data = "notBreaching"

alarm_actions = [aws_sns_topic.cloudwatch_alarm_action.arn]
ok_actions = [aws_sns_topic.cloudwatch_ok_action.arn]

dimensions = {
JobName = "*"
}
}

#
# Log Insight queries
#
Expand Down
28 changes: 16 additions & 12 deletions terragrunt/aws/alarms/eventbridge.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,31 @@ resource "aws_cloudwatch_event_rule" "glue_job_failure" {
})
}

#
# Publish Glue Job failures to SNS using a CloudWatch Alarm message payload.
# This allows us to use the existing SRE Bot webhooks to post to Slack.
#
resource "aws_cloudwatch_event_target" "glue_job_failure" {
rule = aws_cloudwatch_event_rule.glue_job_failure.name
target_id = "PublishMetric"
arn = "arn:aws:events:${var.region}:${var.account_id}:api-destination/cloudwatch-metrics"
target_id = "send-to-sns"
arn = aws_sns_topic.cloudwatch_alarm_action.arn

input_transformer {
input_paths = {
jobName = "$.detail.jobName"
state = "$.detail.state"
message = "$.detail.message"
}
input_template = jsonencode({
MetricData = [{
MetricName = local.glue_job_failure_metric_name
Value = 1
Unit = "Count"
Dimensions = [{
Name = "JobName"
Value = "<jobName>"
}]
}]
Namespace = local.data_lake_namespace
Message = jsonencode({
AlarmArn = "arn:aws:cloudwatch:${var.region}:${var.account_id}:alarm:glue-job-failure",
AlarmName = "glue-job-failure",
AlarmDescription = "`<state>` detected for Glue job `<jobName>`",
AWSAccountId = var.account_id,
OldStateValue = "OK",
NewStateValue = "ALARM",
NewStateReason = "<message>",
})
})
}
}
1 change: 0 additions & 1 deletion terragrunt/aws/alarms/locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ locals {
data_lake_namespace = "data-lake"
glue_crawler_metric_filter_error_pattern = "ERROR"
glue_crawler_error_metric_name = "glue-crawler-error"
glue_job_failure_metric_name = "glue-job-failure"
}
Loading