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

Agent version 1.15.2 #1078

Merged
merged 3 commits into from
Nov 17, 2017
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#Changelog

## 1.15.2
* Bug - Fixed a bug where container state information wasn't reported. [#1076](https://github.com/aws/amazon-ecs-agent/pull/1076)

## 1.15.1
* Bug - Fixed a bug where container state information wasn't reported. [#1067](https://github.com/aws/amazon-ecs-agent/pull/1067)
* Bug - Fixed a bug where a task can be blocked in creating state. [#1048](https://github.com/aws/amazon-ecs-agent/pull/1048)
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.15.1
1.15.2
12 changes: 0 additions & 12 deletions agent/api/ecsclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,18 +312,6 @@ func (client *APIECSClient) SubmitTaskStateChange(change api.TaskStateChange) er
return nil
}

// Submit task state change
if change.Status == api.TaskStatusNone {
seelog.Warnf("SubmitTaskStateChange called with an invalid change: %s", change.String())
return errors.New("ecs api client: SubmitTaskStateChange called with an invalid change")
}

if change.Status != api.TaskRunning && change.Status != api.TaskStopped && len(change.Containers) == 0 {
seelog.Debugf("Not submitting unsupported upstream task state: %s", change.Status.String())
// Not really an error
return nil
}

status := change.Status.BackendStatus()

