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

Ftr: zk/consul Metadata #633

Merged
merged 19 commits into from
Jul 4, 2020
Merged

Conversation

gaoxinge
Copy link

@gaoxinge gaoxinge commented Jun 26, 2020

What this PR does:

  • add consul metadata report
  • add zookeeper metadata report

Which issue(s) this PR fixes:

Fixes #445.

Special notes for your reviewer:

  • TODO
    • add consul metadata report unit test
    • add zookeeper metadata report unit test

Does this PR introduce a user-facing change?:

NONE

@AlexStocks AlexStocks changed the title WIP: Metadata WIP: zk Metadata Jun 27, 2020
@AlexStocks AlexStocks changed the title WIP: zk Metadata WIP: Metadata Jun 27, 2020
@AlexStocks AlexStocks changed the title WIP: Metadata WIP: zk/consul Metadata Jun 27, 2020
@codecov-commenter
Copy link

codecov-commenter commented Jun 28, 2020

Codecov Report

Merging #633 into feature/dubbo-2.7.5 will decrease coverage by 0.06%.
The diff coverage is 72.84%.

Impacted file tree graph

@@                   Coverage Diff                   @@
##           feature/dubbo-2.7.5     #633      +/-   ##
=======================================================
- Coverage                65.98%   65.92%   -0.07%     
=======================================================
  Files                      204      207       +3     
  Lines                    10604    10722     +118     
=======================================================
+ Hits                      6997     7068      +71     
- Misses                    2929     2972      +43     
- Partials                   678      682       +4     
Impacted Files Coverage Δ
metadata/report/delegate/delegate_report.go 29.41% <0.00%> (-19.82%) ⬇️
metadata/report/nacos/report.go 72.09% <68.75%> (+1.88%) ⬆️
metadata/report/consul/report.go 75.51% <75.51%> (ø)
remoting/consul/test_agent.go 81.81% <81.81%> (ø)
metadata/report/zookeeper/report.go 82.00% <82.00%> (ø)
remoting/zookeeper/client.go 66.85% <100.00%> (+0.19%) ⬆️
registry/nacos/listener.go 78.18% <0.00%> (-1.82%) ⬇️
... and 3 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 024f7b2...302dbc2. Read the comment docs.

@gaoxinge gaoxinge changed the title WIP: zk/consul Metadata Ftr: zk/consul Metadata Jun 28, 2020
.gitignore Show resolved Hide resolved
metadata/report/consul/report.go Outdated Show resolved Hide resolved
metadata/report/consul/report.go Outdated Show resolved Hide resolved
metadata/report/nacos/report.go Show resolved Hide resolved
metadata/report/consul/report.go Show resolved Hide resolved

// StoreProviderMetadata stores the metadata.
func (m *consulMetadataReport) StoreProviderMetadata(providerIdentifier *identifier.MetadataIdentifier, serviceDefinitions string) error {
kv := &consul.KVPair{Key: providerIdentifier.GetIdentifierKey(), Value: []byte(serviceDefinitions)}
Copy link
Contributor

Choose a reason for hiding this comment

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

go fmt not work ?

Copy link
Author

Choose a reason for hiding this comment

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

It is ok with go fmt.

k := metadataIdentifier.GetIdentifierKey()
kv, _, err := m.client.KV().Get(k, nil)
if err != nil {
panic(err)
Copy link
Contributor

Choose a reason for hiding this comment

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

don't panic

Copy link
Author

Choose a reason for hiding this comment

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

I remove this panic and return an error in this function.

if err != nil {
return perrors.WithMessage(err, "Could not convert the array to json")
}

report := instance.GetMetadataReportInstance()
Copy link
Contributor

Choose a reason for hiding this comment

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

This common logic may be confirmed by @flycash

Copy link
Contributor

Choose a reason for hiding this comment

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

May create influence to nacos's implement.

Copy link
Author

@gaoxinge gaoxinge Jun 29, 2020

Choose a reason for hiding this comment

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

I think this is a common code for different metadata reports, and one can find the similar code in java version.

Copy link
Member

Choose a reason for hiding this comment

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

Let's keep those codes, I will test it again

metadata/report/nacos/report.go Show resolved Hide resolved
metadata/report/zookeeper/report.go Show resolved Hide resolved
@@ -0,0 +1,70 @@
/*
Copy link
Contributor

Choose a reason for hiding this comment

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

What the consultAgent used for ?

Copy link
Contributor

Choose a reason for hiding this comment

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

If used for unit test, it's better to move to xxx_test file.

Copy link
Author

@gaoxinge gaoxinge Jun 29, 2020

Choose a reason for hiding this comment

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

This consulAgent is used for test, and is imported by other test, so I rename agent.go to test_agent.go. (xxx_test.go can not be imported by other test.)

// GetSubscribedURLs gets the urls.
func (m *consulMetadataReport) GetSubscribedURLs(subscriberMetadataIdentifier *identifier.SubscriberMetadataIdentifier) ([]string, error) {
k := subscriberMetadataIdentifier.GetIdentifierKey()
kv, _, err := m.client.KV().Get(k, nil)
Copy link
Contributor

Choose a reason for hiding this comment

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

if err != nil || kv == nil {
return emptyStrSlice, err
}

Copy link
Author

Choose a reason for hiding this comment

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

I follow your advice and keep code more simpler.

metadata/report/consul/report.go Outdated Show resolved Hide resolved
metadata/report/consul/report.go Show resolved Hide resolved
if err != nil {
return perrors.WithMessage(err, "Could not convert the array to json")
}

report := instance.GetMetadataReportInstance()
Copy link
Member

Choose a reason for hiding this comment

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

Let's keep those codes, I will test it again

metadata/report/nacos/report.go Show resolved Hide resolved
metadata/report/zookeeper/report.go Outdated Show resolved Hide resolved
func (m *zookeeperMetadataReport) GetSubscribedURLs(subscriberMetadataIdentifier *identifier.SubscriberMetadataIdentifier) ([]string, error) {
k := m.rootDir + subscriberMetadataIdentifier.GetFilePathKey()
v, _, err := m.client.GetContent(k)
if err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

see above comment

Copy link
Author

Choose a reason for hiding this comment

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

I follow your advice and keep code more simpler.

metadata/report/consul/report_test.go Outdated Show resolved Hide resolved
metadata/report/report.go Outdated Show resolved Hide resolved
metadata/report/zookeeper/report_test.go Outdated Show resolved Hide resolved
Copy link
Member

@pantianying pantianying left a comment

Choose a reason for hiding this comment

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

LGTM

@pantianying pantianying merged commit 5a12137 into apache:feature/dubbo-2.7.5 Jul 4, 2020
@gaoxinge gaoxinge deleted the metadata branch July 5, 2020 02:20
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