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

Detect proper hostname automatically. #1345

Merged
merged 5 commits into from Apr 26, 2017

Conversation

diegooliveira
Copy link
Contributor

@diegooliveira diegooliveira commented Mar 26, 2017

The IP-Per-Task feature changed the behavior for clients without this configuration (using the task IP instead of task hostname).
This patch make the new behavior available just for Mesos installation with IP-Per-Task enabled.
It also make it possible to force the use of task's hostname.

@errm
Copy link
Contributor

errm commented Mar 28, 2017

Looks like the unit tests are failing on this change...

@@ -526,21 +527,22 @@ func (provider *Marathon) getBackendServer(task marathon.Task, applications []ma
log.Errorf("Unable to get marathon application from task %s", task.AppID)
return ""
}
if len(task.IPAddresses) == 0 {
if application.IPAddressPerTask == nil || provider.ForceTaskHostname {
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 turn the block into a switch-case statement? Would make things more readable IMHO.

applications := []struct {
forceTaskHostname bool
applications []marathon.Application
task marathon.Task
Copy link
Contributor

Choose a reason for hiding this comment

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

The task seems to be the same for all tests. Please define it in the loop body.

forceTaskHostname: true,
applications: []marathon.Application{
{
ID: "app-with-IP-per-task-config",
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 call this something like app-with-hostname-enforced?

}

for _, app := range applications {
provider := &Marathon{}
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use sub-tests here. You can use the app IDs as descriptions (first parameter to the t.Run() method).

@@ -586,6 +586,14 @@
#
# keepAlive = 10

# Force the use of the task's hostname in the backend server address even in a
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 be a bit more elaborative here and describe the default behavior. I'm thinking of something like the following:

By default, a task's IP address (as returned by the Marathon API) is used as backend server if an IP-per-task configuration can be found; otherwise, the name of the host running the task is used.
The latter behavior can be enforced by enabling this switch.

Please also copy the description into the docs/toml.md file.

@timoreimann
Copy link
Contributor

hey @diegooliveira, any chance to get an update on the PR? Thanks.

@emilevauge
Copy link
Member

@diegooliveira tests are still failing.

@jensendw
Copy link

@emilevauge it looks like the tests are passing again. Do you think this will be merged in before the next release?

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 minor-ish details we need to address.

} else {
// Compare backends
if !reflect.DeepEqual(actualConfig.Backends, c.expectedBackends) {
expected, _ := json.Marshal(c.expectedBackends)
Copy link
Contributor

Choose a reason for hiding this comment

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

Using JSON to display differences can be highly misleading: For instance, the serialization sometimes does not distinguish between a nil and an empty slice.

If pointers are involved, please use go-spew.Sdump.

@@ -107,7 +110,7 @@ func TestMarathonLoadConfig(t *testing.T) {
"backend-test": {
Servers: map[string]types.Server{
"server-test": {
URL: "http://127.0.0.1:80",
URL: "http://localhost:80",
Copy link
Contributor

Choose a reason for hiding this comment

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

Was there a need to change this?

"errors"
"reflect"
"testing"

"fmt"
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you sort the imports alphabetically?

// Compare backends
if !reflect.DeepEqual(actualConfig.Backends, c.expectedBackends) {
t.Fatalf("expected %#v, got %#v", c.expectedBackends, actualConfig.Backends)
t.Run(fmt.Sprintf("Running case: %s", appID), func(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think you need the "Running case" prefix: it's clear we run a case when being logged.

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 parallelize the tests? If so, please call t.Parallel() here.

fakeClient.AssertExpectations(t)
if c.expectedNil {
if actualConfig != nil {
t.Fatalf("Should have been nil, got %v", actualConfig)
Copy link
Contributor

Choose a reason for hiding this comment

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

Please say "config should have been nil, got [...]".

if !reflect.DeepEqual(actualConfig.Backends, c.expectedBackends) {
expected, _ := json.Marshal(c.expectedBackends)
actual, _ := json.Marshal(actualConfig.Backends)
t.Fatalf("expected\t %s\n, \tgot %s\n", expected, actual)
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be an t.Errorf IMHO so that we can still see the frontend assertion even if the backend one fails.

}

for _, app := range applications {
t.Run(fmt.Sprintf("running %s", app.application.ID), func(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

No "running" here too.

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 parallelize the tests? If so, please call t.Parallel() here and do app := app before the call to t.Run to capture the loop variable.


actual := provider.getBackendServer(task, applications)
if actual != app.expected {
t.Errorf("App %s, expected %q, got %q", task.AppID, app.expected, actual)
Copy link
Contributor

Choose a reason for hiding this comment

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

No need to include the app ID in the message: we already get that context by the first parameter to t.Run.

Copy link
Contributor

Choose a reason for hiding this comment

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

Please swap the expected / got order: the actual value should go first (for consistency reasons and because that's Go-typical).

@timoreimann
Copy link
Contributor

Hey @diegooliveira, do you have time for a final update? Would be great to get this feature merged before the code freeze.

@timoreimann timoreimann force-pushed the IP-Per-Task-Fix-Hostname branch 2 times, most recently from bc4173b to a8be80b Compare April 22, 2017 21:03
@timoreimann timoreimann changed the base branch from master to marathon-check-port-label-overwrite-earlier April 22, 2017 21:03
@timoreimann
Copy link
Contributor

timoreimann commented Apr 22, 2017

Wanted to make sure this important PR makes it into the upcoming version 1.3 release, so I carried the PR "in-place". Here's what I did:

@diegooliveira I hope all of this is okay with you.

@timoreimann
Copy link
Contributor

Fixes #1243.

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.

Unsurprisingly, I approve my own changes. :-)

@timoreimann
Copy link
Contributor

@containous/traefik please review.

@timoreimann timoreimann added this to the 1.3 milestone Apr 22, 2017
@timoreimann timoreimann changed the title Fix unsound behavior [Marathon] Detect proper hostname automatically. Apr 22, 2017
@diegooliveira
Copy link
Contributor Author

@timoreimann nice work, sorry for the delay, busy month. The addition of spew was a nice touch.

@ldez ldez added kind/bug/fix a bug fix and removed bug labels Apr 25, 2017
@timoreimann timoreimann force-pushed the marathon-check-port-label-overwrite-earlier branch from cb7f4bd to 099d605 Compare April 25, 2017 21:18
Copy link
Member

@ldez ldez left a comment

Choose a reason for hiding this comment

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

LGTM.
You must solve conflicts before 😉

Diego de Oliveira and others added 5 commits April 26, 2017 11:35
  The IP-Per-Task feature changed the behavior for
clients without this configuration (using the task IP instead
of task hostname). This patch make the new behavior available
just for Mesos installation with IP-Per-Task enabled. It also
make it possible to force the use of task's hostname.
Allows to move specific test cases to dedicated tests for new function.
- Cover error cases.
- Use sub-tests.
@timoreimann timoreimann changed the base branch from marathon-check-port-label-overwrite-earlier to master April 26, 2017 09:36
@timoreimann timoreimann merged commit 5a8215a into traefik:master Apr 26, 2017
@ldez ldez changed the title [Marathon] Detect proper hostname automatically. Detect proper hostname automatically. May 25, 2017
@kopax

This comment has been minimized.

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

Successfully merging this pull request may close these issues.

None yet

7 participants