Skip to content

Commit

Permalink
Fall back to saved state when checking state db
Browse files Browse the repository at this point in the history
  • Loading branch information
sparrc committed Dec 7, 2022
1 parent 618408a commit 99ed01b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
6 changes: 5 additions & 1 deletion agent/app/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ const (
instanceIdBackoffMax = time.Second * 5
instanceIdBackoffJitter = 0.2
instanceIdBackoffMultiple = 1.3
instanceIdMaxRetryCount = 3
instanceIdMaxRetryCount = 5

targetLifecycleBackoffMin = time.Second
targetLifecycleBackoffMax = time.Second * 5
Expand Down Expand Up @@ -536,6 +536,10 @@ func (agent *ecsAgent) newTaskEngine(containerChangeEventStream *eventstream.Eve
}

currentEC2InstanceID := agent.getEC2InstanceID()
if currentEC2InstanceID == "" {
currentEC2InstanceID = savedData.ec2InstanceID
seelog.Warnf("Not able to get EC2 Instance ID from IMDS, using EC2 Instance ID from saved state: '%s'", currentEC2InstanceID)
}
if savedData.ec2InstanceID != "" && savedData.ec2InstanceID != currentEC2InstanceID {
seelog.Warnf(instanceIDMismatchErrorFormat,
savedData.ec2InstanceID, currentEC2InstanceID)
Expand Down
1 change: 1 addition & 0 deletions agent/app/agent_compatibility_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ func TestCompatibilityNotSetFail(t *testing.T) {
require.NoError(t, dataClient.SaveTask(task))
}

cfg.Cluster = "test-cluster"
agent := &ecsAgent{
cfg: &cfg,
dataClient: dataClient,
Expand Down
2 changes: 2 additions & 0 deletions agent/app/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -889,6 +889,8 @@ func TestGetEC2InstanceIDIIDError(t *testing.T) {
ec2MetadataClient := mock_ec2.NewMockEC2MetadataClient(ctrl)
agent := &ecsAgent{ec2MetadataClient: ec2MetadataClient}

ec2MetadataClient.EXPECT().InstanceID().Return("", errors.New("error"))
ec2MetadataClient.EXPECT().InstanceID().Return("", errors.New("error"))
ec2MetadataClient.EXPECT().InstanceID().Return("", errors.New("error"))
ec2MetadataClient.EXPECT().InstanceID().Return("", errors.New("error"))
ec2MetadataClient.EXPECT().InstanceID().Return("", errors.New("error"))
Expand Down
5 changes: 4 additions & 1 deletion agent/tcs/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,10 @@ func TestMetricsDisabled(t *testing.T) {
published <- struct{}{}
}).Return(nil).MinTimes(1)

go cs.Serve()
go func() {
err := cs.Serve()
assert.NoError(t, err)
}()
<-published
<-readed
}
Expand Down

0 comments on commit 99ed01b

Please sign in to comment.