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

Feature/polaris feat: Add Polaris support #1797

Merged
merged 79 commits into from
May 18, 2022
Merged

Conversation

houseme
Copy link
Member

@houseme houseme commented May 3, 2022

Add Polaris service

#1504

#1826

polarismesh/polaris#163

@codecov-commenter
Copy link

codecov-commenter commented May 3, 2022

Codecov Report

Merging #1797 (fc77c0d) into master (3a014dc) will decrease coverage by 0.21%.
The diff coverage is 63.69%.

❗ Current head fc77c0d differs from pull request most recent head dc6dc31. Consider uploading reports for the commit dc6dc31 to get more accurate results

@@            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     
Flag Coverage Δ
go-1.15 ?
go-1.15-386 73.20% <63.69%> (?)
go-1.15-amd64 73.15% <63.69%> (?)
go-1.16 ?
go-1.16-386 73.22% <63.69%> (?)
go-1.16-amd64 73.21% <63.69%> (?)
go-1.17 ?
go-1.17-386 73.21% <63.69%> (?)
go-1.17-amd64 73.20% <63.69%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
net/gclient/gclient_config.go 39.13% <0.00%> (ø)
net/gclient/gclient_tracing.go 44.00% <ø> (ø)
net/gclient/gclient_tracing_tracer.go 0.00% <ø> (ø)
net/ghttp/ghttp_func.go 62.50% <ø> (ø)
net/ghttp/ghttp_server_graceful.go 60.73% <ø> (ø)
net/ghttp/ghttp_server_handler.go 62.85% <ø> (ø)
net/ghttp/ghttp_server_registry.go 8.51% <0.00%> (ø)
net/gsvc/gsvc.go 33.33% <ø> (ø)
net/gsvc/gsvc_discovery.go 0.00% <0.00%> (ø)
net/gsvc/gsvc_registry.go 0.00% <0.00%> (ø)
... and 35 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3a014dc...dc6dc31. Read the comment docs.

@houseme houseme changed the title Feature/polaris feat: Add Polaris service Feature/polaris feat: Add Polaris service [Do not merge] May 4, 2022
@houseme houseme requested a review from gqcn May 12, 2022 15:21
@gqcn gqcn changed the title Feature/polaris feat: Add Polaris service [Do not merge] Feature/polaris feat: Add Polaris support May 13, 2022
@@ -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)},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Endpoints的格式统一采用ip:port的格式,至于使用端如何使用,按照此格式解析。不要随便修改这个格式。

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

net/gsvc/gsvc_search.go Show resolved Hide resolved
net/gsvc/gsvc_service.go Show resolved Hide resolved
// Separator is the default defaultSeparator for path.
func Separator() string {
return defaultSeparator
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果defaultSeparator需要被外部访问,定义为公开常量即可,不用再定义个方法来暴露。

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

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)
Copy link
Member

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)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

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)
Copy link
Member

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)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -19,47 +19,60 @@ import (
)

const (
separator = "/"
defaultSeparator = "/"
delimiter = ","
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

没有必要单独定义一个常量。如果你实在是想要定义,可以定义为endpointDelimiter

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

)

var (
_ gsvc.Registrar = &Registry{}
Copy link
Member

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实现。

Copy link
Member Author

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 Show resolved Hide resolved
)

// _instanceIDSeparator Instance id Separator.
const _instanceIDSeparator = "-"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

能否不要使用_开头的名称定义。

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@houseme houseme requested a review from gqcn May 13, 2022 11:38
}

// NewRegistry create a new registry.
func NewRegistry(provider polaris.ProviderAPI, consumer polaris.ConsumerAPI, opts ...Option) (r *Registry) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NewRegistry -> New

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}

// NewRegistryWithConfig new a registry with config.
func NewRegistryWithConfig(conf config.Configuration, opts ...Option) (r *Registry) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NewRegistryWithConfig -> NewWithConfig

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


// 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://", ""})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不用做替换,使用默认的endpoint约定,即host:port格式。
这个格式倒是可以在gsvc那边服务注册的时候加个校验,而不是在所有使用的地方再去校验。

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个 那我去修改一下_test.go文件

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

// 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)
Copy link
Member

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

Copy link
Member Author

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 Show resolved Hide resolved
net/gsvc/gsvc_service.go Outdated Show resolved Hide resolved
net/gsvc/gsvc_service.go Outdated Show resolved Hide resolved
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)
Copy link
Member

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)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个地方是和默认的不相同,在最前面不添加分隔符。

Copy link
Member Author

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_registry.go Outdated Show resolved Hide resolved
@houseme houseme requested a review from gqcn May 16, 2022 12:53
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")
Copy link
Member

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引起的报错。

Copy link
Member Author

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 Show resolved Hide resolved
@houseme houseme requested a review from gqcn May 16, 2022 14:12

if r.opt.Heartbeat {
// start heartbeat report
go func() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是不是需要进行控制下这个协程?反注册的话走context.Cancel进行取消

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@gqcn gqcn added the ready to merge Used in PR, which means this PR is reviewed. label May 17, 2022
@gqcn gqcn merged commit ab82599 into gogf:master May 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready to merge Used in PR, which means this PR is reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants