diff --git a/metadata/definition/definition.go b/metadata/definition/definition.go index 2cb11e3984..d4d5780033 100644 --- a/metadata/definition/definition.go +++ b/metadata/definition/definition.go @@ -37,10 +37,10 @@ type ServiceDefiner interface { // ServiceDefinition is the describer of service definition type ServiceDefinition struct { - CanonicalName string - CodeSource string - Methods []MethodDefinition - Types []TypeDefinition + CanonicalName string `json:"canonicalName"` + CodeSource string `json:"codeSource"` + Methods []MethodDefinition `json:"methods"` + Types []TypeDefinition `json:"types"` } // ToBytes convert ServiceDefinition to json string @@ -71,26 +71,26 @@ func (def *ServiceDefinition) String() string { // FullServiceDefinition is the describer of service definition with parameters type FullServiceDefinition struct { - Parameters map[string]string + Parameters map[string]string `json:"parameters"` ServiceDefinition } // MethodDefinition is the describer of method definition type MethodDefinition struct { - Name string - ParameterTypes []string - ReturnType string - Parameters []TypeDefinition + Name string `json:"name"` + ParameterTypes []string `json:"parameterTypes"` + ReturnType string `json:"returnType"` + Parameters []TypeDefinition `json:"parameters"` } // TypeDefinition is the describer of type definition type TypeDefinition struct { - ID string - Type string - Items []TypeDefinition - Enums []string - Properties map[string]TypeDefinition - TypeBuilderName string + ID string `json:"id"` + Type string `json:"type"` + Items []TypeDefinition `json:"items"` + Enums []string `json:"enums"` + Properties map[string]TypeDefinition `json:"properties"` + TypeBuilderName string `json:"typeBuilderName"` } // BuildServiceDefinition can build service definition which will be used to describe a service diff --git a/metadata/identifier/base_metadata_identifier.go b/metadata/identifier/base_metadata_identifier.go index cdfeac787e..7df3e6c3af 100644 --- a/metadata/identifier/base_metadata_identifier.go +++ b/metadata/identifier/base_metadata_identifier.go @@ -21,6 +21,10 @@ import ( "net/url" ) +import ( + "github.com/dubbogo/gost/log/logger" +) + import ( "dubbo.apache.org/dubbo-go/v3/common/constant" ) @@ -43,6 +47,10 @@ type BaseMetadataIdentifier struct { func joinParams(joinChar string, params []string) string { var joinedStr string for _, param := range params { + if param == "" { + logger.Info("[Metadata report] Break loop in `joinParams` to avoid invalid path when meeting empty param") + break + } joinedStr += joinChar joinedStr += param } diff --git a/metadata/report/delegate/delegate_report.go b/metadata/report/delegate/delegate_report.go index 70a12ac226..d57b35f8ab 100644 --- a/metadata/report/delegate/delegate_report.go +++ b/metadata/report/delegate/delegate_report.go @@ -304,7 +304,7 @@ func (mr *MetadataReport) doHandlerMetadataCollection(metadataMap map[*identifie } for e := range metadataMap { if common.RoleType(common.PROVIDER).Role() == e.Side { - mr.StoreProviderMetadata(e, metadataMap[e].(*definition.ServiceDefinition)) + mr.StoreProviderMetadata(e, metadataMap[e].(*definition.FullServiceDefinition)) } else if common.RoleType(common.CONSUMER).Role() == e.Side { mr.StoreConsumerMetadata(e, metadataMap[e].(map[string]string)) } diff --git a/metadata/service/local/service_test.go b/metadata/service/local/service_test.go index 031c8a56b1..c1e952c873 100644 --- a/metadata/service/local/service_test.go +++ b/metadata/service/local/service_test.go @@ -99,16 +99,16 @@ func TestMetadataService(t *testing.T) { assert.NoError(t, err) err = mts.PublishServiceDefinition(u) assert.NoError(t, err) - expected := "{\"Parameters\":{\"anyhost\":\"true\",\"application\":\"BDTService\"," + + expected := "{\"parameters\":{\"anyhost\":\"true\",\"application\":\"BDTService\"," + "\"bean.name\":\"UserProvider\",\"category\":\"providers\",\"default.timeout\":\"10000\"," + "\"dubbo\":\"dubbo-provider-golang-1.0.0\",\"environment\":\"dev\",\"group\":\"group1\"," + "\"interface\":\"com.ikurento.user.UserProvider\",\"ip\":\"192.168.56.1\"," + "\"methods\":\"GetUser\",\"module\":\"dubbogo user-info server\",\"org\":\"ikurento.com\"," + "\"owner\":\"ZX\",\"pid\":\"1447\",\"revision\":\"0.0.1\",\"side\":\"provider\"," + "\"timeout\":\"3000\",\"timestamp\":\"1556509797245\",\"version\":\"0.0.1\"}," + - "\"CanonicalName\":\"com.ikurento.user.UserProvider\",\"CodeSource\":\"\"," + - "\"Methods\":[{\"Name\":\"GetUser\",\"ParameterTypes\":[\"slice\"],\"ReturnType\":\"ptr\"," + - "\"Parameters\":null}],\"Types\":null}" + "\"canonicalName\":\"com.ikurento.user.UserProvider\",\"codeSource\":\"\"," + + "\"methods\":[{\"name\":\"GetUser\",\"parameterTypes\":[\"slice\"],\"returnType\":\"ptr\"," + + "\"parameters\":null}],\"types\":null}" def1, err := mts.GetServiceDefinition(serviceName, group, version) assert.Equal(t, expected, def1) assert.NoError(t, err) diff --git a/metadata/service/remote/service_test.go b/metadata/service/remote/service_test.go index fa4a17e984..e435ef7a4e 100644 --- a/metadata/service/remote/service_test.go +++ b/metadata/service/remote/service_test.go @@ -146,17 +146,16 @@ func TestMockInmemoryProc(t *testing.T) { err = mts.PublishServiceDefinition(u) assert.NoError(t, err) - expected := "{\"Parameters\":{\"anyhost\":\"true\",\"application\":\"BDTService\"," + + expected := "{\"parameters\":{\"anyhost\":\"true\",\"application\":\"BDTService\"," + "\"bean.name\":\"UserProvider\",\"category\":\"providers\",\"default.timeout\":\"10000\"," + "\"dubbo\":\"dubbo-provider-golang-1.0.0\",\"environment\":\"dev\",\"group\":\"group1\"," + "\"interface\":\"com.ikurento.user.UserProvider\",\"ip\":\"192.168.56.1\"," + "\"methods\":\"GetUser\",\"module\":\"dubbogo user-info server\",\"org\":\"ikurento.com\"," + "\"owner\":\"ZX\",\"pid\":\"1447\",\"revision\":\"0.0.1\",\"side\":\"provider\"," + "\"timeout\":\"3000\",\"timestamp\":\"1556509797245\",\"version\":\"0.0.1\"}," + - "\"CanonicalName\":\"com.ikurento.user.UserProvider\",\"CodeSource\":\"\"," + - "\"Methods\":[{\"Name\":\"GetUser\",\"ParameterTypes\":[\"slice\"],\"ReturnType\":\"ptr\"," + - "\"Parameters\":null}],\"Types\":null}" - + "\"canonicalName\":\"com.ikurento.user.UserProvider\",\"codeSource\":\"\"," + + "\"methods\":[{\"name\":\"GetUser\",\"parameterTypes\":[\"slice\"],\"returnType\":\"ptr\"," + + "\"parameters\":null}],\"types\":null}" def1, _ := mts.GetServiceDefinition(serviceName, group, version) assert.Equal(t, expected, def1) serviceKey := definition.ServiceDescriperBuild(serviceName, group, version)