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

Add an ECS provider #1088

Merged
merged 1 commit into from
Feb 5, 2017
Merged

Add an ECS provider #1088

merged 1 commit into from
Feb 5, 2017

Conversation

lpetre
Copy link

@lpetre lpetre commented Jan 31, 2017

I need to do a couple things, but I wanted to open this PR for discussion.

TODO:

  • write tests
  • update documentation
  • update glide.yaml
  • make sure provider.Watch is implemented correctly

@stingerpk
Copy link

+1

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.

Wow @lpetre thanks a lot 😍 !
Few comments here and there. Coud you complete the sample toml file?
My main concern is on goroutines management in provider/ecs.go. Not sure it will behave correctly on the long term (possible memory leak).
Other than that, looks good :)
/cc @containous/traefik

provider/ecs.go Outdated
sess := session.New()
ec2meta := ec2metadata.New(sess)
if provider.Region == "" {
log.Printf("No EC2 region provided, querying instance metadata endpoint...")
Copy link
Member

Choose a reason for hiding this comment

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

Can you use a log level instead ?

provider/ecs.go Outdated
}()

operation := func() error {
select {
Copy link
Member

Choose a reason for hiding this comment

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

Why did you add a select clause here?

Copy link
Author

Choose a reason for hiding this comment

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

In the case where the stop channel has been sent a value, I cancel the context, my operation will return context.Canceled, and backoff.RetryNotify will call my operation again. So I handle that here.

Copy link
Member

Choose a reason for hiding this comment

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

Isn't this use case already handled by https://github.com/containous/traefik/pull/1088/files#diff-20ed89f06f1c428e51205096690cb934R149? Besides, You are not waiting anything here, you will just pass one time.

Copy link
Author

@lpetre lpetre Feb 4, 2017

Choose a reason for hiding this comment

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

I'll push a fix, but without this select in the current form this code would retry forever when the stop channel is sent a value. Because provider.loadECSConfig (called here and here will return an non-nil error, like context.Canceled, and the backoff code will call the operation again, forever.

Copy link
Author

@lpetre lpetre Feb 4, 2017

Choose a reason for hiding this comment

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

I agree with your comment that this https://github.com/containous/traefik/pull/1088/files#diff-20ed89f06f1c428e51205096690cb934R149 also handles the case, but only if we're waiting for the refresh timer. If we had been in the middle of an AWS http request, that is when the select was useful.

provider/ecs.go Outdated
notify := func(err error, time time.Duration) {
log.Errorf("ECS connection error %+v, retrying in %s", err, time)
}
err := backoff.RetryNotify(operation, job.NewBackOff(backoff.NewExponentialBackOff()), notify)
Copy link
Member

Choose a reason for hiding this comment

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

Could you wrap it with safe.OperationWithRecover(operation), in case of a panic in the goroutine?

@lpetre
Copy link
Author

lpetre commented Feb 4, 2017

Thanks for the feedback @emilevauge. Regarding the goroutines in provider/ecs.go, there is one long running goroutine at line 108 that is responsible for watching the stop channel and cancelling the context, which I use to cancel any outstanding AWS API http requests. As far as I can tell this only can leak if stop is never signaled.

Otherwise there is a goroutine owned by the pool that is responsible for calling my operation. This will exit without error if the ctx context is cancelled.

I don't think there is a way for goroutines to leak here.

@SantoDE
Copy link
Collaborator

SantoDE commented Feb 4, 2017

Wow @lpetre. Thanks a lot! Beside the little thing of @emilevauge , I'm good :)

LGTM 👼

@SantoDE
Copy link
Collaborator

SantoDE commented Feb 5, 2017

Hey @lpetre ,

thanks for all your help! I'll review your latest commits soon. One thing upfront: There are conflicts in your glide files. Could you resolve them and rebase your branch to only have 1 commit? :)

@lpetre
Copy link
Author

lpetre commented Feb 5, 2017

@SantoDE no problem, I'll do that as soon as I'm back at my computer.

@lpetre
Copy link
Author

lpetre commented Feb 5, 2017

@SantoDE this is rebased and up to date with latest master

@emilevauge
Copy link
Member

@lpetre thanks a lot for you reactivity 👏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants