Skip to content

Commit d1dc3e8

Browse files
authored
Config/Annotations: Add proxy-busy-buffers-size. (#12433)
1 parent 5ae018e commit d1dc3e8

File tree

10 files changed

+59
-0
lines changed

10 files changed

+59
-0
lines changed

docs/user-guide/nginx-configuration/annotations-risk.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
| Proxy | proxy-buffer-size | Low | location |
7474
| Proxy | proxy-buffering | Low | location |
7575
| Proxy | proxy-buffers-number | Low | location |
76+
| Proxy | proxy-busy-buffers-size | Low | location |
7677
| Proxy | proxy-connect-timeout | Low | location |
7778
| Proxy | proxy-cookie-domain | Medium | location |
7879
| Proxy | proxy-cookie-path | Medium | location |

docs/user-guide/nginx-configuration/annotations.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ You can add these Kubernetes annotations to specific Ingress objects to customiz
116116
|[nginx.ingress.kubernetes.io/proxy-buffering](#proxy-buffering)|string|
117117
|[nginx.ingress.kubernetes.io/proxy-buffers-number](#proxy-buffers-number)|number|
118118
|[nginx.ingress.kubernetes.io/proxy-buffer-size](#proxy-buffer-size)|string|
119+
|[nginx.ingress.kubernetes.io/proxy-busy-buffers-size](#proxy-busy-buffers-size)|string|
119120
|[nginx.ingress.kubernetes.io/proxy-max-temp-file-size](#proxy-max-temp-file-size)|string|
120121
|[nginx.ingress.kubernetes.io/ssl-ciphers](#ssl-ciphers)|string|
121122
|[nginx.ingress.kubernetes.io/ssl-prefer-server-ciphers](#ssl-ciphers)|"true" or "false"|
@@ -742,6 +743,18 @@ To configure this setting globally, set `proxy-buffer-size` in [NGINX ConfigMap]
742743
nginx.ingress.kubernetes.io/proxy-buffer-size: "8k"
743744
```
744745

746+
### Proxy busy buffers size
747+
748+
[Limits the total size of buffers that can be busy](https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_busy_buffers_size) sending a response to the client while the response is not yet fully read.
749+
750+
By default proxy busy buffers size is set as "8k".
751+
752+
To configure this setting globally, set `proxy-busy-buffers-size` in the [ConfigMap](./configmap.md#proxy-busy-buffers-size). To use custom values in an Ingress rule, define this annotation:
753+
754+
```yaml
755+
nginx.ingress.kubernetes.io/proxy-busy-buffers-size: "16k"
756+
```
757+
745758
### Proxy max temp file size
746759

747760
When [`buffering`](https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_buffering) of responses from the proxied server is enabled, and the whole response does not fit into the buffers set by the [`proxy_buffer_size`](https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_buffer_size) and [`proxy_buffers`](https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_buffers) directives, a part of the response can be saved to a temporary file. This directive sets the maximum `size` of the temporary file setting the [`proxy_max_temp_file_size`](https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_max_temp_file_size). The size of data written to the temporary file at a time is set by the [`proxy_temp_file_write_size`](https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_temp_file_write_size) directive.

docs/user-guide/nginx-configuration/configmap.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ The following table shows a configuration option's name, type, and the default v
179179
| [proxy-send-timeout](#proxy-send-timeout) | int | 60 | |
180180
| [proxy-buffers-number](#proxy-buffers-number) | int | 4 | |
181181
| [proxy-buffer-size](#proxy-buffer-size) | string | "4k" | |
182+
| [proxy-busy-buffers-size](#proxy-busy-buffers-size) | string | "8k" | |
182183
| [proxy-cookie-path](#proxy-cookie-path) | string | "off" | |
183184
| [proxy-cookie-domain](#proxy-cookie-domain) | string | "off" | |
184185
| [proxy-next-upstream](#proxy-next-upstream) | string | "error timeout" | |
@@ -1109,6 +1110,10 @@ Sets the number of the buffer used for [reading the first part of the response](
11091110

11101111
Sets the size of the buffer used for [reading the first part of the response](https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_buffer_size) received from the proxied server. This part usually contains a small response header.
11111112

1113+
## proxy-busy-buffers-size
1114+
1115+
[Limits the total size of buffers that can be busy](https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_busy_buffers_size) sending a response to the client while the response is not yet fully read.
1116+
11121117
## proxy-cookie-path
11131118

11141119
Sets a text that [should be changed in the path attribute](https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_cookie_path) of the “Set-Cookie” header fields of a proxied server response.

internal/ingress/annotations/proxy/main.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const (
3131
proxyReadTimeoutAnnotation = "proxy-read-timeout"
3232
proxyBuffersNumberAnnotation = "proxy-buffers-number"
3333
proxyBufferSizeAnnotation = "proxy-buffer-size"
34+
proxyBusyBuffersSizeAnnotation = "proxy-busy-buffers-size"
3435
proxyCookiePathAnnotation = "proxy-cookie-path"
3536
proxyCookieDomainAnnotation = "proxy-cookie-domain"
3637
proxyBodySizeAnnotation = "proxy-body-size"
@@ -82,6 +83,12 @@ var proxyAnnotations = parser.Annotation{
8283
Documentation: `This annotation sets the size of the buffer proxy_buffer_size used for reading the first part of the response received from the proxied server.
8384
By default proxy buffer size is set as "4k".`,
8485
},
86+
proxyBusyBuffersSizeAnnotation: {
87+
Validator: parser.ValidateRegex(parser.SizeRegex, true),
88+
Scope: parser.AnnotationScopeLocation,
89+
Risk: parser.AnnotationRiskLow,
90+
Documentation: `This annotation limits the total size of buffers that can be busy sending a response to the client while the response is not yet fully read. By default proxy busy buffers size is set as "8k".`,
91+
},
8592
proxyCookiePathAnnotation: {
8693
Validator: parser.ValidateRegex(parser.URLIsValidRegex, true),
8794
Scope: parser.AnnotationScopeLocation,
@@ -167,6 +174,7 @@ type Config struct {
167174
ReadTimeout int `json:"readTimeout"`
168175
BuffersNumber int `json:"buffersNumber"`
169176
BufferSize string `json:"bufferSize"`
177+
BusyBuffersSize string `json:"busyBuffersSize"`
170178
CookieDomain string `json:"cookieDomain"`
171179
CookiePath string `json:"cookiePath"`
172180
NextUpstream string `json:"nextUpstream"`
@@ -206,6 +214,9 @@ func (l1 *Config) Equal(l2 *Config) bool {
206214
if l1.BufferSize != l2.BufferSize {
207215
return false
208216
}
217+
if l1.BusyBuffersSize != l2.BusyBuffersSize {
218+
return false
219+
}
209220
if l1.CookieDomain != l2.CookieDomain {
210221
return false
211222
}
@@ -290,6 +301,11 @@ func (a proxy) Parse(ing *networking.Ingress) (interface{}, error) {
290301
config.BufferSize = defBackend.ProxyBufferSize
291302
}
292303

304+
config.BusyBuffersSize, err = parser.GetStringAnnotation(proxyBusyBuffersSizeAnnotation, ing, a.annotationConfig.Annotations)
305+
if err != nil {
306+
config.BusyBuffersSize = defBackend.ProxyBusyBuffersSize
307+
}
308+
293309
config.CookiePath, err = parser.GetStringAnnotation(proxyCookiePathAnnotation, ing, a.annotationConfig.Annotations)
294310
if err != nil {
295311
config.CookiePath = defBackend.ProxyCookiePath

internal/ingress/annotations/proxy/main_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ func (m mockBackend) GetDefaultBackend() defaults.Backend {
8888
ProxyReadTimeout: 20,
8989
ProxyBuffersNumber: 4,
9090
ProxyBufferSize: "10k",
91+
ProxyBusyBuffersSize: "15k",
9192
ProxyBodySize: "3k",
9293
ProxyNextUpstream: "error",
9394
ProxyNextUpstreamTimeout: 0,
@@ -108,6 +109,7 @@ func TestProxy(t *testing.T) {
108109
data[parser.GetAnnotationWithPrefix("proxy-read-timeout")] = "3"
109110
data[parser.GetAnnotationWithPrefix("proxy-buffers-number")] = "8"
110111
data[parser.GetAnnotationWithPrefix("proxy-buffer-size")] = "1k"
112+
data[parser.GetAnnotationWithPrefix("proxy-busy-buffers-size")] = "4k"
111113
data[parser.GetAnnotationWithPrefix("proxy-body-size")] = "2k"
112114
data[parser.GetAnnotationWithPrefix("proxy-next-upstream")] = off
113115
data[parser.GetAnnotationWithPrefix("proxy-next-upstream-timeout")] = "5"
@@ -141,6 +143,9 @@ func TestProxy(t *testing.T) {
141143
if p.BufferSize != "1k" {
142144
t.Errorf("expected 1k as buffer-size but returned %v", p.BufferSize)
143145
}
146+
if p.BusyBuffersSize != "4k" {
147+
t.Errorf("expected 4k as busy-buffers-size but returned %v", p.BusyBuffersSize)
148+
}
144149
if p.BodySize != "2k" {
145150
t.Errorf("expected 2k as body-size but returned %v", p.BodySize)
146151
}
@@ -176,6 +181,7 @@ func TestProxyComplex(t *testing.T) {
176181
data[parser.GetAnnotationWithPrefix("proxy-read-timeout")] = "3"
177182
data[parser.GetAnnotationWithPrefix("proxy-buffers-number")] = "8"
178183
data[parser.GetAnnotationWithPrefix("proxy-buffer-size")] = "1k"
184+
data[parser.GetAnnotationWithPrefix("proxy-busy-buffers-size")] = "4k"
179185
data[parser.GetAnnotationWithPrefix("proxy-body-size")] = "2k"
180186
data[parser.GetAnnotationWithPrefix("proxy-next-upstream")] = "error http_502"
181187
data[parser.GetAnnotationWithPrefix("proxy-next-upstream-timeout")] = "5"
@@ -209,6 +215,9 @@ func TestProxyComplex(t *testing.T) {
209215
if p.BufferSize != "1k" {
210216
t.Errorf("expected 1k as buffer-size but returned %v", p.BufferSize)
211217
}
218+
if p.BusyBuffersSize != "4k" {
219+
t.Errorf("expected 4k as buffer-size but returned %v", p.BusyBuffersSize)
220+
}
212221
if p.BodySize != "2k" {
213222
t.Errorf("expected 2k as body-size but returned %v", p.BodySize)
214223
}
@@ -264,6 +273,9 @@ func TestProxyWithNoAnnotation(t *testing.T) {
264273
if p.BufferSize != "10k" {
265274
t.Errorf("expected 10k as buffer-size but returned %v", p.BufferSize)
266275
}
276+
if p.BusyBuffersSize != "15k" {
277+
t.Errorf("expected 15k as buffer-size but returned %v", p.BusyBuffersSize)
278+
}
267279
if p.BodySize != "3k" {
268280
t.Errorf("expected 3k as body-size but returned %v", p.BodySize)
269281
}

internal/ingress/controller/config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -850,6 +850,7 @@ func NewDefault() Configuration {
850850
ProxySendTimeout: 60,
851851
ProxyBuffersNumber: 4,
852852
ProxyBufferSize: "4k",
853+
ProxyBusyBuffersSize: "8k",
853854
ProxyCookieDomain: "off",
854855
ProxyCookiePath: "off",
855856
ProxyNextUpstream: "error timeout",

internal/ingress/controller/controller.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,6 +1255,7 @@ func (n *NGINXController) createServers(data []*ingress.Ingress,
12551255
ReadTimeout: bdef.ProxyReadTimeout,
12561256
BuffersNumber: bdef.ProxyBuffersNumber,
12571257
BufferSize: bdef.ProxyBufferSize,
1258+
BusyBuffersSize: bdef.ProxyBusyBuffersSize,
12581259
CookieDomain: bdef.ProxyCookieDomain,
12591260
CookiePath: bdef.ProxyCookiePath,
12601261
NextUpstream: bdef.ProxyNextUpstream,

internal/ingress/defaults/main.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ type Backend struct {
6969
// http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_buffer_size)
7070
ProxyBufferSize string `json:"proxy-buffer-size"`
7171

72+
// Limits the total size of buffers that can be busy sending a response to the client while
73+
// the response is not yet fully read.
74+
// http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_busy_buffers_size
75+
ProxyBusyBuffersSize string `json:"proxy-busy-buffers-size"`
76+
7277
// Sets a text that should be changed in the path attribute of the “Set-Cookie” header fields of
7378
// a proxied server response.
7479
// http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_cookie_path

rootfs/etc/nginx/template/nginx.tmpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,6 +1041,7 @@ stream {
10411041
{{ end }}
10421042
proxy_buffer_size {{ $location.Proxy.BufferSize }};
10431043
proxy_buffers {{ $location.Proxy.BuffersNumber }} {{ $location.Proxy.BufferSize }};
1044+
proxy_busy_buffers_size {{ $location.Proxy.BusyBuffersSize }};
10441045
proxy_request_buffering {{ $location.Proxy.RequestBuffering }};
10451046

10461047
proxy_ssl_server_name on;
@@ -1296,6 +1297,7 @@ stream {
12961297
proxy_buffering {{ $location.Proxy.ProxyBuffering }};
12971298
proxy_buffer_size {{ $location.Proxy.BufferSize }};
12981299
proxy_buffers {{ $location.Proxy.BuffersNumber }} {{ $location.Proxy.BufferSize }};
1300+
proxy_busy_buffers_size {{ $location.Proxy.BusyBuffersSize }};
12991301
{{ if isValidByteSize $location.Proxy.ProxyMaxTempFileSize true }}
13001302
proxy_max_temp_file_size {{ $location.Proxy.ProxyMaxTempFileSize }};
13011303
{{ end }}

test/e2e/annotations/proxy.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,13 @@ var _ = framework.DescribeAnnotation("proxy-*", func() {
160160
proxyBuffering := "on"
161161
proxyBuffersNumber := "8"
162162
proxyBufferSize := "8k"
163+
proxyBusyBuffersSize := "16k"
163164

164165
annotations := make(map[string]string)
165166
annotations["nginx.ingress.kubernetes.io/proxy-buffering"] = proxyBuffering
166167
annotations["nginx.ingress.kubernetes.io/proxy-buffers-number"] = proxyBuffersNumber
167168
annotations["nginx.ingress.kubernetes.io/proxy-buffer-size"] = proxyBufferSize
169+
annotations["nginx.ingress.kubernetes.io/proxy-busy-buffers-size"] = proxyBusyBuffersSize
168170

169171
ing := framework.NewSingleIngress(host, "/", host, f.Namespace, framework.EchoService, 80, annotations)
170172
f.EnsureIngress(ing)
@@ -174,6 +176,7 @@ var _ = framework.DescribeAnnotation("proxy-*", func() {
174176
return strings.Contains(server, fmt.Sprintf("proxy_buffering %s;", proxyBuffering)) &&
175177
strings.Contains(server, fmt.Sprintf("proxy_buffer_size %s;", proxyBufferSize)) &&
176178
strings.Contains(server, fmt.Sprintf("proxy_buffers %s %s;", proxyBuffersNumber, proxyBufferSize)) &&
179+
strings.Contains(server, fmt.Sprintf("proxy_busy_buffers_size %s;", proxyBusyBuffersSize)) &&
177180
strings.Contains(server, fmt.Sprintf("proxy_request_buffering %s;", proxyBuffering))
178181
})
179182
})

0 commit comments

Comments
 (0)