req := ecs.SubmitTaskStateChangeInput{
Expand Down
52 changes: 35 additions & 17 deletions agent/api/ecsclient/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -702,22 +702,19 @@ func TestSubmitContainerStateChangeWhileTaskInPending(t *testing.T) {
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()

client, _, mockSubmitStateClient := NewMockClient(mockCtrl, ec2.NewBlackholeEC2MetadataClient(), nil)
mockSubmitStateClient.EXPECT().SubmitTaskStateChange(&taskSubmitInputMatcher{
ecs.SubmitTaskStateChangeInput{
Cluster: strptr(configuredCluster),
Task: strptr("arn"),
Status: strptr("PENDING"),
Reason: strptr(""),
Containers: []*ecs.ContainerStateChange{
{
ContainerName: strptr("container"),
Status: strptr("RUNNING"),
NetworkBindings: []*ecs.NetworkBinding{},
},
},
testCases := []struct {
taskStatus api.TaskStatus
}{
{
api.TaskStatusNone,
},
})
{
api.TaskPulled,
},
{
api.TaskCreated,
},
}

taskStateChangePending := api.TaskStateChange{
Status: api.TaskCreated,
Expand All @@ -731,6 +728,27 @@ func TestSubmitContainerStateChangeWhileTaskInPending(t *testing.T) {
},
}

err := client.SubmitTaskStateChange(taskStateChangePending)
assert.NoError(t, err)
for _, tc := range testCases {
t.Run(fmt.Sprintf("TaskStatus: %s", tc.taskStatus.String()), func(t *testing.T) {
taskStateChangePending.Status = tc.taskStatus
client, _, mockSubmitStateClient := NewMockClient(mockCtrl, ec2.NewBlackholeEC2MetadataClient(), nil)
mockSubmitStateClient.EXPECT().SubmitTaskStateChange(&taskSubmitInputMatcher{
ecs.SubmitTaskStateChangeInput{
Cluster: strptr(configuredCluster),
Task: strptr("arn"),
Status: strptr("PENDING"),
Reason: strptr(""),
Containers: []*ecs.ContainerStateChange{
{
ContainerName: strptr("container"),
Status: strptr("RUNNING"),
NetworkBindings: []*ecs.NetworkBinding{},
},
},
},
})
err := client.SubmitTaskStateChange(taskStateChangePending)
assert.NoError(t, err)
})
}
}
36 changes: 21 additions & 15 deletions agent/eventhandler/task_handler_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ func (event *sendableEvent) taskArn() string {
return event.taskChange.TaskARN
}

// taskShouldBeSent checks whether the event should be sent, this includes
// both task state change and container state change events
func (event *sendableEvent) taskShouldBeSent() bool {
event.lock.RLock()
defer event.lock.RUnlock()
Expand All @@ -70,27 +72,31 @@ func (event *sendableEvent) taskShouldBeSent() bool {
return false
}
tevent := event.taskChange
if tevent.Status == api.TaskStatusNone {
return false // defensive programming :)
}
if event.taskSent {
return false // redundant event
}
if tevent.Task != nil && tevent.Task.GetSentStatus() >= tevent.Status {
// If the task status has already been sent, check if there are
// any container states that need to be sent
for _, containerStateChange := range tevent.Containers {
container := containerStateChange.Container
if container.GetSentStatus() < container.GetKnownStatus() {
// We found a container that needs its state
// change to be sent to ECS.
return true
}
}

// task and container change event should have task != nil
if tevent.Task == nil {
return false
}
return true

// Task event should be sent
if tevent.Task.GetSentStatus() < tevent.Status {
return true
}

// Container event should be sent
for _, containerStateChange := range tevent.Containers {
container := containerStateChange.Container
if container.GetSentStatus() < container.GetKnownStatus() {
// We found a container that needs its state
// change to be sent to ECS.
return true
}
}

return false
}

func (event *sendableEvent) taskAttachmentShouldBeSent() bool {
Expand Down
24 changes: 24 additions & 0 deletions agent/eventhandler/task_handler_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,17 @@ func TestShouldTaskEventBeSent(t *testing.T) {
// We don't send a task event to backend if task status == NONE
event: newSendableTaskEvent(api.TaskStateChange{
Status: api.TaskStatusNone,
Task: &api.Task{
SentStatusUnsafe: api.TaskStatusNone,
},
}),
shouldBeSent: false,
},
{
// task status == RUNNING should be sent to backend
event: newSendableTaskEvent(api.TaskStateChange{
Status: api.TaskRunning,
Task: &api.Task{},
}),
shouldBeSent: true,
},
Expand Down Expand Up @@ -94,6 +98,25 @@ func TestShouldTaskEventBeSent(t *testing.T) {
}),
shouldBeSent: true,
},
{
// Container state change should be sent regardless of task
// status.
event: newSendableTaskEvent(api.TaskStateChange{
Status: api.TaskStatusNone,
Task: &api.Task{
SentStatusUnsafe: api.TaskStatusNone,
},
Containers: []api.ContainerStateChange{
{
Container: &api.Container{
SentStatusUnsafe: api.ContainerStatusNone,
KnownStatusUnsafe: api.ContainerRunning,
},
},
},
}),
shouldBeSent: true,
},
{
// All states sent, nothing to send
event: newSendableTaskEvent(api.TaskStateChange{
Expand Down Expand Up @@ -137,6 +160,7 @@ func TestShouldTaskAttachmentEventBeSent(t *testing.T) {
// ENI Attachment is only sent if task status == NONE
event: newSendableTaskEvent(api.TaskStateChange{
Status: api.TaskStopped,
Task: &api.Task{},
}),
attachmentShouldBeSent: false,
taskShouldBeSent: true,
Expand Down
2 changes: 1 addition & 1 deletion agent/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ package version
// repository. Only the 'Version' const should change in checked-in source code

// Version is the version of the Agent
const Version = "1.15.1"
const Version = "1.15.2"

// GitDirty indicates the cleanliness of the git repo when this agent was built
const GitDirty = true
Expand Down
2 changes: 1 addition & 1 deletion misc/windows-deploy/user-data.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Set agent env variables for the Machine context (durable)
[Environment]::SetEnvironmentVariable("ECS_CLUSTER", "windows", "Machine")
[Environment]::SetEnvironmentVariable("ECS_ENABLE_TASK_IAM_ROLE", "false", "Machine")
$agentVersion = 'v1.15.1'
$agentVersion = 'v1.15.2'
$agentZipUri = "https://s3.amazonaws.com/amazon-ecs-agent/ecs-agent-windows-$agentVersion.zip"
$agentZipMD5Uri = "$agentZipUri.md5"

Expand Down