func()

in pkg/monitor/sqsevent/asg-lifecycle-event.go [134:167]


func (m SQSMonitor) checkHeartbeatTimeout(heartbeatInterval int, lifecycleDetail *LifecycleDetail) {
	input := &autoscaling.DescribeLifecycleHooksInput{
		AutoScalingGroupName: aws.String(lifecycleDetail.AutoScalingGroupName),
		LifecycleHookNames:   []*string{aws.String(lifecycleDetail.LifecycleHookName)},
	}

	lifecyclehook, err := m.ASG.DescribeLifecycleHooks(input)
	if err != nil {
		log.Err(err).Msg("failed to describe lifecycle hook")
		return
	}

	if len(lifecyclehook.LifecycleHooks) == 0 {
		log.Warn().
			Str("asgName", lifecycleDetail.AutoScalingGroupName).
			Str("lifecycleHookName", lifecycleDetail.LifecycleHookName).
			Msg("Tried to check heartbeat timeout, but no lifecycle hook found from ASG")
		return
	}

	heartbeatTimeout := int(*lifecyclehook.LifecycleHooks[0].HeartbeatTimeout)

	if heartbeatInterval >= heartbeatTimeout {
		log.Warn().Msgf(
			"Heartbeat interval (%d seconds) is equal to or greater than "+
				"the heartbeat timeout (%d seconds) for the lifecycle hook %s attached to ASG %s. "+
				"The node would likely be terminated before the heartbeat is sent",
			heartbeatInterval,
			heartbeatTimeout,
			*lifecyclehook.LifecycleHooks[0].LifecycleHookName,
			*lifecyclehook.LifecycleHooks[0].AutoScalingGroupName,
		)
	}
}