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:registry timeout not pars #1392

Merged
merged 5 commits into from
Aug 20, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
fix:registry timeout not pars
  • Loading branch information
zhaoyunxing92 committed Aug 19, 2021
commit b68a889387e7f14ae70e56427bb0552916a7bf58
10 changes: 10 additions & 0 deletions common/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"strconv"
"strings"
"sync"
"time"
)

import (
Expand Down Expand Up @@ -860,3 +861,12 @@ func SetCompareURLEqualFunc(f CompareURLEqualFunc) {
func GetCompareURLEqualFunc() CompareURLEqualFunc {
return compareURLEqualFunc
}

//GetParamDuration get duration if param is invalid or missing will return 3s
func (c *URL) GetParamDuration(s string, d string) time.Duration {

if t, err := time.ParseDuration(c.GetParam(s, d)); err == nil {
return t
}
return 3 * time.Second
}
9 changes: 3 additions & 6 deletions config/remote_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
import (
"dubbo.apache.org/dubbo-go/v3/common"
"dubbo.apache.org/dubbo-go/v3/common/constant"
"dubbo.apache.org/dubbo-go/v3/common/logger"
)

// RemoteConfig: usually we need some middleware, including nacos, zookeeper
Expand All @@ -45,8 +44,8 @@ type RemoteConfig struct {
Params map[string]string `yaml:"params" json:"params,omitempty"`
}

// Prefix
func (c *RemoteConfig) Prefix() string {
// Prefix dubbo.remote.
func (rc *RemoteConfig) Prefix() string {
return constant.RemotePrefix
}

Expand All @@ -56,8 +55,6 @@ func (rc *RemoteConfig) Timeout() time.Duration {
if res, err := time.ParseDuration(rc.TimeoutStr); err == nil {
return res
}
logger.Errorf("Could not parse the timeout string to Duration: %s, the default value will be returned",
rc.TimeoutStr)
return 5 * time.Second
}

Expand Down Expand Up @@ -90,7 +87,7 @@ func (rc *RemoteConfig) getUrlMap() url.Values {
urlMap := url.Values{}
urlMap.Set(constant.CONFIG_USERNAME_KEY, rc.Username)
urlMap.Set(constant.CONFIG_PASSWORD_KEY, rc.Password)
urlMap.Set(constant.CONFIG_TIMEOUT_KEY, rc.TimeoutStr)
urlMap.Set(constant.REGISTRY_TIMEOUT_KEY, rc.TimeoutStr)

for key, val := range rc.Params {
urlMap.Set(key, val)
Expand Down
3 changes: 1 addition & 2 deletions metadata/report/etcd/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ package etcd
import (
"encoding/json"
"strings"
"time"
)

import (
Expand Down Expand Up @@ -146,7 +145,7 @@ type etcdMetadataReportFactory struct{}

// CreateMetadataReport get the MetadataReport instance of etcd
func (e *etcdMetadataReportFactory) CreateMetadataReport(url *common.URL) report.MetadataReport {
timeout, _ := time.ParseDuration(url.GetParam(constant.REGISTRY_TIMEOUT_KEY, constant.DEFAULT_REG_TIMEOUT))
timeout := url.GetParamDuration(constant.REGISTRY_TIMEOUT_KEY, constant.DEFAULT_REG_TIMEOUT)
addresses := strings.Split(url.Location, ",")
client, err := gxetcd.NewClient(gxetcd.MetadataETCDV3Client, addresses, timeout, 1)
if err != nil {
Expand Down
8 changes: 1 addition & 7 deletions registry/etcdv3/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"path"
"strings"
"sync"
"time"
)

import (
Expand Down Expand Up @@ -75,12 +74,7 @@ func (r *etcdV3Registry) ClientLock() *sync.Mutex {
}

func newETCDV3Registry(url *common.URL) (registry.Registry, error) {
timeout, err := time.ParseDuration(url.GetParam(constant.REGISTRY_TIMEOUT_KEY, constant.DEFAULT_REG_TIMEOUT))
if err != nil {
logger.Errorf("timeout config %v is invalid ,err is %v",
url.GetParam(constant.REGISTRY_TIMEOUT_KEY, constant.DEFAULT_REG_TIMEOUT), err.Error())
return nil, perrors.WithMessagef(err, "new etcd registry(address:%+v)", url.Location)
}
timeout := url.GetParamDuration(constant.REGISTRY_TIMEOUT_KEY, constant.DEFAULT_REG_TIMEOUT)

logger.Infof("etcd address is: %v, timeout is: %s", url.Location, timeout.String())

Expand Down
5 changes: 1 addition & 4 deletions remoting/nacos/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,7 @@ func GetNacosConfig(url *common.URL) ([]nacosConstant.ServerConfig, nacosConstan
serverConfigs = append(serverConfigs, nacosConstant.ServerConfig{IpAddr: ip, Port: uint64(port)})
}

timeout, err := time.ParseDuration(url.GetParam(constant.REGISTRY_TIMEOUT_KEY, constant.DEFAULT_REG_TIMEOUT))
if err != nil {
return []nacosConstant.ServerConfig{}, nacosConstant.ClientConfig{}, err
}
timeout := url.GetParamDuration(constant.REGISTRY_TIMEOUT_KEY, constant.DEFAULT_REG_TIMEOUT)

clientConfig := nacosConstant.ClientConfig{
TimeoutMs: uint64(int32(timeout / time.Millisecond)),
Expand Down
9 changes: 2 additions & 7 deletions remoting/zookeeper/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package zookeeper

import (
"strings"
"time"
)

import (
Expand Down Expand Up @@ -55,12 +54,8 @@ func ValidateZookeeperClient(container ZkClientFacade, zkName string) error {

if container.ZkClient() == nil {
// in dubbo, every registry only connect one node, so this is []string{r.Address}
timeout, paramErr := time.ParseDuration(url.GetParam(constant.REGISTRY_TIMEOUT_KEY, constant.DEFAULT_REG_TIMEOUT))
if paramErr != nil {
logger.Errorf("timeout config %v is invalid, err is %v",
url.GetParam(constant.REGISTRY_TIMEOUT_KEY, constant.DEFAULT_REG_TIMEOUT), paramErr.Error())
return perrors.WithMessagef(paramErr, "newZookeeperClient(address:%+v)", url.Location)
}
timeout := url.GetParamDuration(constant.REGISTRY_TIMEOUT_KEY, constant.DEFAULT_REG_TIMEOUT)

zkAddresses := strings.Split(url.Location, ",")
newClient, cltErr := gxzookeeper.NewZookeeperClient(zkName, zkAddresses, true, gxzookeeper.WithZkTimeOut(timeout))
if cltErr != nil {
Expand Down