-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Feature/polaris feat: Add Polaris support #1797
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1797 +/- ##
==========================================
- Coverage 73.46% 73.25% -0.22%
==========================================
Files 495 503 +8
Lines 44328 45392 +1064
==========================================
+ Hits 32566 33252 +686
- Misses 9801 10115 +314
- Partials 1961 2025 +64
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
net/ghttp/ghttp_server_registry.go
Outdated
@@ -47,7 +47,7 @@ func (s *Server) doServiceRegister() { | |||
} | |||
s.service = &gsvc.Service{ | |||
Name: s.GetName(), | |||
Endpoints: []string{fmt.Sprintf(`%s:%s`, ip, port)}, | |||
Endpoints: []string{fmt.Sprintf(`%s://%s:%s`, protocol, ip, port)}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Endpoints
的格式统一采用ip:port
的格式,至于使用端如何使用,按照此格式解析。不要随便修改这个格式。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
net/gsvc/gsvc_service.go
Outdated
// Separator is the default defaultSeparator for path. | ||
func Separator() string { | ||
return defaultSeparator | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果defaultSeparator
需要被外部访问,定义为公开常量即可,不用再定义个方法来暴露。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
net/gsvc/gsvc_service.go
Outdated
if s.Separator != defaultSeparator { | ||
return gstr.Join([]string{s.Prefix, s.Deployment, s.Namespace, s.Name, s.Version}, s.Separator) | ||
} | ||
return s.Separator + gstr.Join([]string{s.Prefix, s.Deployment, s.Namespace, s.Name, s.Version}, s.Separator) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
请参考如下:
var separator = defaultSeparator
if s.Separator != "" {
separator = s.Separator
}
return separator + gstr.Join([]string{s.Prefix, s.Deployment, s.Namespace, s.Name, s.Version}, separator)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
net/gsvc/gsvc_service.go
Outdated
if s.Separator != defaultSeparator { | ||
return gstr.Join([]string{s.Prefix, s.Deployment, s.Namespace, s.Name, s.Version}, s.Separator) | ||
} | ||
return s.Separator + gstr.Join([]string{s.Prefix, s.Deployment, s.Namespace, s.Name, s.Version}, s.Separator) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
请参考如下:
var separator = defaultSeparator
if s.Separator != "" {
separator = s.Separator
}
return separator + gstr.Join([]string{s.Prefix, s.Deployment, s.Namespace, s.Name, s.Version}, separator)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
net/gsvc/gsvc_service.go
Outdated
@@ -19,47 +19,60 @@ import ( | |||
) | |||
|
|||
const ( | |||
separator = "/" | |||
defaultSeparator = "/" | |||
delimiter = "," |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
没有必要单独定义一个常量。如果你实在是想要定义,可以定义为endpointDelimiter
。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
contrib/registry/polaris/polaris.go
Outdated
) | ||
|
||
var ( | ||
_ gsvc.Registrar = &Registry{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里应该是_ gsvc.Registry = &Registry{}
,该断言保障Registry
对象能同时实现注册和发现两个特性,参考下etcd
实现。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
contrib/registry/polaris/polaris.go
Outdated
) | ||
|
||
// _instanceIDSeparator Instance id Separator. | ||
const _instanceIDSeparator = "-" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
能否不要使用_
开头的名称定义。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
# Conflicts: # example/go.sum # go.sum
contrib/registry/polaris/polaris.go
Outdated
} | ||
|
||
// NewRegistry create a new registry. | ||
func NewRegistry(provider polaris.ProviderAPI, consumer polaris.ConsumerAPI, opts ...Option) (r *Registry) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NewRegistry -> New
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
contrib/registry/polaris/polaris.go
Outdated
} | ||
|
||
// NewRegistryWithConfig new a registry with config. | ||
func NewRegistryWithConfig(conf config.Configuration, opts ...Option) (r *Registry) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NewRegistryWithConfig -> NewWithConfig
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
contrib/registry/polaris/polaris.go
Outdated
|
||
// getHostAndPortFromEndpoint get host and port from endpoint. | ||
func getHostAndPortFromEndpoint(ctx context.Context, endpoint string) (host string, port int, err error) { | ||
endpoint = gstr.ReplaceByArray(endpoint, []string{"tcp://", "", "udp://", "", "http://", "", "https://", "", "ws://", "", "wss://", ""}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不用做替换,使用默认的endpoint
约定,即host:port
格式。
这个格式倒是可以在gsvc
那边服务注册的时候加个校验,而不是在所有使用的地方再去校验。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个 那我去修改一下_test.go文件
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
contrib/registry/polaris/polaris.go
Outdated
// getHostAndPortFromEndpoint get host and port from endpoint. | ||
func getHostAndPortFromEndpoint(ctx context.Context, endpoint string) (host string, port int, err error) { | ||
endpoint = gstr.ReplaceByArray(endpoint, []string{"tcp://", "", "udp://", "", "http://", "", "https://", "", "ws://", "", "wss://", ""}) | ||
httpArr := gstr.Split(endpoint, endpointDelimiter) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 为什么用
httpArr
,这是HTTP
地址吗? gstr.Split -> gstr.SplitAndTrim
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
net/gsvc/gsvc_service.go
Outdated
if s.Separator != DefaultSeparator { | ||
return gstr.Join([]string{s.Prefix, s.Deployment, s.Namespace, s.Name, s.Version}, defaultSeparator) | ||
} | ||
return defaultSeparator + gstr.Join([]string{s.Prefix, s.Deployment, s.Namespace, s.Name, s.Version}, defaultSeparator) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这段代码重复率标高,请参考如下:
var separator = defaultSeparator
if s.Separator != "" {
separator = s.Separator
}
return separator + gstr.Join([]string{s.Prefix, s.Deployment, s.Namespace, s.Name, s.Version}, separator)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个地方是和默认的不相同,在最前面不添加分隔符。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
contrib/registry/polaris/polaris.go
Outdated
func getHostAndPortFromEndpoint(ctx context.Context, endpoint string) (host string, port int, err error) { | ||
endpoints := gstr.SplitAndTrim(endpoint, endpointDelimiter) | ||
if len(endpoints) < 2 { | ||
err = gerror.New("invalid endpoint") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
err = gerror.Newf(`invalid endpoint "%s"`, endpoint)
就一个invalid endpoint
不足以反馈问题,报错的时候调用端不知道是什么endpoint
引起的报错。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
|
||
if r.opt.Heartbeat { | ||
// start heartbeat report | ||
go func() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
是不是需要进行控制下这个协程?反注册的话走context.Cancel进行取消
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Add Polaris service
#1504
#1826
polarismesh/polaris#163