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

Prevent resetting valid agent state db when IMDS fails on startup #3509

Merged
merged 1 commit into from
Dec 8, 2022
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
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() {
Copy link
Contributor

@mythri-garaga mythri-garaga Dec 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this change as part of this PR?(was is it an intended change?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes sorry I meant to comment on this before sending for review.

This test randomly failed on me once and I was trying to debug, but I couldn't figure anything out without knowing what happened to this Serve() function call.

Afterwards I couldnt reproduce. If it's just very slightly flakey, at least in the future we can see if this function failed so I thought we should keep it in, since it's harmless to check this in a unit test anyways.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

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