Skip to content

Commit 86d33d7

Browse files
committed
[release]Check resolvers
Custom resolvers can be specified through the new environment variable . Per-service resolving can be specified through the parameter . Please consult [Environment Variables](http://proxy.dockerflow.com/config/\#environment-variables) and [General Query Parameters](http://proxy.dockerflow.com/usage/\#general-query-parameters) for more info.
1 parent e5d8e89 commit 86d33d7

File tree

6 files changed

+44
-3
lines changed

6 files changed

+44
-3
lines changed

actions/reconfigure_test.go

+30
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,36 @@ backend %s-be%s_0
719719
s.Equal(expectedData, actualData)
720720
}
721721

722+
func (s ReconfigureTestSuite) Test_Execute_AddsCheckResolvers_WhenSet() {
723+
s.reconfigure.CheckResolvers = true
724+
var actualFilename, actualData string
725+
expectedFilename := fmt.Sprintf("%s/%s-be.cfg", s.TemplatesPath, s.ServiceName)
726+
expectedData := fmt.Sprintf(
727+
`
728+
backend %s-be%s_0
729+
mode http
730+
http-request add-header X-Forwarded-Proto https if { ssl_fc }
731+
server %s %s:%s check resolvers docker`,
732+
s.ServiceName,
733+
s.reconfigure.ServiceDest[0].Port,
734+
s.ServiceName,
735+
s.ServiceName,
736+
s.reconfigure.ServiceDest[0].Port,
737+
)
738+
writeBeTemplateOrig := writeBeTemplate
739+
defer func() { writeBeTemplate = writeBeTemplateOrig }()
740+
writeBeTemplate = func(filename string, data []byte, perm os.FileMode) error {
741+
actualFilename = filename
742+
actualData = string(data)
743+
return nil
744+
}
745+
746+
s.reconfigure.Execute(true)
747+
748+
s.Equal(expectedFilename, actualFilename)
749+
s.Equal(expectedData, actualData)
750+
}
751+
722752
func (s ReconfigureTestSuite) Test_Execute_AddsReqHeader_WhenSetReqHeaderIsSet() {
723753
s.reconfigure.SetReqHeader = []string{"header-1", "Strict-Transport-Security \"max-age=16000000; includeSubDomains; preload;\""}
724754
var actualFilename, actualData string

docs/config.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ The following environment variables can be used to configure the *Docker Flow Pr
1515
|CA_FILE |Path to a PEM file from which to load CA certificates that will be used to verify client's certificate. Preferably, the file should be provided as a Docker secret.<br>**Example:** /run/secrets/ca-file|
1616
|CAPTURE_REQUEST_HEADER|Allows capturing specific request headers. This feature is useful if debugging is enabled (e.g. `DEBUG=true`) and the format is customized with `DEBUG_HTTP_FORMAT` or `DEBUG_TCP_FORMAT` to output headers. Header name and lenght in bytes must be separated with colon (e.g. `Host:15`). Multiple headers should be separated with colon (e.g. `Host:15,X-Forwarded-For:20`).<br>**Example:** `Host:15,X-Forwarded-For:20,Referer:15`|
1717
|CFG_TEMPLATE_PATH |Path to the configuration template. The path can be absolute (starting with `/`) or relative to `/cfg/tmpl`.<br>**Default value:** `/cfg/tmpl/haproxy.tmpl`|
18-
|CHECK_RESOLVERS |Enable resolvers. Provides higher reliability at the cost of backend initialization time. If enabled, it might take a few seconds until a backend is resolved and operational.<br>**Default value:** `false`|
18+
|CHECK_RESOLVERS |Enable resolvers. Provides higher reliability at the cost of backend initialization time. If enabled, it might take a few seconds until a backend is resolved and operational. Resolvers can be customized through the environment variable `RESOLVERS`.<br>**Default value:** `false`|
1919
|CERTS |This parameter is **deprecated** as of February 2017. All the certificates from the `/certs/` directory are now loaded automatically.|
2020
|COMPRESSION_ALGO |Enable HTTP compression. The currently supported algorithms are:<br>**identity**: this is mostly for debugging.<br>**gzip**: applies gzip compression. This setting is only available when support for zlib or libslz was built in.<br>**deflate**: same as *gzip*, but with deflate algorithm and zlib format. Note that this algorithm has ambiguous support on many browsers and no support at all from recent ones. It is strongly recommended not to use it for anything else than experimentation. This setting is only available when support for zlib or libslz was built in.<br>**raw-deflate**: same as *deflate* without the zlib wrapper, and used as an alternative when the browser wants "deflate". All major browsers understand it and despite violating the standards, it is known to work better than *deflate*, at least on MSIE and some versions of Safari. This setting is only available when support for zlib or libslz was built in.<br>Compression will be activated depending on the Accept-Encoding request header. With identity, it does not take care of that header. If backend servers support HTTP compression, these directives will be no-op: haproxy will see the compressed response and will not compress again. If backend servers do not support HTTP compression and there is Accept-Encoding header in request, haproxy will compress the matching response.<br>Compression is disabled when:<br>* the request does not advertise a supported compression algorithm in the "Accept-Encoding" header<br>* the response message is not HTTP/1.1<br>* HTTP status code is not 200<br>* response header "Transfer-Encoding" contains "chunked" (Temporary Workaround)<br>* response contain neither a "Content-Length" header nor a "Transfer-Encoding" whose last value is "chunked"<br>* response contains a "Content-Type" header whose first value starts with "multipart"<br>* the response contains the "no-transform" value in the "Cache-control" header<br>* User-Agent matches "Mozilla/4" unless it is MSIE 6 with XP SP2, or MSIE 7 and later<br>* The response contains a "Content-Encoding" header, indicating that the response is already compressed (see compression offload)<br>**Example:** gzip|
2121
|COMPRESSION_TYPE |The type of files that will be compressed.<br>**Example:** text/css text/html text/javascript application/javascript text/plain text/xml application/json|

docs/usage.md

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ The following query parameters can be used to send a *reconfigure* request to *D
1818
|addReqHeader |Additional headers that will be added to the request before forwarding it to the service. Multiple headers should be separated with comma (`,`). Change the environment variable `SEPARATOR` if comma is to be used for other purposes. Please consult [Add a header to the request](https://www.haproxy.com/doc/aloha/7.0/haproxy/http_rewriting.html#add-a-header-to-the-request) for more info.<br>**Example:** `X-Forwarded-Port %[dst_port],X-Forwarded-Ssl on if { ssl_fc }`|
1919
|addResHeader |Additional headers that will be added to the response before forwarding it to the client. Multiple headers should be separated with comma (`,`). Change the environment variable `SEPARATOR` if comma is to be used for other purposes. Please consult [Add a header to the response](https://www.haproxy.com/doc/aloha/7.0/haproxy/http_rewriting.html#rewriting-http-responses) for more info.<br>**Example:** `X-Via %[env(HOSTNAME)],Server haproxy`|
2020
|backendExtra |Additional configuration that will be added to the bottom of the service backend |
21+
|checkResolvers |Enable resolvers for the specific service. Provides higher reliability at the cost of backend initialization time. If enabled, it might take a few seconds until a backend is resolved and operational. Resolvers can be customized through the environment variable `RESOLVERS`.<br>**Default value:** `false`|
2122
|connectionMode |HAProxy supports 5 connection modes.<br><br>`http-keep-alive`: all requests and responses are processed.<br>`http-tunnel`: only the first request and response are processed, everything else is forwarded with no analysis.<br>`httpclose`: tunnel with "Connection: close" added in both directions.<br>`http-server-close`: the server-facing connection is closed after the response.<br>`forceclose`: the connection is actively closed after end of response.<br><br>In general, it is preferred to use `http-server-close` with application servers, and some static servers might benefit from `http-keep-alive`.<br>Connection mode is restricted to HTTP mode only. If specified, connection mode will be applied to the backend section.<br>**Example:** http-keep-alive|
2223
|delReqHeader |Additional headers that will be deleted in the request before forwarding it to the service. Multiple headers should be separated with comma (`,`). Change the environment variable `SEPARATOR` if comma is to be used for other purposes. 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`|
2324
|delResHeader |Additional headers that will be deleted in the response before forwarding it to the client. Multiple headers should be separated with comma (`,`). Change the environment variable `SEPARATOR` if comma is to be used for other purposes. 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`|

proxy/types.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,10 @@ type Service struct {
9191
AddResHeader []string `split_words:"true"`
9292
// Additional configuration that will be added to the bottom of the service backend
9393
BackendExtra string `split_words:"true"`
94-
// Whether to use `docker` as a check resolver. Set through the environment variable CHECK_RESOLVERS
94+
// Enable resolvers.
95+
// Provides higher reliability at the cost of backend initialization time.
96+
// If enabled, it might take a few seconds until a backend is resolved and operational.
97+
// Resolvers can be customized through the environment variable RESOLVERS.
9598
CheckResolvers bool `split_words:"true"`
9699
// Enable HTTP compression.
97100
// The currently supported algorithms are: identity, gzip, deflate, raw-deflate.

proxy/types_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@ func (s *TypesTestSuite) getServiceMap(expected Service, indexSuffix, separator
368368
"addReqHeader": strings.Join(expected.AddReqHeader, separator),
369369
"addResHeader": strings.Join(expected.AddResHeader, separator),
370370
"backendExtra": expected.BackendExtra,
371+
"checkResolvers": strconv.FormatBool(expected.CheckResolvers),
371372
"delReqHeader": strings.Join(expected.DelReqHeader, separator),
372373
"delResHeader": strings.Join(expected.DelResHeader, separator),
373374
"distribute": strconv.FormatBool(expected.Distribute),
@@ -417,6 +418,7 @@ func (s *TypesTestSuite) getExpectedService() Service {
417418
AddReqHeader: []string{"add-header-1", "add-header-2"},
418419
AddResHeader: []string{"add-header-1", "add-header-2"},
419420
BackendExtra: "additional backend config",
421+
CheckResolvers: true,
420422
DelReqHeader: []string{"del-header-1", "del-header-2"},
421423
DelResHeader: []string{"del-header-1", "del-header-2"},
422424
Distribute: true,

server/server_test.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,7 @@ func (s *ServerTestSuite) Test_GetServiceFromUrl_ReturnsProxyService() {
521521
AclName: "aclName",
522522
AddReqHeader: []string{"add-header-1", "add-header-2"},
523523
AddResHeader: []string{"add-header-1", "add-header-2"},
524+
CheckResolvers: true,
524525
CompressionAlgo: "compressionAlgo",
525526
CompressionType: "compressionType",
526527
ConnectionMode: "my-connection-mode",
@@ -561,7 +562,7 @@ func (s *ServerTestSuite) Test_GetServiceFromUrl_ReturnsProxyService() {
561562
{Username: "user2", Password: "pass2", PassEncrypted: true}},
562563
}
563564
addr := fmt.Sprintf(
564-
"%s?serviceName=%s&users=%s&usersPassEncrypted=%t&aclName=%s&serviceCert=%s&outboundHostname=%s&pathType=%s&reqPathSearch=%s&reqPathReplace=%s&templateFePath=%s&templateBePath=%s&timeoutServer=%s&timeoutTunnel=%s&reqMode=%s&httpsOnly=%t&httpsRedirectCode=%s&isDefaultBackend=%t&redirectWhenHttpProto=%t&httpsPort=%d&serviceDomain=%s&redirectFromDomain=%s&distribute=%t&sslVerifyNone=%t&serviceDomainAlgo=%s&addReqHeader=%s&addResHeader=%s&setReqHeader=%s&setResHeader=%s&delReqHeader=%s&delResHeader=%s&servicePath=/&servicePathExclude=%s&port=1234&connectionMode=%s&serviceHeader=X-Version:3,name:Viktor&allowedMethods=GET,DELETE&deniedMethods=PUT,POST&compressionAlgo=%s&compressionType=%s",
565+
"%s?serviceName=%s&users=%s&usersPassEncrypted=%t&aclName=%s&serviceCert=%s&outboundHostname=%s&pathType=%s&reqPathSearch=%s&reqPathReplace=%s&templateFePath=%s&templateBePath=%s&timeoutServer=%s&timeoutTunnel=%s&reqMode=%s&httpsOnly=%t&httpsRedirectCode=%s&isDefaultBackend=%t&redirectWhenHttpProto=%t&httpsPort=%d&serviceDomain=%s&redirectFromDomain=%s&distribute=%t&sslVerifyNone=%t&serviceDomainAlgo=%s&addReqHeader=%s&addResHeader=%s&setReqHeader=%s&setResHeader=%s&delReqHeader=%s&delResHeader=%s&servicePath=/&servicePathExclude=%s&port=1234&connectionMode=%s&serviceHeader=X-Version:3,name:Viktor&allowedMethods=GET,DELETE&deniedMethods=PUT,POST&compressionAlgo=%s&compressionType=%s&checkResolvers=%t",
565566
s.BaseUrl,
566567
expected.ServiceName,
567568
"user1:pass1,user2:pass2",
@@ -597,6 +598,7 @@ func (s *ServerTestSuite) Test_GetServiceFromUrl_ReturnsProxyService() {
597598
expected.ConnectionMode,
598599
expected.CompressionAlgo,
599600
expected.CompressionType,
601+
expected.CheckResolvers,
600602
)
601603
req, _ := http.NewRequest("GET", addr, nil)
602604
srv := serve{}
@@ -664,6 +666,7 @@ func (s *ServerTestSuite) Test_GetServicesFromEnvVars_ReturnsServices() {
664666
AclName: "my-AclName",
665667
AddReqHeader: []string{"add-header-1", "add-header-2"},
666668
AddResHeader: []string{"add-header-1", "add-header-2"},
669+
CheckResolvers: true,
667670
CompressionAlgo: "compressionAlgo",
668671
ConnectionMode: "my-connection-mode",
669672
DelReqHeader: []string{"del-header-1", "del-header-2"},
@@ -709,6 +712,7 @@ func (s *ServerTestSuite) Test_GetServicesFromEnvVars_ReturnsServices() {
709712
os.Setenv("DFP_SERVICE_ADD_REQ_HEADER", strings.Join(service.AddReqHeader, ","))
710713
os.Setenv("DFP_SERVICE_ADD_RES_HEADER", strings.Join(service.AddResHeader, ","))
711714
os.Setenv("DFP_SERVICE_ALLOWED_METHODS", strings.Join(service.ServiceDest[0].AllowedMethods, ","))
715+
os.Setenv("DFP_SERVICE_CHECK_RESOLVERS", strconv.FormatBool(service.CheckResolvers))
712716
os.Setenv("DFP_SERVICE_COMPRESSION_ALGO", service.CompressionAlgo)
713717
os.Setenv("DFP_SERVICE_COMPRESSION_TYPE", service.CompressionType)
714718
os.Setenv("DFP_SERVICE_CONNECTION_MODE", service.ConnectionMode)
@@ -751,6 +755,7 @@ func (s *ServerTestSuite) Test_GetServicesFromEnvVars_ReturnsServices() {
751755
os.Unsetenv("DFP_SERVICE_ADD_REQ_HEADER")
752756
os.Unsetenv("DFP_SERVICE_ADD_RES_HEADER")
753757
os.Unsetenv("DFP_SERVICE_ALLOWED_METHODS")
758+
os.Unsetenv("DFP_SERVICE_CHECK_RESOLVERS")
754759
os.Unsetenv("DFP_SERVICE_COMPRESSION_ALGO")
755760
os.Unsetenv("DFP_SERVICE_COMPRESSION_TYPE")
756761
os.Unsetenv("DFP_SERVICE_CONNECTION_MODE")

0 commit comments

Comments
 (0)