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

Bind healthcheck to backend by entryPointName #1868

Merged
merged 5 commits into from
Aug 10, 2017
Merged

Bind healthcheck to backend by entryPointName #1868

merged 5 commits into from
Aug 10, 2017

Conversation

chrigl
Copy link
Contributor

@chrigl chrigl commented Jul 17, 2017

Description

Fixes: #1866
Conflicts: #1867

If we need to have one lb instance per entrypoint for some reasons, I
don't see, this commit registers healtchcheck with
entryPointName+frontend.Backend as a key. So the healthcheck will be
registered as often as there are entrypoints. Because of this, I would
prefer #1867.

Fixes: #1866
Conflicts: #1867

If we need to have one lb instance per entrypoint for some reasons, I
don't see, this commit registers healtchcheck with
`entryPointName+frontend.Backend` as a key. So the healthcheck will be
registered as often as there are entrypoints. Because of this, I would
prefer #1867.
@ldez ldez added kind/enhancement a new or improved feature. status/1-needs-design-review kind/bug/fix a bug fix and removed kind/enhancement a new or improved feature. labels Jul 17, 2017
@emilevauge
Copy link
Member

Thanks for your contribution, design LGTM

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.

Hey @chrigl, great fix! We would love to see an integration test on this use case. Do you think you could do this ?

@ldez ldez added this to the 1.4 milestone Jul 20, 2017
@chrigl
Copy link
Contributor Author

chrigl commented Jul 22, 2017

@emilevauge added an integration test.

c.Assert(err, checker.IsNil)
}
// Test http1 is healthy and only whoami2 responds
for i := 0; i < 4; i++ {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you replace this loop by a try:

// Check if whoami1 never respond
err = try.Request(frontend1Req, 2*time.Second, try.BodyContains(whoami1Host))
c.Assert(err, checker.Not(checker.IsNil))

Instead of testing the presence of whoami2 you can test the absence of whoami1.

}
// Test http1 is healthy and only whoami2 responds
for i := 0; i < 4; i++ {
frontendReq, err := http.NewRequest(http.MethodGet, "http://127.0.0.1:8000/", nil)
Copy link
Contributor

Choose a reason for hiding this comment

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

You can extract the request from the loop and rename like that frontend2Req

// Test http2 is healthy and only whoami2 responds
// Looping to give traefik the chance to forward to a broken server
for i := 0; i < 4; i++ {
frontendReq, err := http.NewRequest(http.MethodGet, "http://127.0.0.1:9000/", nil)
Copy link
Contributor

Choose a reason for hiding this comment

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

You can extract the request from the loop and rename like that frontend1Req


// Test http2 is healthy and only whoami2 responds
// Looping to give traefik the chance to forward to a broken server
for i := 0; i < 4; i++ {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you replace this loop by a try:

// Check if whoami1 never respond
err = try.Request(frontend2Req, 2*time.Second, try.BodyContains(whoami1Host))
c.Assert(err, checker.Not(checker.IsNil))

Instead of testing the presence of whoami2 you can test the absence of whoami1.

@@ -92,3 +92,89 @@ func (s *HealthCheckSuite) TestSimpleConfiguration(c *check.C) {
c.Assert(err, checker.IsNil)
c.Assert(resp.StatusCode, checker.Equals, http.StatusNotFound)
}

func (s *HealthCheckSuite) TestMultipleEntrypoints(c *check.C) {
whoami1Host := s.composeProject.Container(c, "whoami1").NetworkSettings.IPAddress
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you refactor tests like that:

type HealthCheckSuite struct{
	BaseSuite
	whoami1IP string
	whoami2IP string
}

func (s *HealthCheckSuite) SetUpSuite(c *check.C) {
	s.createComposeProject(c, "healthcheck")
	s.composeProject.Start(c)

	s.whoami1IP = s.composeProject.Container(c, "whoami1").NetworkSettings.IPAddress
	s.whoami2IP = s.composeProject.Container(c, "whoami2").NetworkSettings.IPAddress
}

and replace all occurrence of whoami1Host and whoami2Host by s.whoami1IP and s.whoami2IP

* replaced unnecessary for loops by Try
* replaced whoamiHosts by s.whoamiIPs
* added additional test case to also cover drr backends
@chrigl
Copy link
Contributor Author

chrigl commented Jul 31, 2017

@ldez Thanks for your feedback. Changed code to your recommendations, and added a new test case to also cover healthchecks on drr backends.

Copy link
Contributor

@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

Copy link
Member

@juliens juliens left a comment

Choose a reason for hiding this comment

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

LGTM
Great job

@ldez ldez merged commit ff11467 into traefik:master Aug 10, 2017
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.

4 participants