carlos / platform Public

region-host: reboot alarm waits 3 min so recover goes first

Astra round 1 P1: with both alarms at 2 x 60 s a system failure (which
usually fails the instance check too) could fire reboot and recover
together. AWS advises the reboot alarm wait three periods. P2: the
override tests now check alarm_actions as well as ok_actions, for both
the email topic and an existing alerts_topic_arn.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 563d401ec7652e102350bde7931abab69edb4784 parent 846784f
2 files changed, +35 −9
  • infra/modules/region-host/main.tf +7 −4
  • infra/modules/region-host/tests/health_alarms.tftest.hcl +28 −5

CI cancelled — superseded by a newer push — run details

diff --git a/infra/modules/region-host/main.tf b/infra/modules/region-host/main.tf
index 7eee0ad32..dd749ba85 100644
--- a/infra/modules/region-host/main.tf
+++ b/infra/modules/region-host/main.tf
@@ -633,17 +633,20 @@ resource "aws_cloudwatch_metric_alarm" "host_auto_recover" {
# The other half of the status checks: the hardware is fine but the guest has
# stopped answering (kernel hang, exhausted memory, broken network config).
-# EC2's own remedy for that is a reboot; recover does not apply.
+# EC2's own remedy for that is a reboot; recover does not apply. A system
+# failure usually fails the instance check too, so this alarm waits three
+# minutes to the recover alarm's two: recover goes first, as AWS advises,
+# rather than racing a reboot on the same impaired box.
resource "aws_cloudwatch_metric_alarm" "host_instance_check" {
count = var.mode == "fixed" && var.enable_auto_recovery ? 1 : 0
alarm_name = "${var.name}-instance-check"
- alarm_description = "EC2 instance-status-check failure on ${var.name} for 2 minutes: the box is rebooted. If it fails again after the reboot, read the instance's console output."
+ alarm_description = "EC2 instance-status-check failure on ${var.name} for 3 minutes: the box is rebooted. If it fails again after the reboot, read the instance's console output."
namespace = "AWS/EC2"
metric_name = "StatusCheckFailed_Instance"
statistic = "Maximum"
period = 60
- evaluation_periods = 2
- datapoints_to_alarm = 2
+ evaluation_periods = 3
+ datapoints_to_alarm = 3
threshold = 1
comparison_operator = "GreaterThanOrEqualToThreshold"
treat_missing_data = "missing"
diff --git a/infra/modules/region-host/tests/health_alarms.tftest.hcl b/infra/modules/region-host/tests/health_alarms.tftest.hcl
index 09c41242f..bf587613b 100644
--- a/infra/modules/region-host/tests/health_alarms.tftest.hcl
+++ b/infra/modules/region-host/tests/health_alarms.tftest.hcl
@@ -81,23 +81,24 @@ run "status_alarms_without_any_topic" {
aws_cloudwatch_metric_alarm.host_instance_check[0].metric_name == "StatusCheckFailed_Instance" &&
aws_cloudwatch_metric_alarm.host_instance_check[0].statistic == "Maximum" &&
aws_cloudwatch_metric_alarm.host_instance_check[0].period == 60 &&
- aws_cloudwatch_metric_alarm.host_instance_check[0].evaluation_periods == 2 &&
- aws_cloudwatch_metric_alarm.host_instance_check[0].datapoints_to_alarm == 2 &&
+ aws_cloudwatch_metric_alarm.host_instance_check[0].evaluation_periods == 3 &&
+ aws_cloudwatch_metric_alarm.host_instance_check[0].datapoints_to_alarm == 3 &&
aws_cloudwatch_metric_alarm.host_instance_check[0].threshold == 1 &&
aws_cloudwatch_metric_alarm.host_instance_check[0].comparison_operator == "GreaterThanOrEqualToThreshold" &&
aws_cloudwatch_metric_alarm.host_instance_check[0].treat_missing_data == "missing" &&
aws_cloudwatch_metric_alarm.host_instance_check[0].dimensions == tomap({ InstanceId = "i-0123456789abcdef0" })
)
- error_message = "instance-check alarm must watch this instance's instance status check, 2 of 2 one-minute periods"
+ error_message = "instance-check alarm must watch this instance's instance status check, 3 of 3 one-minute periods"
}
assert {
condition = (
aws_cloudwatch_metric_alarm.host_auto_recover[0].metric_name == "StatusCheckFailed_System" &&
aws_cloudwatch_metric_alarm.host_auto_recover[0].period == 60 &&
aws_cloudwatch_metric_alarm.host_auto_recover[0].evaluation_periods == 2 &&
+ aws_cloudwatch_metric_alarm.host_auto_recover[0].evaluation_periods < aws_cloudwatch_metric_alarm.host_instance_check[0].evaluation_periods &&
aws_cloudwatch_metric_alarm.host_auto_recover[0].dimensions == tomap({ InstanceId = "i-0123456789abcdef0" })
)
- error_message = "auto-recover alarm's metric and timing must not change"
+ error_message = "auto-recover alarm's metric and timing must not change, and it must fire before the reboot alarm"
}
}
@@ -160,7 +161,7 @@ run "health_topic_alone_arms_nothing_else" {
}
}
-run "health_topic_overrides_the_alerts_topic" {
+run "health_topic_overrides_the_alerts_email_topic" {
command = plan
variables {
alerts_email = "ops@example.com"
@@ -168,6 +169,9 @@ run "health_topic_overrides_the_alerts_topic" {
}
assert {
condition = (
+ aws_cloudwatch_metric_alarm.host_auto_recover[0].alarm_actions == toset(["arn:aws:automate:eu-west-1:ec2:recover", "arn:aws:sns:eu-west-1:123456789012:dev-ha-alerts"]) &&
+ aws_cloudwatch_metric_alarm.host_instance_check[0].alarm_actions == toset(["arn:aws:automate:eu-west-1:ec2:reboot", "arn:aws:sns:eu-west-1:123456789012:dev-ha-alerts"]) &&
+ aws_cloudwatch_metric_alarm.host_memory_low[0].alarm_actions == toset(["arn:aws:sns:eu-west-1:123456789012:carlos-test-ie-alerts"]) &&
aws_cloudwatch_metric_alarm.host_auto_recover[0].ok_actions == toset(["arn:aws:sns:eu-west-1:123456789012:dev-ha-alerts"]) &&
aws_cloudwatch_metric_alarm.host_instance_check[0].ok_actions == toset(["arn:aws:sns:eu-west-1:123456789012:dev-ha-alerts"]) &&
aws_cloudwatch_metric_alarm.host_memory_low[0].ok_actions == toset(["arn:aws:sns:eu-west-1:123456789012:carlos-test-ie-alerts"])
@@ -176,6 +180,25 @@ run "health_topic_overrides_the_alerts_topic" {
}
}
+run "health_topic_overrides_the_alerts_topic_arn" {
+ command = plan
+ variables {
+ alerts_topic_arn = "arn:aws:sns:eu-west-1:123456789012:permanent-ha-alerts"
+ health_alerts_topic_arn = "arn:aws:sns:eu-west-1:123456789012:dev-ha-alerts"
+ }
+ assert {
+ condition = (
+ aws_cloudwatch_metric_alarm.host_auto_recover[0].alarm_actions == toset(["arn:aws:automate:eu-west-1:ec2:recover", "arn:aws:sns:eu-west-1:123456789012:dev-ha-alerts"]) &&
+ aws_cloudwatch_metric_alarm.host_instance_check[0].alarm_actions == toset(["arn:aws:automate:eu-west-1:ec2:reboot", "arn:aws:sns:eu-west-1:123456789012:dev-ha-alerts"]) &&
+ aws_cloudwatch_metric_alarm.host_memory_low[0].alarm_actions == toset(["arn:aws:sns:eu-west-1:123456789012:permanent-ha-alerts"]) &&
+ aws_cloudwatch_metric_alarm.host_auto_recover[0].ok_actions == toset(["arn:aws:sns:eu-west-1:123456789012:dev-ha-alerts"]) &&
+ aws_cloudwatch_metric_alarm.host_instance_check[0].ok_actions == toset(["arn:aws:sns:eu-west-1:123456789012:dev-ha-alerts"]) &&
+ aws_cloudwatch_metric_alarm.host_memory_low[0].ok_actions == toset(["arn:aws:sns:eu-west-1:123456789012:permanent-ha-alerts"])
+ )
+ error_message = "the health topic takes the status alarms; the memory alarm keeps the alerts topic"
+ }
+}
+
run "auto_recovery_off_arms_neither_status_alarm" {
command = plan
variables {