Skip to content

Commit

Permalink
Merge pull request #781 from remind101/dedupe-describes
Browse files Browse the repository at this point in the history
Reduce number of DescribeTaskDefinition calls.
  • Loading branch information
ejholmes committed Apr 12, 2016
2 parents 549c08e + a19d44e commit 37b71e9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
* `emp scale -l` now lists configured scale, not the running processes [#769](https://github.com/remind101/empire/pull/769)
* Fixed a bug where it was previously possible to create a signed access token with an empty username [#780](https://github.com/remind101/empire/pull/780)

**Performance**

* `emp ps` should be significantly faster for services running a lot of processes [#781](https://github.com/remind101/empire/pull/781)

**Security**

* Empire is now built with Go 1.5.3 to address [CVE-2015-8618](https://groups.google.com/forum/#!topic/golang-announce/MEATuOi_ei4) [#737](https://github.com/remind101/empire/pull/737).
Expand Down
22 changes: 16 additions & 6 deletions scheduler/ecs/ecs.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,20 +238,30 @@ func (m *Scheduler) Instances(ctx context.Context, appID string) ([]*scheduler.I
return instances, err
}

taskDefinitions := make(map[string]*ecs.TaskDefinition)
for _, t := range tasks {
resp, err := m.ecs.DescribeTaskDefinition(ctx, &ecs.DescribeTaskDefinitionInput{
TaskDefinition: t.TaskDefinitionArn,
})
if err != nil {
return instances, err
k := *t.TaskDefinitionArn

if _, ok := taskDefinitions[k]; !ok {
resp, err := m.ecs.DescribeTaskDefinition(ctx, &ecs.DescribeTaskDefinitionInput{
TaskDefinition: t.TaskDefinitionArn,
})
if err != nil {
return instances, err
}
taskDefinitions[k] = resp.TaskDefinition
}
}

for _, t := range tasks {
taskDefinition := taskDefinitions[*t.TaskDefinitionArn]

id, err := arn.ResourceID(*t.TaskArn)
if err != nil {
return instances, err
}

p, err := taskDefinitionToProcess(resp.TaskDefinition)
p, err := taskDefinitionToProcess(taskDefinition)
if err != nil {
return instances, err
}
Expand Down
10 changes: 5 additions & 5 deletions scheduler/ecs/ecs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func TestScheduler_Instances(t *testing.T) {
},
Response: awsutil.Response{
StatusCode: 200,
Body: `{"taskArns":["arn:aws:ecs:us-east-1:249285743859:task/ae69bb4c-3903-4844-82fe-548ac5b74570"]}`,
Body: `{"taskArns":["arn:aws:ecs:us-east-1:249285743859:task/ae69bb4c-3903-4844-82fe-548ac5b74570","arn:aws:ecs:us-east-1:249285743859:task/ae69bb4c-3903-4844-82fe-548ac5b74571"]}`,
},
},

Expand All @@ -150,11 +150,11 @@ func TestScheduler_Instances(t *testing.T) {
Request: awsutil.Request{
RequestURI: "/",
Operation: "AmazonEC2ContainerServiceV20141113.DescribeTasks",
Body: `{"cluster":"empire","tasks":["arn:aws:ecs:us-east-1:249285743859:task/ae69bb4c-3903-4844-82fe-548ac5b74570"]}`,
Body: `{"cluster":"empire","tasks":["arn:aws:ecs:us-east-1:249285743859:task/ae69bb4c-3903-4844-82fe-548ac5b74570","arn:aws:ecs:us-east-1:249285743859:task/ae69bb4c-3903-4844-82fe-548ac5b74571"]}`,
},
Response: awsutil.Response{
StatusCode: 200,
Body: `{"tasks":[{"taskArn":"arn:aws:ecs:us-east-1:249285743859:task/ae69bb4c-3903-4844-82fe-548ac5b74570","taskDefinitionArn":"arn:aws:ecs:us-east-1:249285743859:task-definition/1234--web","lastStatus":"RUNNING","startedAt": 1448419193}]}`,
Body: `{"tasks":[{"taskArn":"arn:aws:ecs:us-east-1:249285743859:task/ae69bb4c-3903-4844-82fe-548ac5b74570","taskDefinitionArn":"arn:aws:ecs:us-east-1:249285743859:task-definition/1234--web","lastStatus":"RUNNING","startedAt": 1448419193},{"taskArn":"arn:aws:ecs:us-east-1:249285743859:task/ae69bb4c-3903-4844-82fe-548ac5b74571","taskDefinitionArn":"arn:aws:ecs:us-east-1:249285743859:task-definition/1234--web","lastStatus":"RUNNING","startedAt": 1448419193}]}`,
},
},

Expand All @@ -178,8 +178,8 @@ func TestScheduler_Instances(t *testing.T) {
t.Fatal(err)
}

if len(instances) != 1 {
t.Fatal("expected 1 instance")
if len(instances) != 2 {
t.Fatal("expected 2 instances")
}

i := instances[0]
Expand Down

0 comments on commit 37b71e9

Please sign in to comment.