Skip to content

Commit

Permalink
Fix-up error message a bit (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
holtwilkins authored Dec 11, 2019
1 parent 608be37 commit 0d0b5e3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
17 changes: 14 additions & 3 deletions bouncer/asgset.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"time"

log "github.com/Sirupsen/logrus"
"github.com/aws/aws-sdk-go/service/autoscaling"
"github.com/pkg/errors"

"github.com/palantir/bouncer/aws"
Expand Down Expand Up @@ -54,7 +55,7 @@ func (a *ASGSet) GetImmutableInstances() []*Instance {
var instances []*Instance
for _, asg := range a.ASGs {
for _, inst := range asg.Instances {
if *inst.ASGInstance.LifecycleState == "Terminating" || *inst.ASGInstance.LifecycleState == "Pending" || *inst.ASGInstance.LifecycleState == "Terminating:Proceed" {
if *inst.ASGInstance.LifecycleState == autoscaling.LifecycleStateTerminating || *inst.ASGInstance.LifecycleState == autoscaling.LifecycleStatePending || *inst.ASGInstance.LifecycleState == autoscaling.LifecycleStateTerminatingProceed {
instances = append(instances, inst)
}
}
Expand Down Expand Up @@ -243,11 +244,21 @@ func (a *ASGSet) IsNewUnhealthy() bool {

newUnhealthy := a.GetUnhealthyNewInstances()
for _, inst := range newUnhealthy {
state := *inst.ASGInstance.LifecycleState
var msg string

switch state {
case autoscaling.LifecycleStateTerminating, autoscaling.LifecycleStateTerminatingProceed, autoscaling.LifecycleStateTerminatingWait:
msg = "Waiting for unhealthy new instance to get out of the way"
default:
msg = "Waiting for new instance to become healthy"
}

log.WithFields(log.Fields{
"ASG": *inst.AutoscalingGroup.AutoScalingGroupName,
"InstanceID": *inst.ASGInstance.InstanceId,
"State": *inst.ASGInstance.LifecycleState,
}).Info("Waiting for new instance to become healthy")
"State": state,
}).Info(msg)
isNewUnhealthy = true
}

Expand Down
10 changes: 3 additions & 7 deletions bouncer/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"time"

log "github.com/Sirupsen/logrus"
"github.com/aws/aws-sdk-go/service/autoscaling"
"github.com/pkg/errors"

"github.com/palantir/bouncer/aws"
Expand Down Expand Up @@ -56,11 +57,6 @@ const (

asgSeparator = ","
desiredCapSeparator = ":"

// The state instance is in while waiting for autoscaling:EC2_INSTANCE_LAUNCHING transition hook
pendingHookState = "Pending:Wait"
// The state instance is in while waiting for autoscaling:EC2_INSTANCE_TERMINATING transition hook
terminateHookState = "Terminating:Wait"
)

func retry(attempts int, sleep time.Duration, callback func() error) (err error) {
Expand Down Expand Up @@ -165,11 +161,11 @@ func (r *BaseRunner) KillInstance(inst *Instance) error {
}).Info("Picked instance to die next")
var hook string

if *inst.ASGInstance.LifecycleState == pendingHookState {
if *inst.ASGInstance.LifecycleState == autoscaling.LifecycleStatePendingWait {
hook = r.opts.PendingHook
}

if *inst.ASGInstance.LifecycleState == terminateHookState {
if *inst.ASGInstance.LifecycleState == autoscaling.LifecycleStateTerminatingWait {
hook = r.opts.TerminateHook
}

Expand Down

0 comments on commit 0d0b5e3

Please sign in to comment.