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

support for default_backend #222

Merged
merged 10 commits into from
Apr 29, 2017
Merged

Conversation

d-h1
Copy link
Contributor

@d-h1 d-h1 commented Apr 26, 2017

docs/usage.md Outdated
@@ -25,6 +25,7 @@ The following query parameters can be used to send a *reconfigure* request to *D
|reqMode |The request mode. The proxy should be able to work with any mode supported by HAProxy. However, actively supported and tested modes are `http`, `tcp`, and `sni`. The `sni` mode implies TCP with an SNI-based routing.<br>Example: `tcp`|No|http|
|reqPathReplace |A regular expression to apply the modification. If specified, `reqPathSearch` needs to be set as well.<br>Example: `/demo/`|No| |
|reqPathSearch |A regular expression to search the content to be replaced. If specified, `reqPathReplace` needs to be set as well.<br>Example: `/something/`|No| |
|ServiceDefaultBackend | If true, the service will be set to the default_backend rule, meaning it will catch all requests not matching any other rules.<br>Example: `true`|No| |
Copy link
Owner

Choose a reason for hiding this comment

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

ServiceDefaultBackend might be confusing. People might expect to put some value other than true. Maybe it would be better to name it isDefaultBackend?

Copy link
Contributor Author

@d-h1 d-h1 Apr 27, 2017

Choose a reason for hiding this comment

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

I agree, isDefaultBackend sounds much better, I'll update my PR

@vfarcic
Copy link
Owner

vfarcic commented Apr 27, 2017

One more thing... Can you add a test to https://github.com/vfarcic/docker-flow-proxy/blob/master/integration_tests/integration_swarm_test.go?

@d-h1
Copy link
Contributor Author

d-h1 commented Apr 27, 2017

The integration test turned out to be more complicated than I thought. My excuse is that I'm a complete newbie in golang...

To test isDefaultBackend properly we'd need to:

  1. Start a service with a serviceDomain
  2. Get the service's ip
  3. Add the serviceDomain and a subdomain pointing to the service's ip in the hosts file
  4. request (GET) the subdomain and receive 503.

I'm not sure how to do step 3..
Some help would be appreciated 😄

Copy link
Owner

@vfarcic vfarcic left a comment

Choose a reason for hiding this comment

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

Apart from the two minor comments, this looks great.

I'll take care of integration tests (hopefully during the weekend).

@@ -759,6 +760,7 @@ func (s *ServerTestSuite) Test_GetServicesFromEnvVars_ReturnsServices() {
os.Setenv("DFP_SERVICE_DISTRIBUTE", strconv.FormatBool(service.Distribute))
os.Setenv("DFP_SERVICE_HTTPS_ONLY", strconv.FormatBool(service.HttpsOnly))
os.Setenv("DFP_SERVICE_HTTPS_PORT", strconv.Itoa(service.HttpsPort))
os.Setenv("DFP_SERVICE_DEFAULT_BACKEND", strconv.FormatBool(service.IsDefaultBackend))
Copy link
Owner

Choose a reason for hiding this comment

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

Why not call it DFP_SERVICE_IS_DEFAULT_BACKEND? That would make it consistent and easy to remember that env. var. names are the same as request params with the DFP_SERVICE_ prefix.

docs/usage.md Outdated
@@ -21,6 +21,7 @@ The following query parameters can be used to send a *reconfigure* request to *D
|delReqHeader |Additional headers that will be deleted in the request before forwarding it to the service. Multiple headers should be separated with comma (`,`). Please consult [Delete a header in the request](https://www.haproxy.com/doc/aloha/7.0/haproxy/http_rewriting.html#delete-a-header-in-the-request) for more info.<br>Example: `X-Forwarded-For,Cookie`|No| |
|delResHeader |Additional headers that will be deleted in the response before forwarding it to the client. Multiple headers should be separated with comma (`,`). Please consult [Delete a header in the response](https://www.haproxy.com/doc/aloha/7.0/haproxy/http_rewriting.html#delete-a-header-in-the-response) for more info.<br>Example: `X-Varnish,X-Cache`|No| |
|httpsPort |The internal HTTPS port of a service that should be reconfigured. The port is used only in the `swarm` mode. If not specified, the `port` parameter will be used instead.<br>Example: `443`|No| |
|isDefaultBackend | If true, the service will be set to the default_backend rule, meaning it will catch all requests not matching any other rules.<br>Example: `true`|No| |
Copy link
Owner

Choose a reason for hiding this comment

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

Can you also add an entry in the Environment Variables section below?

@vfarcic
Copy link
Owner

vfarcic commented Apr 28, 2017

I'd like to run past you a scenario for integration tests.

  1. Configure proxy to serve requests on /xxx (it does not exist) and be the default backend at the same time.
  2. Send a request to /demo/hello.
  3. Receive 200.

If my understanding is correct, default backend should forward a request to an address so the above scenario should work. Am I correct in my assumption. If I am, I'll add the test ASAP.

@vfarcic
Copy link
Owner

vfarcic commented Apr 28, 2017

Take a look at https://gist.github.com/vfarcic/c26a46defba4ff84d1ac7f918fd80c25 and let me know if you think that would be a valid test. If it is, please add it to the PR.

@d-h1
Copy link
Contributor Author

d-h1 commented Apr 28, 2017

You are right! That integration test should be good enough to try isDefaultBackend, thanks for the help..

I have a new issue now, when I change "DFP_SERVICE_DEFAULT_BACKEND" to "DFP_SERVICE_IS_DEFAULT_BACKEND" the test "Test_GetServicesFromEnvVars_ReturnsServices" seems to fail and I'm not sure why?

@vfarcic
Copy link
Owner

vfarcic commented Apr 29, 2017

I have a new issue now, when I change "DFP_SERVICE_DEFAULT_BACKEND" to "DFP_SERVICE_IS_DEFAULT_BACKEND" the test "Test_GetServicesFromEnvVars_ReturnsServices" seems to fail and I'm not sure why?

The problem is in envconfig:"default_backend" . By specifying it, you told the code to use DEFAULT_BACKEND as env. var. name. That worked before but when you renamed it to IS_DEFAULT_BACKEND, the envconfig still continued looking for DEFAULT_BACKEND.

I fixed it and merged the PR. If all the tests pass, it'll be ready for a release.

@vfarcic vfarcic merged commit cece848 into vfarcic:master Apr 29, 2017
@d-h1 d-h1 deleted the feature/default_backend branch April 29, 2017 12:31
@vfarcic
Copy link
Owner

vfarcic commented Apr 29, 2017

Integration tests were missing isDefaultBackend=true. Now everything works and is merged to master. Release 1.336 was created. Thanks @leostarcevic.

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

Successfully merging this pull request may close these issues.

2 participants