Skip to content

Commit d241b74

Browse files
committed
feat(proxyBuffers): Add app-level proxy buffer config options
1 parent f81d872 commit d241b74

File tree

4 files changed

+79
-3
lines changed

4 files changed

+79
-3
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,10 @@ _Note that Kubernetes annotation maps are all of Go type `map[string]string`. A
271271
| <a name="app-tcp-timeout"></a>routable application | service | [router.deis.io/tcpTimeout](#app-tcp-timeout) | router's `defaultTimeout` | nginx `proxy_send_timeout` and `proxy_read_timeout` settings expressed in units `ms`, `s`, `m`, `h`, `d`, `w`, `M`, or `y`. |
272272
| <a name="app-maintenance"></a>routable application | service | [router.deis.io/maintenance](#app-maintenance) | `"false"` | Whether the app is under maintenance so that all traffic for this app is redirected to a static maintenance page with an error code of `503`. |
273273
| <a name="ssl-enforce"></a>routable application | service | [router.deis.io/ssl.enforce](#ssl-enforce) | `"false"` | Whether to respond with a 301 for all HTTP requests with a permanent redirect to the HTTPS equivalent address. |
274+
| <a name="app-nginx-proxy-buffers-enabled"></a>routable application | service | [router.deis.io/nginx.proxyBuffers.enabled](#app-nginx-proxy-buffers-enabled) | `"false"` | Whether to enabled proxy buffering. |
275+
| <a name="app-nginx-proxy-buffers-number"></a>routable application | service | [router.deis.io/nginx.proxyBuffers.number](#app-nginx-proxy-buffers-number) | `"8"` | `number` argument to the nginx `proxy_buffers` directive. |
276+
| <a name="app-nginx-proxy-buffers-size"></a>routable application | service | [router.deis.io/nginx.proxyBuffers.size](#app-nginx-proxy-buffers-size) | `"4k"` | `size` argument to the nginx `proxy_buffers` directive expressed in bytes (no suffix), kilobytes (suffixes `k` and `K`), or megabytes (suffixes `m` and `M`). |
277+
| <a name="app-nginx-proxy-buffers-busy-size"></a>routable application | service | [router.deis.io/nginx.proxyBuffers.busySize](#app-nginx-proxy-buffers-busy-size) | `"8k"` | nginx `proxy_busy_buffers_size` expressed in bytes (no suffix), kilobytes (suffixes `k` and `K`), or megabytes (suffixes `m` and `M`). |
274278

275279
#### Annotations by example
276280

model/model.go

+34-2
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,9 @@ type AppConfig struct {
126126
CertMappings map[string]string `key:"certificates" constraint:"(?i)^((([a-z0-9]+(-*[a-z0-9]+)*)|((\\*\\.)?[a-z0-9]+(-*[a-z0-9]+)*\\.)+[a-z0-9]+(-*[a-z0-9]+)+):([a-z0-9]+(-*[a-z0-9]+)*)(\\s*,\\s*)?)+$"`
127127
Certificates map[string]*Certificate
128128
Available bool
129-
Maintenance bool `key:"maintenance" constraint:"(?i)^(true|false)$"`
130-
SSLConfig *SSLConfig `key:"ssl"`
129+
Maintenance bool `key:"maintenance" constraint:"(?i)^(true|false)$"`
130+
SSLConfig *SSLConfig `key:"ssl"`
131+
Nginx *NginxAppConfig `key:"nginx"`
131132
}
132133

133134
func newAppConfig(routerConfig *RouterConfig) *AppConfig {
@@ -136,6 +137,7 @@ func newAppConfig(routerConfig *RouterConfig) *AppConfig {
136137
TCPTimeout: routerConfig.DefaultTimeout,
137138
Certificates: make(map[string]*Certificate, 0),
138139
SSLConfig: newSSLConfig(),
140+
Nginx: newNginxAppConfig(),
139141
}
140142
}
141143

@@ -215,6 +217,36 @@ func newHSTSConfig() *HSTSConfig {
215217
}
216218
}
217219

220+
// NginxAppConfig is a wrapper for all Nginx-specific app configurations. These
221+
// options shouldn't be expected to be universally supported by alternative
222+
// router implementations.
223+
type NginxAppConfig struct {
224+
ProxyBuffersConfig *ProxyBuffersConfig `key:"proxyBuffers"`
225+
}
226+
227+
func newNginxAppConfig() *NginxAppConfig {
228+
return &NginxAppConfig{
229+
ProxyBuffersConfig: newProxyBuffersConfig(),
230+
}
231+
}
232+
233+
// ProxyBuffersConfig represents configuration options having to do with Nginx
234+
// proxy buffers.
235+
type ProxyBuffersConfig struct {
236+
Enabled bool `key:"enabled" constraint:"(?i)^(true|false)$"`
237+
Number int `key:"number" constraint:"^[1-9]\\d*$"`
238+
Size string `key:"size" constraint:"^[1-9]\\d*[kKmM]?$"`
239+
BusySize string `key:"busySize" constraint:"^[1-9]\\d*[kKmM]?$"`
240+
}
241+
242+
func newProxyBuffersConfig() *ProxyBuffersConfig {
243+
return &ProxyBuffersConfig{
244+
Number: 8,
245+
Size: "4k",
246+
BusySize: "8k",
247+
}
248+
}
249+
218250
// Build creates a RouterConfig configuration object by querying the k8s API for
219251
// relevant metadata concerning itself and all routable services.
220252
func Build(kubeClient *kubernetes.Clientset) (*RouterConfig, error) {

model/model_validation_test.go

+36
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,38 @@ func TestValidHSTSPreload(t *testing.T) {
343343
testValidValues(t, newTestHSTSConfig, "Preload", "preload", []string{"true", "false", "TRUE", "FALSE"})
344344
}
345345

346+
func TestInvalidAppProxyBuffersEnabled(t *testing.T) {
347+
testInvalidValues(t, newTestProxyBuffersConfig, "Enabled", "enabled", []string{"0", "-1", "foobar"})
348+
}
349+
350+
func TestValidAppProxyBuffersEnabled(t *testing.T) {
351+
testValidValues(t, newTestProxyBuffersConfig, "Enabled", "enabled", []string{"true", "false", "TRUE", "FALSE"})
352+
}
353+
354+
func TestInvalidAppProxyBuffersNumber(t *testing.T) {
355+
testInvalidValues(t, newTestProxyBuffersConfig, "Number", "number", []string{"0", "-1", "foobar"})
356+
}
357+
358+
func TestValidAppProxyBuffersNumber(t *testing.T) {
359+
testValidValues(t, newTestProxyBuffersConfig, "Number", "number", []string{"1", "2", "10"})
360+
}
361+
362+
func TestInvalidAppProxyBuffersSize(t *testing.T) {
363+
testInvalidValues(t, newTestProxyBuffersConfig, "Size", "size", []string{"0", "-1", "foobar"})
364+
}
365+
366+
func TestValidAppProxyBuffersSize(t *testing.T) {
367+
testValidValues(t, newTestProxyBuffersConfig, "Size", "size", []string{"1", "2", "20", "1k", "2k", "10m", "10M"})
368+
}
369+
370+
func TestInvalidAppProxyBuffersBusySize(t *testing.T) {
371+
testInvalidValues(t, newTestProxyBuffersConfig, "BusySize", "busySize", []string{"0", "-1", "foobar"})
372+
}
373+
374+
func TestValidAppProxyBusyBuffersBusySize(t *testing.T) {
375+
testValidValues(t, newTestProxyBuffersConfig, "BusySize", "busySize", []string{"1", "2", "20", "1k", "2k", "10m", "10M"})
376+
}
377+
346378
func testInvalidValues(t *testing.T, builder func() interface{}, fieldName string, key string, badValues []string) {
347379
badMap := make(map[string]string, 1)
348380
for _, badValue := range badValues {
@@ -390,6 +422,10 @@ func newTestHSTSConfig() interface{} {
390422
return newHSTSConfig()
391423
}
392424

425+
func newTestProxyBuffersConfig() interface{} {
426+
return newProxyBuffersConfig()
427+
}
428+
393429
func checkError(t *testing.T, value string, err error) {
394430
want := "modeler.ModelValidationError"
395431
if err == nil {

nginx/config.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,11 @@ http {
242242
add_header X-Correlation-Id $correlation_id always;
243243
{{end}}
244244
245-
{{ if $appConfig.Maintenance }}return 503;{{ else if $appConfig.Available }}proxy_buffering off;
245+
{{ if $appConfig.Maintenance }}return 503;{{ else if $appConfig.Available }}
246+
proxy_buffering {{ if $appConfig.Nginx.ProxyBuffersConfig.Enabled }}on{{ else }}off{{ end }};
247+
proxy_buffer_size {{ $appConfig.Nginx.ProxyBuffersConfig.Size }};
248+
proxy_buffers {{ $appConfig.Nginx.ProxyBuffersConfig.Number }} {{ $appConfig.Nginx.ProxyBuffersConfig.Size }};
249+
proxy_busy_buffers_size {{ $appConfig.Nginx.ProxyBuffersConfig.BusySize }};
246250
proxy_set_header Host $host;
247251
proxy_set_header X-Forwarded-For $remote_addr;
248252
proxy_set_header X-Forwarded-Proto $access_scheme;

0 commit comments

Comments
 (0)