From 73949d394041c1b9e45378bf3690ced64055adf2 Mon Sep 17 00:00:00 2001 From: alchemy-lee <2769566951@qq.com> Date: Tue, 22 Jun 2021 22:25:39 +0800 Subject: [PATCH] move timeout config outside the clusters (#190) --- configs/conf.yaml | 5 +++-- pkg/client/dubbo/dubbo.go | 11 +++++++---- pkg/config/conf_test.yaml | 5 +++-- pkg/config/config_load_test.go | 14 ++++++++------ pkg/model/bootstrap.go | 7 +++++++ pkg/model/cluster.go | 20 +++++++++----------- samples/admin/proxy/conf.yaml | 5 +++-- samples/dubbogo/http/pixiu/conf.yaml | 5 +++-- samples/dubbogo/multi/config/conf.yaml | 5 +++-- samples/dubbogo/simple/body/conf.yaml | 5 +++-- samples/dubbogo/simple/mix/conf.yaml | 5 +++-- samples/dubbogo/simple/proxy/conf.yaml | 5 +++-- samples/dubbogo/simple/query/conf.yaml | 5 +++-- samples/dubbogo/simple/uri/conf.yaml | 5 +++-- samples/plugins/config/conf.yaml | 5 +++-- 15 files changed, 64 insertions(+), 43 deletions(-) diff --git a/configs/conf.yaml b/configs/conf.yaml index 3ef86e8ba..0bd99f210 100644 --- a/configs/conf.yaml +++ b/configs/conf.yaml @@ -75,8 +75,6 @@ static_resources: clusters: - name: "test_dubbo" lb_policy: "RoundRobin" - connect_timeout: "5s" - request_timeout: "10s" registries: "zookeeper": protocol: "zookeeper" @@ -84,6 +82,9 @@ static_resources: address: "127.0.0.1:2181" username: "" password: "" + timeout_config: + connect_timeout: "5s" + request_timeout: "10s" shutdown_config: timeout: "60s" step_timeout: "10s" diff --git a/pkg/client/dubbo/dubbo.go b/pkg/client/dubbo/dubbo.go index 0c828ebf8..9e5454e36 100644 --- a/pkg/client/dubbo/dubbo.go +++ b/pkg/client/dubbo/dubbo.go @@ -89,18 +89,21 @@ func NewDubboClient() *Client { // Init init dubbo, config mapping can do here func (dc *Client) Init() error { - cls := config.GetBootstrap().StaticResources.Clusters + staticResources := config.GetBootstrap().StaticResources + cls := staticResources.Clusters + tc := staticResources.TimeoutConfig - // dubbogo comsumer config + // dubbogo consumer config dgCfg = dg.ConsumerConfig{ Check: new(bool), Registries: make(map[string]*dg.RegistryConfig, 4), } + // timeout config + dgCfg.Connect_Timeout = tc.ConnectTimeoutStr + dgCfg.Request_Timeout = tc.RequestTimeoutStr dgCfg.ApplicationConfig = defaultApplication for i := range cls { c := cls[i] - dgCfg.Request_Timeout = c.RequestTimeoutStr - dgCfg.Connect_Timeout = c.ConnectTimeoutStr for k, v := range c.Registries { if len(v.Protocol) == 0 { logger.Warnf("can not find registry protocol config, use default type 'zookeeper'") diff --git a/pkg/config/conf_test.yaml b/pkg/config/conf_test.yaml index c79be624f..889a92275 100644 --- a/pkg/config/conf_test.yaml +++ b/pkg/config/conf_test.yaml @@ -63,8 +63,6 @@ static_resources: clusters: - name: "test_dubbo" lb_policy: "RoundRobin" - connect_timeout: "5s" - request_timeout: "10s" registries: "zookeeper": timeout: "3s" @@ -74,6 +72,9 @@ static_resources: "consul": timeout: "3s" address: "127.0.0.1:8500" + timeout_config: + connect_timeout: "5s" + request_timeout: "10s" shutdown_config: timeout: "60s" step_timeout: "10s" diff --git a/pkg/config/config_load_test.go b/pkg/config/config_load_test.go index 375ef92be..d589cd5f6 100644 --- a/pkg/config/config_load_test.go +++ b/pkg/config/config_load_test.go @@ -114,12 +114,10 @@ func TestMain(m *testing.M) { }, Clusters: []*model.Cluster{ { - Name: "test_dubbo", - TypeStr: "EDS", - Type: model.EDS, - LbStr: "RoundRobin", - ConnectTimeoutStr: "5s", - RequestTimeoutStr: "10s", + Name: "test_dubbo", + TypeStr: "EDS", + Type: model.EDS, + LbStr: "RoundRobin", Registries: map[string]model.Registry{ "zookeeper": { Timeout: "3s", @@ -134,6 +132,10 @@ func TestMain(m *testing.M) { }, }, }, + TimeoutConfig: model.TimeoutConfig{ + ConnectTimeoutStr: "5s", + RequestTimeoutStr: "10s", + }, ShutdownConfig: &model.ShutdownConfig{ Timeout: "60s", StepTimeout: "10s", diff --git a/pkg/model/bootstrap.go b/pkg/model/bootstrap.go index 1c99c3d07..c5d491f94 100644 --- a/pkg/model/bootstrap.go +++ b/pkg/model/bootstrap.go @@ -56,6 +56,7 @@ func (bs *Bootstrap) ExistCluster(name string) bool { type StaticResources struct { Listeners []Listener `yaml:"listeners" json:"listeners" mapstructure:"listeners"` Clusters []*Cluster `yaml:"clusters" json:"clusters" mapstructure:"clusters"` + TimeoutConfig TimeoutConfig `yaml:"timeout_config" json:"timeout_config" mapstructure:"timeout_config"` ShutdownConfig *ShutdownConfig `yaml:"shutdown_config" json:"shutdown_config" mapstructure:"shutdown_config"` PprofConf PprofConf `yaml:"pprofConf" json:"pprofConf" mapstructure:"pprofConf"` AccessLogConfig AccessLogConfig `yaml:"accessLog" json:"accessLog" mapstructure:"accessLog"` @@ -77,3 +78,9 @@ type APIMetaConfig struct { Address string `yaml:"address" json:"address,omitempty"` APIConfigPath string `default:"/pixiu/config/api" yaml:"api_config_path" json:"api_config_path,omitempty" mapstructure:"api_config_path"` } + +// TimeoutConfig the config of ConnectTimeout and RequestTimeout +type TimeoutConfig struct { + ConnectTimeoutStr string `yaml:"connect_timeout" json:"connect_timeout,omitempty"` // ConnectTimeout timeout for connect to cluster node + RequestTimeoutStr string `yaml:"request_timeout" json:"request_timeout,omitempty"` +} diff --git a/pkg/model/cluster.go b/pkg/model/cluster.go index ee53b6f5b..0877fd2d8 100644 --- a/pkg/model/cluster.go +++ b/pkg/model/cluster.go @@ -19,17 +19,15 @@ package model // Cluster a single upstream cluster type Cluster struct { - Name string `yaml:"name" json:"name"` // Name the cluster unique name - TypeStr string `yaml:"type" json:"type"` // Type the cluster discovery type string value - Type DiscoveryType `yaml:",omitempty" json:",omitempty"` // Type the cluster discovery type - EdsClusterConfig EdsClusterConfig `yaml:"eds_cluster_config" json:"eds_cluster_config" mapstructure:"eds_cluster_config"` - LbStr string `yaml:"lb_policy" json:"lb_policy"` // Lb the cluster select node used loadBalance policy - Lb LbPolicy `yaml:",omitempty" json:",omitempty"` // Lb the cluster select node used loadBalance policy - ConnectTimeoutStr string `yaml:"connect_timeout" json:"connect_timeout"` // ConnectTimeout timeout for connect to cluster node - HealthChecks []HealthCheck `yaml:"health_checks" json:"health_checks"` - Hosts []Address `yaml:"hosts" json:"hosts"` // Hosts whe discovery type is Static, StrictDNS or LogicalDns, this need config - RequestTimeoutStr string `yaml:"request_timeout" json:"request_timeout"` - Registries map[string]Registry `yaml:"registries" json:"registries"` + Name string `yaml:"name" json:"name"` // Name the cluster unique name + TypeStr string `yaml:"type" json:"type"` // Type the cluster discovery type string value + Type DiscoveryType `yaml:",omitempty" json:",omitempty"` // Type the cluster discovery type + EdsClusterConfig EdsClusterConfig `yaml:"eds_cluster_config" json:"eds_cluster_config" mapstructure:"eds_cluster_config"` + LbStr string `yaml:"lb_policy" json:"lb_policy"` // Lb the cluster select node used loadBalance policy + Lb LbPolicy `yaml:",omitempty" json:",omitempty"` // Lb the cluster select node used loadBalance policy + HealthChecks []HealthCheck `yaml:"health_checks" json:"health_checks"` + Hosts []Address `yaml:"hosts" json:"hosts"` // Hosts whe discovery type is Static, StrictDNS or LogicalDns, this need config + Registries map[string]Registry `yaml:"registries" json:"registries"` } // DiscoveryType diff --git a/samples/admin/proxy/conf.yaml b/samples/admin/proxy/conf.yaml index b18a5e09b..2f6736a4d 100644 --- a/samples/admin/proxy/conf.yaml +++ b/samples/admin/proxy/conf.yaml @@ -64,8 +64,6 @@ static_resources: clusters: - name: "test_dubbo" lb_policy: "RoundRobin" - connect_timeout: "5s" - request_timeout: "10s" registries: "zookeeper": timeout: "3s" @@ -75,6 +73,9 @@ static_resources: # "consul": # timeout: "3s" # address: "127.0.0.1:8500" + timeout_config: + connect_timeout: "5s" + request_timeout: "10s" shutdown_config: timeout: "60s" step_timeout: "10s" diff --git a/samples/dubbogo/http/pixiu/conf.yaml b/samples/dubbogo/http/pixiu/conf.yaml index 6f353a8d2..95f623166 100644 --- a/samples/dubbogo/http/pixiu/conf.yaml +++ b/samples/dubbogo/http/pixiu/conf.yaml @@ -32,8 +32,6 @@ static_resources: clusters: - name: "test_dubbo" lb_policy: "RoundRobin" - connect_timeout: "5s" - request_timeout: "10s" registries: "zookeeper": protocol: "zookeeper" @@ -44,6 +42,9 @@ static_resources: # "consul": # timeout: "3s" # address: "127.0.0.1:8500" + timeout_config: + connect_timeout: "5s" + request_timeout: "10s" shutdown_config: timeout: "60s" step_timeout: "10s" diff --git a/samples/dubbogo/multi/config/conf.yaml b/samples/dubbogo/multi/config/conf.yaml index 5691e9880..07fe310cf 100644 --- a/samples/dubbogo/multi/config/conf.yaml +++ b/samples/dubbogo/multi/config/conf.yaml @@ -63,8 +63,6 @@ static_resources: clusters: - name: "test_dubbo" lb_policy: "RoundRobin" - connect_timeout: "5s" - request_timeout: "10s" registries: "zookeeper1": protocol: "zookeeper" @@ -74,6 +72,9 @@ static_resources: protocol: "zookeeper" timeout: "3s" address: "127.0.0.1:2182" + timeout_config: + connect_timeout: "5s" + request_timeout: "10s" shutdown_config: timeout: "60s" step_timeout: "10s" diff --git a/samples/dubbogo/simple/body/conf.yaml b/samples/dubbogo/simple/body/conf.yaml index beb8e64b4..6e65bf500 100644 --- a/samples/dubbogo/simple/body/conf.yaml +++ b/samples/dubbogo/simple/body/conf.yaml @@ -32,14 +32,15 @@ static_resources: clusters: - name: "test_dubbo" lb_policy: "RoundRobin" - connect_timeout: "5s" - request_timeout: "10s" registries: "zookeeper": timeout: "3s" address: "127.0.0.1:2181" username: "" password: "" + timeout_config: + connect_timeout: "5s" + request_timeout: "10s" shutdown_config: timeout: "60s" step_timeout: "10s" diff --git a/samples/dubbogo/simple/mix/conf.yaml b/samples/dubbogo/simple/mix/conf.yaml index 7f98a7828..0d61e23f5 100644 --- a/samples/dubbogo/simple/mix/conf.yaml +++ b/samples/dubbogo/simple/mix/conf.yaml @@ -32,14 +32,15 @@ static_resources: clusters: - name: "test_dubbo" lb_policy: "RoundRobin" - connect_timeout: "5s" - request_timeout: "10s" registries: "zookeeper": timeout: "3s" address: "127.0.0.1:2181" username: "" password: "" + timeout_config: + connect_timeout: "5s" + request_timeout: "10s" shutdown_config: timeout: "60s" step_timeout: "10s" diff --git a/samples/dubbogo/simple/proxy/conf.yaml b/samples/dubbogo/simple/proxy/conf.yaml index 010769f8b..44e197491 100644 --- a/samples/dubbogo/simple/proxy/conf.yaml +++ b/samples/dubbogo/simple/proxy/conf.yaml @@ -32,14 +32,15 @@ static_resources: clusters: - name: "test_dubbo" lb_policy: "RoundRobin" - connect_timeout: "5s" - request_timeout: "10s" registries: "zookeeper": timeout: "3s" address: "127.0.0.1:2181" username: "" password: "" + timeout_config: + connect_timeout: "5s" + request_timeout: "10s" shutdown_config: timeout: "60s" step_timeout: "10s" diff --git a/samples/dubbogo/simple/query/conf.yaml b/samples/dubbogo/simple/query/conf.yaml index 663174495..6c35f16fa 100644 --- a/samples/dubbogo/simple/query/conf.yaml +++ b/samples/dubbogo/simple/query/conf.yaml @@ -32,14 +32,15 @@ static_resources: clusters: - name: "test_dubbo" lb_policy: "RoundRobin" - connect_timeout: "5s" - request_timeout: "10s" registries: "zookeeper": timeout: "3s" address: "127.0.0.1:2181" username: "" password: "" + timeout_config: + connect_timeout: "5s" + request_timeout: "10s" shutdown_config: timeout: "60s" step_timeout: "10s" diff --git a/samples/dubbogo/simple/uri/conf.yaml b/samples/dubbogo/simple/uri/conf.yaml index 2067be47a..af60e205d 100644 --- a/samples/dubbogo/simple/uri/conf.yaml +++ b/samples/dubbogo/simple/uri/conf.yaml @@ -32,14 +32,15 @@ static_resources: clusters: - name: "test_dubbo" lb_policy: "RoundRobin" - connect_timeout: "5s" - request_timeout: "10s" registries: "zookeeper": timeout: "3s" address: "127.0.0.1:2181" username: "" password: "" + timeout_config: + connect_timeout: "5s" + request_timeout: "10s" shutdown_config: timeout: "60s" step_timeout: "10s" diff --git a/samples/plugins/config/conf.yaml b/samples/plugins/config/conf.yaml index bde9d5fc6..c966192ed 100644 --- a/samples/plugins/config/conf.yaml +++ b/samples/plugins/config/conf.yaml @@ -32,8 +32,6 @@ static_resources: clusters: - name: "test_dubbo" lb_policy: "RoundRobin" - connect_timeout: "5s" - request_timeout: "10s" registries: "zookeeper": timeout: "3s" @@ -43,6 +41,9 @@ static_resources: # "consul": # timeout: "3s" # address: "127.0.0.1:8500" + timeout_config: + connect_timeout: "5s" + request_timeout: "10s" shutdown_config: timeout: "60s" step_timeout: "10s"