feat: configurable proxy buffer number
This commit is contained in:
parent
d74dea7585
commit
c92d29d462
8 changed files with 29 additions and 4 deletions
|
@ -29,6 +29,7 @@ type Config struct {
|
||||||
ConnectTimeout int `json:"connectTimeout"`
|
ConnectTimeout int `json:"connectTimeout"`
|
||||||
SendTimeout int `json:"sendTimeout"`
|
SendTimeout int `json:"sendTimeout"`
|
||||||
ReadTimeout int `json:"readTimeout"`
|
ReadTimeout int `json:"readTimeout"`
|
||||||
|
BufferNumber int `json:"bufferNumber"`
|
||||||
BufferSize string `json:"bufferSize"`
|
BufferSize string `json:"bufferSize"`
|
||||||
CookieDomain string `json:"cookieDomain"`
|
CookieDomain string `json:"cookieDomain"`
|
||||||
CookiePath string `json:"cookiePath"`
|
CookiePath string `json:"cookiePath"`
|
||||||
|
@ -60,6 +61,9 @@ func (l1 *Config) Equal(l2 *Config) bool {
|
||||||
if l1.ReadTimeout != l2.ReadTimeout {
|
if l1.ReadTimeout != l2.ReadTimeout {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
if l1.BufferNumber != l2.BufferNumber {
|
||||||
|
return false
|
||||||
|
}
|
||||||
if l1.BufferSize != l2.BufferSize {
|
if l1.BufferSize != l2.BufferSize {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -123,6 +127,11 @@ func (a proxy) Parse(ing *extensions.Ingress) (interface{}, error) {
|
||||||
config.ReadTimeout = defBackend.ProxyReadTimeout
|
config.ReadTimeout = defBackend.ProxyReadTimeout
|
||||||
}
|
}
|
||||||
|
|
||||||
|
config.BufferNumber, err = parser.GetIntAnnotation("proxy-buffer-number", ing)
|
||||||
|
if err != nil {
|
||||||
|
config.BufferNumber = defBackend.ProxyBufferNumber
|
||||||
|
}
|
||||||
|
|
||||||
config.BufferSize, err = parser.GetStringAnnotation("proxy-buffer-size", ing)
|
config.BufferSize, err = parser.GetStringAnnotation("proxy-buffer-size", ing)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
config.BufferSize = defBackend.ProxyBufferSize
|
config.BufferSize = defBackend.ProxyBufferSize
|
||||||
|
|
|
@ -73,6 +73,7 @@ func (m mockBackend) GetDefaultBackend() defaults.Backend {
|
||||||
ProxyConnectTimeout: 10,
|
ProxyConnectTimeout: 10,
|
||||||
ProxySendTimeout: 15,
|
ProxySendTimeout: 15,
|
||||||
ProxyReadTimeout: 20,
|
ProxyReadTimeout: 20,
|
||||||
|
ProxyBufferNumber: 4,
|
||||||
ProxyBufferSize: "10k",
|
ProxyBufferSize: "10k",
|
||||||
ProxyBodySize: "3k",
|
ProxyBodySize: "3k",
|
||||||
ProxyNextUpstream: "error",
|
ProxyNextUpstream: "error",
|
||||||
|
@ -89,6 +90,7 @@ func TestProxy(t *testing.T) {
|
||||||
data[parser.GetAnnotationWithPrefix("proxy-connect-timeout")] = "1"
|
data[parser.GetAnnotationWithPrefix("proxy-connect-timeout")] = "1"
|
||||||
data[parser.GetAnnotationWithPrefix("proxy-send-timeout")] = "2"
|
data[parser.GetAnnotationWithPrefix("proxy-send-timeout")] = "2"
|
||||||
data[parser.GetAnnotationWithPrefix("proxy-read-timeout")] = "3"
|
data[parser.GetAnnotationWithPrefix("proxy-read-timeout")] = "3"
|
||||||
|
data[parser.GetAnnotationWithPrefix("proxy-buffer-number")] = "8"
|
||||||
data[parser.GetAnnotationWithPrefix("proxy-buffer-size")] = "1k"
|
data[parser.GetAnnotationWithPrefix("proxy-buffer-size")] = "1k"
|
||||||
data[parser.GetAnnotationWithPrefix("proxy-body-size")] = "2k"
|
data[parser.GetAnnotationWithPrefix("proxy-body-size")] = "2k"
|
||||||
data[parser.GetAnnotationWithPrefix("proxy-next-upstream")] = "off"
|
data[parser.GetAnnotationWithPrefix("proxy-next-upstream")] = "off"
|
||||||
|
@ -114,6 +116,9 @@ func TestProxy(t *testing.T) {
|
||||||
if p.ReadTimeout != 3 {
|
if p.ReadTimeout != 3 {
|
||||||
t.Errorf("expected 3 as read-timeout but returned %v", p.ReadTimeout)
|
t.Errorf("expected 3 as read-timeout but returned %v", p.ReadTimeout)
|
||||||
}
|
}
|
||||||
|
if p.BufferNumber != 8 {
|
||||||
|
t.Errorf("expected 8 as proxy-buffer-number but returned %v", p.BufferNumber)
|
||||||
|
}
|
||||||
if p.BufferSize != "1k" {
|
if p.BufferSize != "1k" {
|
||||||
t.Errorf("expected 1k as buffer-size but returned %v", p.BufferSize)
|
t.Errorf("expected 1k as buffer-size but returned %v", p.BufferSize)
|
||||||
}
|
}
|
||||||
|
@ -157,6 +162,9 @@ func TestProxyWithNoAnnotation(t *testing.T) {
|
||||||
if p.ReadTimeout != 20 {
|
if p.ReadTimeout != 20 {
|
||||||
t.Errorf("expected 20 as read-timeout but returned %v", p.ReadTimeout)
|
t.Errorf("expected 20 as read-timeout but returned %v", p.ReadTimeout)
|
||||||
}
|
}
|
||||||
|
if p.BufferNumber != 4 {
|
||||||
|
t.Errorf("expected 4 as buffer-number but returned %v", p.BufferNumber)
|
||||||
|
}
|
||||||
if p.BufferSize != "10k" {
|
if p.BufferSize != "10k" {
|
||||||
t.Errorf("expected 10k as buffer-size but returned %v", p.BufferSize)
|
t.Errorf("expected 10k as buffer-size but returned %v", p.BufferSize)
|
||||||
}
|
}
|
||||||
|
|
|
@ -671,6 +671,7 @@ func NewDefault() Configuration {
|
||||||
ProxyConnectTimeout: 5,
|
ProxyConnectTimeout: 5,
|
||||||
ProxyReadTimeout: 60,
|
ProxyReadTimeout: 60,
|
||||||
ProxySendTimeout: 60,
|
ProxySendTimeout: 60,
|
||||||
|
ProxyBufferNumber: 4,
|
||||||
ProxyBufferSize: "4k",
|
ProxyBufferSize: "4k",
|
||||||
ProxyCookieDomain: "off",
|
ProxyCookieDomain: "off",
|
||||||
ProxyCookiePath: "off",
|
ProxyCookiePath: "off",
|
||||||
|
|
|
@ -887,6 +887,7 @@ func (n *NGINXController) createServers(data []*ingress.Ingress,
|
||||||
ConnectTimeout: bdef.ProxyConnectTimeout,
|
ConnectTimeout: bdef.ProxyConnectTimeout,
|
||||||
SendTimeout: bdef.ProxySendTimeout,
|
SendTimeout: bdef.ProxySendTimeout,
|
||||||
ReadTimeout: bdef.ProxyReadTimeout,
|
ReadTimeout: bdef.ProxyReadTimeout,
|
||||||
|
BufferNumber: bdef.ProxyBufferNumber,
|
||||||
BufferSize: bdef.ProxyBufferSize,
|
BufferSize: bdef.ProxyBufferSize,
|
||||||
CookieDomain: bdef.ProxyCookieDomain,
|
CookieDomain: bdef.ProxyCookieDomain,
|
||||||
CookiePath: bdef.ProxyCookiePath,
|
CookiePath: bdef.ProxyCookiePath,
|
||||||
|
|
|
@ -50,6 +50,10 @@ type Backend struct {
|
||||||
// http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_send_timeout
|
// http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_send_timeout
|
||||||
ProxySendTimeout int `json:"proxy-send-timeout"`
|
ProxySendTimeout int `json:"proxy-send-timeout"`
|
||||||
|
|
||||||
|
// Sets the number of the buffers used for reading a response from the proxied server
|
||||||
|
// http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_buffers
|
||||||
|
ProxyBufferNumber int `json:"proxy-buffer-number"`
|
||||||
|
|
||||||
// Sets the size of the buffer used for reading the first part of the response received from the
|
// Sets the size of the buffer used for reading the first part of the response received from the
|
||||||
// proxied server. This part usually contains a small response header.
|
// proxied server. This part usually contains a small response header.
|
||||||
// http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_buffer_size)
|
// http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_buffer_size)
|
||||||
|
|
|
@ -969,7 +969,7 @@ stream {
|
||||||
|
|
||||||
proxy_buffering {{ $location.Proxy.ProxyBuffering }};
|
proxy_buffering {{ $location.Proxy.ProxyBuffering }};
|
||||||
proxy_buffer_size {{ $location.Proxy.BufferSize }};
|
proxy_buffer_size {{ $location.Proxy.BufferSize }};
|
||||||
proxy_buffers 4 {{ $location.Proxy.BufferSize }};
|
proxy_buffers {{$location.Proxy.BufferNumber}} {{ $location.Proxy.BufferSize }};
|
||||||
proxy_request_buffering {{ $location.Proxy.RequestBuffering }};
|
proxy_request_buffering {{ $location.Proxy.RequestBuffering }};
|
||||||
|
|
||||||
proxy_http_version 1.1;
|
proxy_http_version 1.1;
|
||||||
|
@ -1267,7 +1267,7 @@ stream {
|
||||||
|
|
||||||
proxy_buffering {{ $location.Proxy.ProxyBuffering }};
|
proxy_buffering {{ $location.Proxy.ProxyBuffering }};
|
||||||
proxy_buffer_size {{ $location.Proxy.BufferSize }};
|
proxy_buffer_size {{ $location.Proxy.BufferSize }};
|
||||||
proxy_buffers 4 {{ $location.Proxy.BufferSize }};
|
proxy_buffers {{$location.Proxy.BufferNumber}} {{ $location.Proxy.BufferSize }};
|
||||||
proxy_request_buffering {{ $location.Proxy.RequestBuffering }};
|
proxy_request_buffering {{ $location.Proxy.RequestBuffering }};
|
||||||
|
|
||||||
proxy_http_version 1.1;
|
proxy_http_version 1.1;
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
"bind-address-ipv6": [ "[2001:db8:a0b:12f0::1]" ,"[3731:54:65fe:2::a7]" ,"[33:33:33::33::33]" ],
|
"bind-address-ipv6": [ "[2001:db8:a0b:12f0::1]" ,"[3731:54:65fe:2::a7]" ,"[33:33:33::33::33]" ],
|
||||||
"backend": {
|
"backend": {
|
||||||
"custom-http-errors": [404],
|
"custom-http-errors": [404],
|
||||||
|
"proxy-buffer-number": "4",
|
||||||
"proxy-buffer-size": "4k",
|
"proxy-buffer-size": "4k",
|
||||||
"proxy-connect-timeout": 5,
|
"proxy-connect-timeout": 5,
|
||||||
"proxy-read-timeout": 60,
|
"proxy-read-timeout": 60,
|
||||||
|
|
|
@ -148,6 +148,7 @@ var _ = framework.IngressNginxDescribe("Annotations - Proxy", func() {
|
||||||
It("should turn on proxy-buffering", func() {
|
It("should turn on proxy-buffering", func() {
|
||||||
annotations := map[string]string{
|
annotations := map[string]string{
|
||||||
"nginx.ingress.kubernetes.io/proxy-buffering": "on",
|
"nginx.ingress.kubernetes.io/proxy-buffering": "on",
|
||||||
|
"nginx.ingress.kubernetes.io/proxy-buffer-number": "4",
|
||||||
"nginx.ingress.kubernetes.io/proxy-buffer-size": "8k",
|
"nginx.ingress.kubernetes.io/proxy-buffer-size": "8k",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue