mirror of
https://gitee.com/rainbond/Rainbond.git
synced 2024-11-29 18:27:58 +08:00
fixed #939
This commit is contained in:
parent
0a7bc39767
commit
26b38edc33
@ -41,6 +41,7 @@ type Config struct {
|
||||
CookieDomain string `json:"cookieDomain"`
|
||||
CookiePath string `json:"cookiePath"`
|
||||
NextUpstream string `json:"nextUpstream"`
|
||||
NextUpstreamTimeout int `json:"nextUpstreamTimeout"`
|
||||
NextUpstreamTries int `json:"nextUpstreamTries"`
|
||||
ProxyRedirectFrom string `json:"proxyRedirectFrom"`
|
||||
ProxyRedirectTo string `json:"proxyRedirectTo"`
|
||||
@ -95,6 +96,7 @@ func NewProxyConfig() Config {
|
||||
CookiePath: defBackend.ProxyCookiePath,
|
||||
NextUpstream: defBackend.ProxyNextUpstream,
|
||||
NextUpstreamTries: defBackend.ProxyNextUpstreamTries,
|
||||
NextUpstreamTimeout: defBackend.ProxyNextUpstreamTimeout,
|
||||
RequestBuffering: defBackend.ProxyRequestBuffering,
|
||||
ProxyRedirectFrom: defBackend.ProxyRedirectFrom,
|
||||
ProxyRedirectTo: defBackend.ProxyRedirectTo,
|
||||
@ -233,6 +235,11 @@ func (a proxy) Parse(ing *extensions.Ingress) (interface{}, error) {
|
||||
config.NextUpstreamTries = defBackend.ProxyNextUpstreamTries
|
||||
}
|
||||
|
||||
config.NextUpstreamTimeout, err = parser.GetIntAnnotation("proxy-next-upstream-timeout", ing)
|
||||
if err != nil {
|
||||
config.NextUpstreamTimeout = defBackend.ProxyNextUpstreamTimeout
|
||||
}
|
||||
|
||||
config.RequestBuffering, err = parser.GetStringAnnotation("proxy-request-buffering", ing)
|
||||
if err != nil {
|
||||
config.RequestBuffering = defBackend.ProxyRequestBuffering
|
||||
|
@ -76,8 +76,9 @@ func (m mockBackend) GetDefaultBackend() defaults.Backend {
|
||||
ProxyBuffersNumber: 4,
|
||||
ProxyBufferSize: "10k",
|
||||
ProxyBodySize: 3,
|
||||
ProxyNextUpstream: "error",
|
||||
ProxyNextUpstream: "error timeout",
|
||||
ProxyNextUpstreamTries: 3,
|
||||
ProxyNextUpstreamTimeout: 0,
|
||||
ProxyRequestBuffering: "on",
|
||||
ProxyBuffering: "off",
|
||||
}
|
||||
@ -125,9 +126,6 @@ func TestProxy(t *testing.T) {
|
||||
if p.BodySize != 2 {
|
||||
t.Errorf("expected 2 as body-size but returned %v", p.BodySize)
|
||||
}
|
||||
if p.NextUpstream != "off" {
|
||||
t.Errorf("expected off as next-upstream but returned %v", p.NextUpstream)
|
||||
}
|
||||
if p.NextUpstreamTries != 3 {
|
||||
t.Errorf("expected 3 as next-upstream-tries but returned %v", p.NextUpstreamTries)
|
||||
}
|
||||
@ -171,9 +169,6 @@ func TestProxyWithNoAnnotation(t *testing.T) {
|
||||
if p.BodySize != 3 {
|
||||
t.Errorf("expected 3k as body-size but returned %v", p.BodySize)
|
||||
}
|
||||
if p.NextUpstream != "error" {
|
||||
t.Errorf("expected error as next-upstream but returned %v", p.NextUpstream)
|
||||
}
|
||||
if p.NextUpstreamTries != 3 {
|
||||
t.Errorf("expected 3 as next-upstream-tries but returned %v", p.NextUpstreamTries)
|
||||
}
|
||||
|
@ -81,7 +81,7 @@ func NewDefault() Configuration {
|
||||
cfg := Configuration{
|
||||
Backend: defaults.Backend{
|
||||
ProxyBodySize: bodySize,
|
||||
ProxyConnectTimeout: 60,
|
||||
ProxyConnectTimeout: 5,
|
||||
ProxyReadTimeout: 60,
|
||||
ProxySendTimeout: 60,
|
||||
ProxyBuffersNumber: 4,
|
||||
@ -90,6 +90,7 @@ func NewDefault() Configuration {
|
||||
ProxyCookiePath: "off",
|
||||
ProxyNextUpstream: "error timeout",
|
||||
ProxyNextUpstreamTries: 3,
|
||||
ProxyNextUpstreamTimeout: 0,
|
||||
ProxyRequestBuffering: "on",
|
||||
ProxyRedirectFrom: "off",
|
||||
ProxyRedirectTo: "off",
|
||||
|
@ -42,6 +42,9 @@ type Server struct {
|
||||
ProxyStreamResponses int
|
||||
|
||||
ProxyStreamTimeout string
|
||||
ProxyStreamNextUpstream bool `json:"proxyStreamNextUpstream"`
|
||||
ProxyStreamNextUpstreamTimeout string `json:"proxyStreamNextUpstreamTimeout"`
|
||||
ProxyStreamNextUpstreamTries int `json:"proxyStreamNextUpstreamTries"`
|
||||
//proxy protocol for tcp real ip
|
||||
ProxyProtocol ProxyProtocol
|
||||
}
|
||||
|
@ -211,6 +211,9 @@ func (o *OrService) getNgxServer(conf *v1.Config) (l7srv []*model.Server, l4srv
|
||||
"tenant_id": vs.Namespace,
|
||||
"service_id": vs.ServiceID,
|
||||
},
|
||||
ProxyStreamNextUpstream: true,
|
||||
ProxyStreamNextUpstreamTimeout: "600s",
|
||||
ProxyStreamNextUpstreamTries: 3,
|
||||
}
|
||||
if vs.SSLCert != nil {
|
||||
server.SSLProtocols = vs.SSlProtocols
|
||||
@ -245,6 +248,9 @@ func (o *OrService) getNgxServer(conf *v1.Config) (l7srv []*model.Server, l4srv
|
||||
"service_id": vs.ServiceID,
|
||||
},
|
||||
UpstreamName: vs.PoolName,
|
||||
ProxyStreamNextUpstream: true,
|
||||
ProxyStreamNextUpstreamTimeout: "600s",
|
||||
ProxyStreamNextUpstreamTries: 3,
|
||||
}
|
||||
server.Listen = strings.Join(vs.Listening, " ")
|
||||
l4srv = append(l4srv, server)
|
||||
|
@ -30,6 +30,11 @@ import (
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
const (
|
||||
slash = "/"
|
||||
nonIdempotent = "non_idempotent"
|
||||
)
|
||||
|
||||
var (
|
||||
funcMap = text_template.FuncMap{
|
||||
"empty": func(input interface{}) bool {
|
||||
@ -41,6 +46,7 @@ var (
|
||||
},
|
||||
"buildLuaHeaderRouter": buildLuaHeaderRouter,
|
||||
"isValidByteSize": isValidByteSize,
|
||||
"buildNextUpstream": buildNextUpstream,
|
||||
}
|
||||
)
|
||||
|
||||
@ -153,3 +159,32 @@ func isValidByteSize(input interface{}, isOffset bool) bool {
|
||||
|
||||
return nginxSizeRegex.MatchString(s)
|
||||
}
|
||||
|
||||
func buildNextUpstream(i, r interface{}) string {
|
||||
nextUpstream, ok := i.(string)
|
||||
if !ok {
|
||||
logrus.Errorf("expected a 'string' type but %T was returned", i)
|
||||
return ""
|
||||
}
|
||||
|
||||
retryNonIdempotent := r.(bool)
|
||||
|
||||
parts := strings.Split(nextUpstream, " ")
|
||||
|
||||
nextUpstreamCodes := make([]string, 0, len(parts))
|
||||
for _, v := range parts {
|
||||
if v != "" && v != nonIdempotent {
|
||||
nextUpstreamCodes = append(nextUpstreamCodes, v)
|
||||
}
|
||||
|
||||
if v == nonIdempotent {
|
||||
retryNonIdempotent = true
|
||||
}
|
||||
}
|
||||
|
||||
if retryNonIdempotent {
|
||||
nextUpstreamCodes = append(nextUpstreamCodes, nonIdempotent)
|
||||
}
|
||||
|
||||
return strings.Join(nextUpstreamCodes, " ")
|
||||
}
|
||||
|
@ -77,6 +77,8 @@ type Backend struct {
|
||||
// https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_next_upstream_tries
|
||||
ProxyNextUpstreamTries int `json:"proxy-next-upstream-tries"`
|
||||
|
||||
ProxyNextUpstreamTimeout int `json:"proxy-next-upstream-timeout"`
|
||||
|
||||
// Sets the original text that should be changed in the "Location" and "Refresh" header fields of a proxied server response.
|
||||
// http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_redirect
|
||||
// Default: off
|
||||
|
@ -274,7 +274,6 @@ function _M.call()
|
||||
html = string.gsub(_M.defaultHTML, "POWER", [[<p class="text2" id="power">Power By <a href="https://www.rainbond.com" target="_blank" rel="noopener noreferrer">Rainbond</a></p>]],1)
|
||||
end
|
||||
ngx.print(html)
|
||||
ngx.status = ngx.HTTP_OK
|
||||
end
|
||||
|
||||
return _M
|
||||
|
@ -68,6 +68,10 @@ server {
|
||||
proxy_send_timeout {{ $loc.Proxy.SendTimeout }}s;
|
||||
proxy_read_timeout {{ $loc.Proxy.ReadTimeout }}s;
|
||||
|
||||
proxy_next_upstream {{ buildNextUpstream $loc.Proxy.NextUpstream false }};
|
||||
proxy_next_upstream_timeout {{ $loc.Proxy.NextUpstreamTimeout }};
|
||||
proxy_next_upstream_tries {{ $loc.Proxy.NextUpstreamTries }};
|
||||
|
||||
proxy_buffering {{ $loc.Proxy.ProxyBuffering }};
|
||||
proxy_buffer_size {{ $loc.Proxy.BufferSize }};
|
||||
proxy_buffers {{ $loc.Proxy.BuffersNumber }} {{ $loc.Proxy.BufferSize }};
|
||||
|
@ -8,6 +8,9 @@ server {
|
||||
{{ if .Listen }}listen {{.Listen}} {{ if $tcpServer.ProxyProtocol.Decode }} proxy_protocol{{ end }};{{ end }}
|
||||
proxy_timeout {{ $tcpServer.ProxyStreamTimeout }};
|
||||
proxy_pass upstream_balancer;
|
||||
proxy_next_upstream {{ if $tcpServer.ProxyStreamNextUpstream }}on{{ else }}off{{ end }};
|
||||
proxy_next_upstream_timeout {{ $tcpServer.ProxyStreamNextUpstreamTimeout }};
|
||||
proxy_next_upstream_tries {{ $tcpServer.ProxyStreamNextUpstreamTries }};
|
||||
{{ if $tcpServer.ProxyProtocol.Encode }}
|
||||
proxy_protocol on;
|
||||
{{ end }}
|
||||
@ -23,6 +26,9 @@ server {
|
||||
{{ if $udpServer.Listen }}listen {{$udpServer.Listen}} {{ if $udpServer.ProxyProtocol.Decode }} proxy_protocol{{ end }};{{ end }}
|
||||
{{ if $udpServer.ProxyStreamResponses }}proxy_responses {{ $udpServer.ProxyStreamResponses }}; {{ end }}
|
||||
proxy_timeout {{ $udpServer.ProxyStreamTimeout }};
|
||||
proxy_next_upstream {{ if $udpServer.ProxyStreamNextUpstream }}on{{ else }}off{{ end }};
|
||||
proxy_next_upstream_timeout {{ $udpServer.ProxyStreamNextUpstreamTimeout }};
|
||||
proxy_next_upstream_tries {{ $udpServer.ProxyStreamNextUpstreamTries }};
|
||||
proxy_pass upstream_balancer;
|
||||
}
|
||||
{{ end }}
|
Loading…
Reference in New Issue
Block a user