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

feat(config): add root config api builder #1491

Merged
merged 7 commits into from
Oct 2, 2021

Conversation

Mulavar
Copy link
Member

@Mulavar Mulavar commented Sep 27, 2021

What this PR does:

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?:


@@ -113,3 +113,49 @@ func WithMetadataType(metadataType string) ApplicationConfigOpt {
ac.MetadataType = metadataType
}
}

type ApplicationConfigBuilder struct {
*ApplicationConfig
Copy link
Contributor

Choose a reason for hiding this comment

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

config *ApplicationConfig

@codecov-commenter
Copy link

codecov-commenter commented Sep 27, 2021

Codecov Report

Merging #1491 (c5dfcd2) into config-api (c164f38) will decrease coverage by 0.54%.
The diff coverage is 11.42%.

❗ Current head c5dfcd2 differs from pull request most recent head 59ee8ea. Consider uploading reports for the commit 59ee8ea to get more accurate results
Impacted file tree graph

@@              Coverage Diff               @@
##           config-api    #1491      +/-   ##
==============================================
- Coverage       42.71%   42.17%   -0.55%     
==============================================
  Files             261      261              
  Lines           14957    15113     +156     
==============================================
- Hits             6389     6374      -15     
- Misses           7819     7994     +175     
+ Partials          749      745       -4     
Impacted Files Coverage Δ
config/application_config.go 10.76% <0.00%> (-7.66%) ⬇️
config/config_loader.go 22.22% <0.00%> (ø)
config/metadata_report_config.go 28.00% <0.00%> (ø)
config/root_config.go 6.14% <0.00%> (-4.47%) ⬇️
config/service_config.go 8.92% <ø> (ø)
config/service_discovery_config.go 0.00% <0.00%> (-50.00%) ⬇️
config/registry_config.go 20.34% <1.81%> (-11.66%) ⬇️
config/protocol_config.go 8.33% <5.26%> (-26.56%) ⬇️
config/dubbo_bootstrap.go 64.06% <73.33%> (+7.19%) ⬆️
... and 2 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 c164f38...59ee8ea. Read the comment docs.

application *ApplicationConfig
}

func (acb *ApplicationConfigBuilder) Organization(organization string) *ApplicationConfigBuilder {
Copy link
Contributor

Choose a reason for hiding this comment

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

赋值函数为啥不在前面加上 Set?

Copy link
Member Author

Choose a reason for hiding this comment

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

一般这种builder模式的运用,在链式赋值时都不会使用set。
我理解是因为这种模式下没有 get 的场景,所以单独的 set 并不会给到更多的语义信息,可忽略。

Copy link
Member Author

Choose a reason for hiding this comment

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

可参考 curator,okhttp3 等框架。

Copy link
Member

Choose a reason for hiding this comment

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

感觉写成了 java。。。。。。。。。。。go 不是用以下形式吗?

&ApplicationConfigBuilder{
key1:value1,
key2:value2,
}

rootConfig *RootConfig
}

func (rb *RootConfigBuilder) Application(application *ApplicationConfig) *RootConfigBuilder {
Copy link
Contributor

Choose a reason for hiding this comment

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

加上 Set 前缀

application *ApplicationConfig
}

func (acb *ApplicationConfigBuilder) Organization(organization string) *ApplicationConfigBuilder {
Copy link
Member

Choose a reason for hiding this comment

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

感觉写成了 java。。。。。。。。。。。go 不是用以下形式吗?

&ApplicationConfigBuilder{
key1:value1,
key2:value2,
}

@@ -188,19 +188,19 @@ func RPCService(service common.RPCService) {
// So you don't need to worry about the race condition
func GetMetricConfig() *MetricConfig {
// todo
//if GetBaseConfig().MetricConfig == nil {
//if GetBaseConfig().Metric == nil {
Copy link
Member

Choose a reason for hiding this comment

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

todo 要不干掉?

Copy link
Member Author

Choose a reason for hiding this comment

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

解释一下上面的问题,
&ApplicationConfigBuilder{
key1:value1,
key2:value2,
}
是一种初始化方式,这个builder是另一个问题,是前段时间讨论后针对目前with的config api一个替换做法,我个人理解builder不算是java专有的吧,这个模式go里面也有用,但是java比较普遍,我们也是讨论了觉得这种方式可读性比with更强所以借鉴这种写法。

return &ProtocolConfigBuilder{protocolConfig: &ProtocolConfig{}}
}

type ProtocolConfigBuilder struct {
Copy link
Member

Choose a reason for hiding this comment

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

这里也是。。。感觉写成了 java

@@ -284,3 +272,98 @@ func WithRegistryParams(params map[string]string) RegistryConfigOpt {
return config
}
}

func NewRegistryConfigBuilder() *RegistryConfigBuilder {
Copy link
Member

Choose a reason for hiding this comment

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

这里也是 java

return &RootConfigBuilder{rootConfig: &RootConfig{}}
}

type RootConfigBuilder struct {
Copy link
Member

Choose a reason for hiding this comment

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

这里也是 java

return nil
}

func NewServiceDiscoveryConfigBuilder() *ServiceDiscoveryConfigBuilder {
Copy link
Member

Choose a reason for hiding this comment

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

这里也 java

@XiaoWeiKIN
Copy link
Contributor

hi,boy。关于dubboBootstrap 和configLoader我有一点疑问,dubboBootstrap 顾名思义是作为程序的引导类,一般来说引导类只有一个,但是似乎configLoader也是做引导程序使用的,这两个是单独对程序进行加载和启动吗?另外假设我使用api配置和外部化配置混用应该如何使用配置? @Mulavar

@Mulavar
Copy link
Member Author

Mulavar commented Oct 1, 2021

hi,boy。关于dubboBootstrap 和configLoader我有一点疑问,dubboBootstrap 顾名思义是作为程序的引导类,一般来说引导类只有一个,但是似乎configLoader也是做引导程序使用的,这两个是单独对程序进行加载和启动吗?另外假设我使用api配置和外部化配置混用应该如何使用配置? @Mulavar

目前暂不考虑混用的场景,bootstrap 这块和 loader 的关系确实不太明晰,我们正在讨论,进一步是不是要合并,还是将程序入口拆分得更加合理 @XiaoWeiKIN

@LaurenceLiZhixin
Copy link
Contributor

I thinks this pr is able to merge, and we would fix TODOs soon.

@LaurenceLiZhixin LaurenceLiZhixin merged commit 9220fa4 into apache:config-api Oct 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants