mirror of
https://github.com/alibaba/higress.git
synced 2026-06-05 02:27:28 +08:00
fix: bug with close setting of idle timeout (#775)
Signed-off-by: sjcsjc123 <1401189096@qq.com>
This commit is contained in:
@@ -15,7 +15,6 @@
|
|||||||
package configmap
|
package configmap
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
@@ -58,7 +57,7 @@ type Global struct {
|
|||||||
// Downstream configures the behavior of the downstream connection.
|
// Downstream configures the behavior of the downstream connection.
|
||||||
type Downstream struct {
|
type Downstream struct {
|
||||||
// IdleTimeout limits the time that a connection may be idle and stream idle.
|
// IdleTimeout limits the time that a connection may be idle and stream idle.
|
||||||
IdleTimeout uint32 `json:"idleTimeout,omitempty"`
|
IdleTimeout uint32 `json:"idleTimeout"`
|
||||||
// MaxRequestHeadersKb limits the size of request headers allowed.
|
// MaxRequestHeadersKb limits the size of request headers allowed.
|
||||||
MaxRequestHeadersKb uint32 `json:"maxRequestHeadersKb,omitempty"`
|
MaxRequestHeadersKb uint32 `json:"maxRequestHeadersKb,omitempty"`
|
||||||
// ConnectionBufferLimits configures the buffer size limits for connections.
|
// ConnectionBufferLimits configures the buffer size limits for connections.
|
||||||
@@ -139,12 +138,19 @@ func compareGlobal(old *Global, new *Global) (Result, error) {
|
|||||||
// deepCopyGlobal deep copies the global option.
|
// deepCopyGlobal deep copies the global option.
|
||||||
func deepCopyGlobal(global *Global) (*Global, error) {
|
func deepCopyGlobal(global *Global) (*Global, error) {
|
||||||
newGlobal := NewDefaultGlobalOption()
|
newGlobal := NewDefaultGlobalOption()
|
||||||
bytes, err := json.Marshal(global)
|
if global.Downstream != nil {
|
||||||
if err != nil {
|
newGlobal.Downstream.IdleTimeout = global.Downstream.IdleTimeout
|
||||||
return nil, err
|
newGlobal.Downstream.MaxRequestHeadersKb = global.Downstream.MaxRequestHeadersKb
|
||||||
|
newGlobal.Downstream.ConnectionBufferLimits = global.Downstream.ConnectionBufferLimits
|
||||||
|
if global.Downstream.Http2 != nil {
|
||||||
|
newGlobal.Downstream.Http2.MaxConcurrentStreams = global.Downstream.Http2.MaxConcurrentStreams
|
||||||
|
newGlobal.Downstream.Http2.InitialStreamWindowSize = global.Downstream.Http2.InitialStreamWindowSize
|
||||||
|
newGlobal.Downstream.Http2.InitialConnectionWindowSize = global.Downstream.Http2.InitialConnectionWindowSize
|
||||||
|
}
|
||||||
}
|
}
|
||||||
err = json.Unmarshal(bytes, newGlobal)
|
newGlobal.AddXRealIpHeader = global.AddXRealIpHeader
|
||||||
return newGlobal, err
|
newGlobal.DisableXEnvoyHeaders = global.DisableXEnvoyHeaders
|
||||||
|
return newGlobal, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewDefaultGlobalOption returns a default global config.
|
// NewDefaultGlobalOption returns a default global config.
|
||||||
|
|||||||
@@ -131,7 +131,7 @@ func Test_deepCopyGlobal(t *testing.T) {
|
|||||||
name: "deep copy 2",
|
name: "deep copy 2",
|
||||||
global: &Global{
|
global: &Global{
|
||||||
Downstream: &Downstream{
|
Downstream: &Downstream{
|
||||||
IdleTimeout: 1,
|
IdleTimeout: 0,
|
||||||
MaxRequestHeadersKb: 9600,
|
MaxRequestHeadersKb: 9600,
|
||||||
ConnectionBufferLimits: 4096,
|
ConnectionBufferLimits: 4096,
|
||||||
Http2: NewDefaultHttp2(),
|
Http2: NewDefaultHttp2(),
|
||||||
@@ -141,7 +141,7 @@ func Test_deepCopyGlobal(t *testing.T) {
|
|||||||
},
|
},
|
||||||
want: &Global{
|
want: &Global{
|
||||||
Downstream: &Downstream{
|
Downstream: &Downstream{
|
||||||
IdleTimeout: 1,
|
IdleTimeout: 0,
|
||||||
MaxRequestHeadersKb: 9600,
|
MaxRequestHeadersKb: 9600,
|
||||||
ConnectionBufferLimits: 4096,
|
ConnectionBufferLimits: 4096,
|
||||||
Http2: NewDefaultHttp2(),
|
Http2: NewDefaultHttp2(),
|
||||||
@@ -151,20 +151,6 @@ func Test_deepCopyGlobal(t *testing.T) {
|
|||||||
},
|
},
|
||||||
wantErr: nil,
|
wantErr: nil,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
name: "deep copy 3",
|
|
||||||
global: &Global{
|
|
||||||
Downstream: &Downstream{},
|
|
||||||
AddXRealIpHeader: true,
|
|
||||||
DisableXEnvoyHeaders: true,
|
|
||||||
},
|
|
||||||
want: &Global{
|
|
||||||
Downstream: NewDefaultDownstream(),
|
|
||||||
AddXRealIpHeader: true,
|
|
||||||
DisableXEnvoyHeaders: true,
|
|
||||||
},
|
|
||||||
wantErr: nil,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
@@ -203,7 +189,10 @@ func Test_AddOrUpdateHigressConfig(t *testing.T) {
|
|||||||
old: NewDefaultHigressConfig(),
|
old: NewDefaultHigressConfig(),
|
||||||
new: &HigressConfig{
|
new: &HigressConfig{
|
||||||
Downstream: &Downstream{
|
Downstream: &Downstream{
|
||||||
IdleTimeout: 1,
|
IdleTimeout: 1,
|
||||||
|
MaxRequestHeadersKb: defaultMaxRequestHeadersKb,
|
||||||
|
ConnectionBufferLimits: defaultConnectionBufferLimits,
|
||||||
|
Http2: NewDefaultHttp2(),
|
||||||
},
|
},
|
||||||
AddXRealIpHeader: true,
|
AddXRealIpHeader: true,
|
||||||
DisableXEnvoyHeaders: true,
|
DisableXEnvoyHeaders: true,
|
||||||
|
|||||||
@@ -543,6 +543,83 @@ var ConfigMapGlobalEnvoy = suite.ConformanceTest{
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "close the setting of idle timeout",
|
||||||
|
higressConfig: &configmap.HigressConfig{
|
||||||
|
Downstream: &configmap.Downstream{
|
||||||
|
IdleTimeout: 0,
|
||||||
|
MaxRequestHeadersKb: 60,
|
||||||
|
ConnectionBufferLimits: 32768,
|
||||||
|
Http2: &configmap.Http2{
|
||||||
|
MaxConcurrentStreams: 100,
|
||||||
|
InitialStreamWindowSize: 65535,
|
||||||
|
InitialConnectionWindowSize: 1048576,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
DisableXEnvoyHeaders: true,
|
||||||
|
AddXRealIpHeader: true,
|
||||||
|
},
|
||||||
|
envoyAssertion: []envoy.Assertion{
|
||||||
|
{
|
||||||
|
Path: "configs.#.dynamic_route_configs.#.route_config",
|
||||||
|
CheckType: envoy.CheckTypeExist,
|
||||||
|
TargetNamespace: "higress-system",
|
||||||
|
ExpectEnvoyConfig: map[string]interface{}{
|
||||||
|
"request_headers_to_add": []interface{}{
|
||||||
|
map[string]interface{}{
|
||||||
|
"append": false,
|
||||||
|
"header": map[string]interface{}{
|
||||||
|
"key": "x-real-ip",
|
||||||
|
"value": "%REQ(X-ENVOY-EXTERNAL-ADDRESS)%",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Path: "configs.#.dynamic_listeners.#.active_state.listener.filter_chains.#.filters.#.typed_config",
|
||||||
|
CheckType: envoy.CheckTypeExist,
|
||||||
|
TargetNamespace: "higress-system",
|
||||||
|
ExpectEnvoyConfig: map[string]interface{}{
|
||||||
|
"@type": "type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager",
|
||||||
|
"stat_prefix": "outbound_0.0.0.0_80",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Path: "configs.#.dynamic_listeners.#.active_state.listener.filter_chains.#.filters.#.typed_config.http_filters",
|
||||||
|
CheckType: envoy.CheckTypeMatch,
|
||||||
|
TargetNamespace: "higress-system",
|
||||||
|
ExpectEnvoyConfig: map[string]interface{}{
|
||||||
|
"name": "envoy.filters.http.router",
|
||||||
|
"typed_config": map[string]interface{}{
|
||||||
|
"@type": "type.googleapis.com/envoy.extensions.filters.http.router.v3.Router",
|
||||||
|
"suppress_envoy_headers": true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Path: "configs.#.dynamic_listeners.#.active_state.listener",
|
||||||
|
CheckType: envoy.CheckTypeExist,
|
||||||
|
TargetNamespace: "higress-system",
|
||||||
|
ExpectEnvoyConfig: map[string]interface{}{
|
||||||
|
"per_connection_buffer_limit_bytes": 32768,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Path: "configs.#.dynamic_listeners.#.active_state.listener.filter_chains.#.filters.#.typed_config",
|
||||||
|
CheckType: envoy.CheckTypeExist,
|
||||||
|
TargetNamespace: "higress-system",
|
||||||
|
ExpectEnvoyConfig: map[string]interface{}{
|
||||||
|
"max_concurrent_streams": 100,
|
||||||
|
"initial_stream_window_size": 65535,
|
||||||
|
"initial_connection_window_size": 1048576,
|
||||||
|
"stream_idle_timeout": "0s",
|
||||||
|
"max_request_headers_kb": 60,
|
||||||
|
"idle_timeout": "0s",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Run("ConfigMap Global Envoy", func(t *testing.T) {
|
t.Run("ConfigMap Global Envoy", func(t *testing.T) {
|
||||||
|
|||||||
Reference in New Issue
Block a user