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

[3.1] Fix nacos App Metadata not compatible with java #2563

Merged
merged 3 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
27 changes: 23 additions & 4 deletions metadata/report/nacos/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,24 @@ type nacosMetadataReport struct {

// GetAppMetadata get metadata info from nacos
func (n *nacosMetadataReport) GetAppMetadata(metadataIdentifier *identifier.SubscriberMetadataIdentifier) (*common.MetadataInfo, error) {
// compatible with java impl first
data, err := n.getConfig(vo.ConfigParam{
DataId: metadataIdentifier.GetIdentifierKey(),
Group: n.group,
DataId: metadataIdentifier.Application,
Group: metadataIdentifier.Revision,
})
if err != nil {
return nil, err
}

if data == "" {
// compatible with dubbo-go 3.1.x before
data, err = n.getConfig(vo.ConfigParam{
DataId: metadataIdentifier.GetIdentifierKey(),
Group: n.group,
})
if err != nil {
return nil, err
}
}
var metadataInfo common.MetadataInfo
err = json.Unmarshal([]byte(data), &metadataInfo)
if err != nil {
Expand All @@ -91,7 +101,16 @@ func (n *nacosMetadataReport) PublishAppMetadata(metadataIdentifier *identifier.
if err != nil {
return err
}

// compatible with java impl
err = n.storeMetadata(vo.ConfigParam{
DataId: metadataIdentifier.Application,
Group: metadataIdentifier.Revision,
Content: string(data),
})
if err != nil {
return err
}
// compatible with dubbo-go 3.1.x before
return n.storeMetadata(vo.ConfigParam{
DataId: metadataIdentifier.GetIdentifierKey(),
Group: n.group,
Expand Down
4 changes: 2 additions & 2 deletions metadata/report/nacos/report_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func Test_nacosMetadataReport_GetAppMetadata(t *testing.T) {

ctrl := gomock.NewController(t)
mnc := NewMockIConfigClient(ctrl)
mnc.EXPECT().GetConfig(gomock.Any()).Return(string(data), nil)
mnc.EXPECT().GetConfig(gomock.Any()).MaxTimes(2).Return(string(data), nil)
nc := &nacosClient.NacosConfigClient{}
nc.SetClient(mnc)

Expand Down Expand Up @@ -253,7 +253,7 @@ func Test_nacosMetadataReport_GetAppMetadata(t *testing.T) {
func Test_nacosMetadataReport_PublishAppMetadata(t *testing.T) {
ctrl := gomock.NewController(t)
mnc := NewMockIConfigClient(ctrl)
mnc.EXPECT().PublishConfig(gomock.Any()).Return(true, nil)
mnc.EXPECT().PublishConfig(gomock.Any()).Times(2).Return(true, nil)
nc := &nacosClient.NacosConfigClient{}
nc.SetClient(mnc)

Expand Down
Loading