Config/Annotations: Add proxy-busy-buffers-size. (#12433)

This commit is contained in:
Boris Kreitchman 2024-12-05 20:10:00 +02:00 committed by GitHub
parent 5ae018e5df
commit d1dc3e827f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 59 additions and 0 deletions

View file

@ -31,6 +31,7 @@ const (
proxyReadTimeoutAnnotation = "proxy-read-timeout"
proxyBuffersNumberAnnotation = "proxy-buffers-number"
proxyBufferSizeAnnotation = "proxy-buffer-size"
proxyBusyBuffersSizeAnnotation = "proxy-busy-buffers-size"
proxyCookiePathAnnotation = "proxy-cookie-path"
proxyCookieDomainAnnotation = "proxy-cookie-domain"
proxyBodySizeAnnotation = "proxy-body-size"
@ -82,6 +83,12 @@ var proxyAnnotations = parser.Annotation{
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.
By default proxy buffer size is set as "4k".`,
},
proxyBusyBuffersSizeAnnotation: {
Validator: parser.ValidateRegex(parser.SizeRegex, true),
Scope: parser.AnnotationScopeLocation,
Risk: parser.AnnotationRiskLow,
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".`,
},
proxyCookiePathAnnotation: {
Validator: parser.ValidateRegex(parser.URLIsValidRegex, true),
Scope: parser.AnnotationScopeLocation,
@ -167,6 +174,7 @@ type Config struct {
ReadTimeout int `json:"readTimeout"`
BuffersNumber int `json:"buffersNumber"`
BufferSize string `json:"bufferSize"`
BusyBuffersSize string `json:"busyBuffersSize"`
CookieDomain string `json:"cookieDomain"`
CookiePath string `json:"cookiePath"`
NextUpstream string `json:"nextUpstream"`
@ -206,6 +214,9 @@ func (l1 *Config) Equal(l2 *Config) bool {
if l1.BufferSize != l2.BufferSize {
return false
}
if l1.BusyBuffersSize != l2.BusyBuffersSize {
return false
}
if l1.CookieDomain != l2.CookieDomain {
return false
}
@ -290,6 +301,11 @@ func (a proxy) Parse(ing *networking.Ingress) (interface{}, error) {
config.BufferSize = defBackend.ProxyBufferSize
}
config.BusyBuffersSize, err = parser.GetStringAnnotation(proxyBusyBuffersSizeAnnotation, ing, a.annotationConfig.Annotations)
if err != nil {
config.BusyBuffersSize = defBackend.ProxyBusyBuffersSize
}
config.CookiePath, err = parser.GetStringAnnotation(proxyCookiePathAnnotation, ing, a.annotationConfig.Annotations)
if err != nil {
config.CookiePath = defBackend.ProxyCookiePath

View file

@ -88,6 +88,7 @@ func (m mockBackend) GetDefaultBackend() defaults.Backend {
ProxyReadTimeout: 20,
ProxyBuffersNumber: 4,
ProxyBufferSize: "10k",
ProxyBusyBuffersSize: "15k",
ProxyBodySize: "3k",
ProxyNextUpstream: "error",
ProxyNextUpstreamTimeout: 0,
@ -108,6 +109,7 @@ func TestProxy(t *testing.T) {
data[parser.GetAnnotationWithPrefix("proxy-read-timeout")] = "3"
data[parser.GetAnnotationWithPrefix("proxy-buffers-number")] = "8"
data[parser.GetAnnotationWithPrefix("proxy-buffer-size")] = "1k"
data[parser.GetAnnotationWithPrefix("proxy-busy-buffers-size")] = "4k"
data[parser.GetAnnotationWithPrefix("proxy-body-size")] = "2k"
data[parser.GetAnnotationWithPrefix("proxy-next-upstream")] = off
data[parser.GetAnnotationWithPrefix("proxy-next-upstream-timeout")] = "5"
@ -141,6 +143,9 @@ func TestProxy(t *testing.T) {
if p.BufferSize != "1k" {
t.Errorf("expected 1k as buffer-size but returned %v", p.BufferSize)
}
if p.BusyBuffersSize != "4k" {
t.Errorf("expected 4k as busy-buffers-size but returned %v", p.BusyBuffersSize)
}
if p.BodySize != "2k" {
t.Errorf("expected 2k as body-size but returned %v", p.BodySize)
}
@ -176,6 +181,7 @@ func TestProxyComplex(t *testing.T) {
data[parser.GetAnnotationWithPrefix("proxy-read-timeout")] = "3"
data[parser.GetAnnotationWithPrefix("proxy-buffers-number")] = "8"
data[parser.GetAnnotationWithPrefix("proxy-buffer-size")] = "1k"
data[parser.GetAnnotationWithPrefix("proxy-busy-buffers-size")] = "4k"
data[parser.GetAnnotationWithPrefix("proxy-body-size")] = "2k"
data[parser.GetAnnotationWithPrefix("proxy-next-upstream")] = "error http_502"
data[parser.GetAnnotationWithPrefix("proxy-next-upstream-timeout")] = "5"
@ -209,6 +215,9 @@ func TestProxyComplex(t *testing.T) {
if p.BufferSize != "1k" {
t.Errorf("expected 1k as buffer-size but returned %v", p.BufferSize)
}
if p.BusyBuffersSize != "4k" {
t.Errorf("expected 4k as buffer-size but returned %v", p.BusyBuffersSize)
}
if p.BodySize != "2k" {
t.Errorf("expected 2k as body-size but returned %v", p.BodySize)
}
@ -264,6 +273,9 @@ func TestProxyWithNoAnnotation(t *testing.T) {
if p.BufferSize != "10k" {
t.Errorf("expected 10k as buffer-size but returned %v", p.BufferSize)
}
if p.BusyBuffersSize != "15k" {
t.Errorf("expected 15k as buffer-size but returned %v", p.BusyBuffersSize)
}
if p.BodySize != "3k" {
t.Errorf("expected 3k as body-size but returned %v", p.BodySize)
}