Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix timeout config overridden #190

Merged
merged 4 commits into from
Jun 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions configs/conf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,16 @@ static_resources:
clusters:
- name: "test_dubbo"
lb_policy: "RoundRobin"
connect_timeout: "5s"
request_timeout: "10s"
registries:
"zookeeper":
protocol: "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"
Expand Down
11 changes: 7 additions & 4 deletions pkg/client/dubbo/dubbo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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'")
Expand Down
5 changes: 3 additions & 2 deletions pkg/config/conf_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ static_resources:
clusters:
- name: "test_dubbo"
lb_policy: "RoundRobin"
connect_timeout: "5s"
request_timeout: "10s"
registries:
"zookeeper":
timeout: "3s"
Expand All @@ -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"
Expand Down
14 changes: 8 additions & 6 deletions pkg/config/config_load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -134,6 +132,10 @@ func TestMain(m *testing.M) {
},
},
},
TimeoutConfig: model.TimeoutConfig{
ConnectTimeoutStr: "5s",
RequestTimeoutStr: "10s",
},
ShutdownConfig: &model.ShutdownConfig{
Timeout: "60s",
StepTimeout: "10s",
Expand Down
7 changes: 7 additions & 0 deletions pkg/model/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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"`
}
20 changes: 9 additions & 11 deletions pkg/model/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions samples/admin/proxy/conf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ static_resources:
clusters:
- name: "test_dubbo"
lb_policy: "RoundRobin"
connect_timeout: "5s"
request_timeout: "10s"
registries:
"zookeeper":
timeout: "3s"
Expand All @@ -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"
Expand Down
5 changes: 3 additions & 2 deletions samples/dubbogo/http/pixiu/conf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ static_resources:
clusters:
- name: "test_dubbo"
lb_policy: "RoundRobin"
connect_timeout: "5s"
request_timeout: "10s"
registries:
"zookeeper":
protocol: "zookeeper"
Expand All @@ -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"
Expand Down
5 changes: 3 additions & 2 deletions samples/dubbogo/multi/config/conf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ static_resources:
clusters:
- name: "test_dubbo"
lb_policy: "RoundRobin"
connect_timeout: "5s"
request_timeout: "10s"
registries:
"zookeeper1":
protocol: "zookeeper"
Expand All @@ -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"
Expand Down
5 changes: 3 additions & 2 deletions samples/dubbogo/simple/body/conf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 3 additions & 2 deletions samples/dubbogo/simple/mix/conf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 3 additions & 2 deletions samples/dubbogo/simple/proxy/conf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 3 additions & 2 deletions samples/dubbogo/simple/query/conf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 3 additions & 2 deletions samples/dubbogo/simple/uri/conf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 3 additions & 2 deletions samples/plugins/config/conf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ static_resources:
clusters:
- name: "test_dubbo"
lb_policy: "RoundRobin"
connect_timeout: "5s"
request_timeout: "10s"
registries:
"zookeeper":
timeout: "3s"
Expand All @@ -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"
Expand Down