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

Chunk taskArns into groups of 100 #1209

Merged
merged 1 commit into from Mar 9, 2017
Merged

Conversation

owen
Copy link
Contributor

@owen owen commented Mar 1, 2017

If the ECS cluster has > 100 tasks, passing them to
ecs.DescribeTasksRequest() will result in the AWS API returning
errors.

This patch breaks them into chunks of at most 100, and calls
DescribeTasks for each chunk.

provider/ecs.go Outdated
sliceEnd = len(taskArns)
}
split_taskreq = append(splitTaskReq, taskArns[i:sliceEnd])
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we move the splitting logic into a small function, e.g.,

func chunkedTaskArns(taskArns []*string) [][]*string

?

Copy link
Contributor

Choose a reason for hiding this comment

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

Some tests on the newly created function would also be nice to cover the representative cases (e.g., 0, 1, 99, 100, 101, 200, 400).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good thinking! I'll catch that :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

also, my git-fu is weak and I managed to commit a broken patch :( fixes soon.

@emilevauge
Copy link
Member

emilevauge commented Mar 2, 2017

@owen shouldn't we rebase this against v1.2 branch to include it in the next release?

@timoreimann
Copy link
Contributor

@owen how's your git-fu going today? ;)

also, do you want to rebase against 1.2 as @emilevauge suggested? The bugfix seems fairly important for ECS users.

@owen
Copy link
Contributor Author

owen commented Mar 6, 2017

it's woeful! I'm king of the force push I guess.

I've:

  • rebased against v1.2
  • split to a small helper function
  • added test cases around splittable values

and will be force pushing again as soon as I ensure it passes a make validate

Should I keep a PR against master with this code, or do you all typically pull v1.2 fixes back in? not sure how that typically works for this project.
(and oh look, more git questions, hehe)

@timoreimann
Copy link
Contributor

@owen we typically sync back the v1.2 branch with master regularly (usually on release of a release candidate / final version), so there should be no need to maintain a separate branch against master.

provider/ecs.go Outdated
Tasks: taskArns,
Cluster: &provider.Cluster,
})
var splitTaskReq [][]*string
Copy link

Choose a reason for hiding this comment

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

Simple comment - as an outsider interrested on this fix:

Is adding a comment to explain why we split the content & do multiple calls will add any value for future maintenance ?
Without knowing the API limitation - or not having the PR context in mind - the 100 split value can be interpreted as coming from nowhere / seems a bit magical.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 on that one; plus, moving the logic into a dedicated function with an informative name (as suggested previously :-) )

I think @owen is already working hard on this one. :-)

@owen owen changed the base branch from master to v1.2 March 7, 2017 15:33
@owen
Copy link
Contributor Author

owen commented Mar 7, 2017

A test case failure I observed last night made me realize that pointing Traefik to an empty cluster would result in bad AWS API calls being made. I've gone ahead and picked up that fix by adding an early return after the first call to ListTasks.

This now works for my empty cluster, and my ~hundred instance cluster. Tests pass, make validate looks good, and it only took one more force push to get it to go up 😬

@timoreimann

@owen
Copy link
Contributor Author

owen commented Mar 7, 2017

@timoreimann / @emilevauge - I'm wondering if I broke your CI environment with my, er, aggressive Git usage.

Let me know if I can help :(

@emilevauge
Copy link
Member

@owen yeah, it seems Travis needs a holiday... Could you push force again?

@owen
Copy link
Contributor Author

owen commented Mar 7, 2017

Looks like the CI is building now. I added a few more tests to wake up the CI pipeline.

Apologies... I actually just learned that "rebase master -> v1.2" is as easy as a click at the top of the pull request. That would've skipped at least one force push on my end, heh.
(I have much to learn about GitHub ;-))

Copy link
Contributor

@timoreimann timoreimann left a comment

Choose a reason for hiding this comment

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

A few very small suggestions left; after that, we should be good. :-)

provider/ecs.go Outdated
Tasks: taskArns,
Cluster: &provider.Cluster,
})
if len(taskArns) == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add a short comment here on why we return early?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

}

if !reflect.DeepEqual(outCount, c.expectedLengths) {
t.Fatalf("Chunking %d elements, expected %#v, got %#v (case %d)", c.count, c.expectedLengths, outCount, i)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should do t.Errorf here: If one case fails, we still want to see the result of the other cases.

Copy link
Contributor

Choose a reason for hiding this comment

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

I also think we can drop the index variable i here. c.count already suffices to identify the failing case unambiguously.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure why I Fatalf'ed there rather than Errorf'ed - fixed :)

@timoreimann
Copy link
Contributor

@owen you haven't go fmt'ed your latest commit -- please run make fmt to fix that. Apart from that, LGTM! ❤️

Could you also squash your commits? After that and another successful CI run, I think we are good to go/merge. :-)

If the ECS cluster has > 100 tasks, passing them to
ecs.DescribeTasksRequest() will result in the AWS API returning
errors.

This patch breaks them into chunks of at most 100, and calls
DescribeTasks for each chunk.

We also return early in case ListTasks returns no values; this
prevents DescribeTasks from throwing HTTP errors.
@owen
Copy link
Contributor Author

owen commented Mar 8, 2017

I fear Travis may not be happy with me again:

[ERROR]	Update failed for gopkg.in/fsnotify.v1: Cannot detect VCS
[ERROR]	Failed to install: Cannot detect VCS
The command '/bin/sh -c cd integration && glide install' returned a non-zero code: 1
make: *** [build] Error 1

@timoreimann
Copy link
Contributor

timoreimann commented Mar 8, 2017

gopkg.in is flaking again. Retriggered the build.

@timoreimann
Copy link
Contributor

Grrr, and now the integration tests are flaking. :(

Retrying HARDER...

@emilevauge
Copy link
Member

Copy link
Member

@emilevauge emilevauge left a comment

Choose a reason for hiding this comment

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

LGTM
Thanks @owen 👍

@emilevauge emilevauge added this to the 1.2 milestone Mar 9, 2017
@emilevauge emilevauge merged commit ee9032f into traefik:v1.2 Mar 9, 2017
@emilevauge emilevauge mentioned this pull request Mar 9, 2017
5 tasks
@ldez ldez added the kind/enhancement a new or improved feature. label Apr 29, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement a new or improved feature.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants