You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2020/08/05 15:10:19 UTC

[GitHub] [dubbo-go] Patrick0308 opened a new pull request #694: Register service instance after provider config load

Patrick0308 opened a new pull request #694:
URL: https://github.com/apache/dubbo-go/pull/694


   <!--  Thanks for sending a pull request! 
   -->
   
   **What this PR does**:
   Register service instance after provider config load
   
   **Which issue(s) this PR fixes**:
   <!--
   *Automatically closes linked issue when PR is merged.
   Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`.
   _If PR is about `failing-tests or flakes`, please post the related issues/tests in a comment and do not use `Fixes`_*
   -->
   Fixes #686 
   
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo-go] AlexStocks commented on a change in pull request #694: Register service instance after provider config load

Posted by GitBox <gi...@apache.org>.
AlexStocks commented on a change in pull request #694:
URL: https://github.com/apache/dubbo-go/pull/694#discussion_r471114238



##########
File path: cluster/cluster_impl/base_cluster_invoker.go
##########
@@ -146,6 +151,20 @@ func (invoker *baseClusterInvoker) doSelectInvoker(lb cluster.LoadBalance, invoc
 	return selectedInvoker
 }
 
+func (invoker *baseClusterInvoker) Invoke(ctx context.Context, invocation protocol.Invocation) protocol.Result {
+	if invoker.interceptor != nil {

Review comment:
       	if invoker.interceptor == nil {
                    return nil
   	}
   
   	invoker.interceptor.BeforeInvoker(ctx, invocation)
   	result := invoker.interceptor.DoInvoke(ctx, invocation)
   	invoker.interceptor.AfterInvoker(ctx, invocation)
   
   	return result




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo-go] Patrick0308 commented on a change in pull request #694: Register service instance after provider config load

Posted by GitBox <gi...@apache.org>.
Patrick0308 commented on a change in pull request #694:
URL: https://github.com/apache/dubbo-go/pull/694#discussion_r472250027



##########
File path: config/config_loader.go
##########
@@ -206,6 +209,97 @@ func loadProviderConfig() {
 			panic(fmt.Sprintf("service %s export failed! err: %#v", key, err))
 		}
 	}
+	registerServiceInstance()
+}
+
+// registerServiceInstance register service instance
+func registerServiceInstance() {
+	url := selectMetadataServiceExportedURL()
+	if url == nil {
+		return
+	}
+	instance, err := createInstance(*url)
+	if err != nil {
+		panic(err)
+	}
+	p := extension.GetProtocol(constant.REGISTRY_KEY)
+	var rp registry.RegistryFactory
+	var ok bool
+	if rp, ok = p.(registry.RegistryFactory); !ok {
+		panic("dubbo registry protocol is invalid")
+	}
+	rs := rp.GetRegistries()
+	for _, r := range rs {
+		var sdr registry.ServiceDiscoveryHolder
+		if sdr, ok = r.(registry.ServiceDiscoveryHolder); !ok {
+			continue
+		}
+		err := sdr.GetServiceDiscovery().Register(instance)
+		if err != nil {
+			panic(err)
+		}
+	}
+}
+
+// createInstance
+func createInstance(url common.URL) (registry.ServiceInstance, error) {
+	appConfig := GetApplicationConfig()
+	port, err := strconv.ParseInt(url.Port, 10, 32)
+	if err != nil {
+		return nil, perrors.WithMessage(err, "invalid port: "+url.Port)
+	}
+
+	host := url.Ip
+	if len(host) == 0 {
+		host, err = gxnet.GetLocalIP()
+		if err != nil {
+			return nil, perrors.WithMessage(err, "could not get the local Ip")
+		}
+	}
+
+	// usually we will add more metadata
+	metadata := make(map[string]string, 8)
+	metadata[constant.METADATA_STORAGE_TYPE_PROPERTY_NAME] = appConfig.MetadataType
+
+	return &registry.DefaultServiceInstance{
+		ServiceName: appConfig.Name,
+		Host:        host,
+		Port:        int(port),
+		Id:          host + constant.KEY_SEPARATOR + url.Port,
+		Enable:      true,
+		Healthy:     true,
+		Metadata:    metadata,
+	}, nil
+}
+
+// selectMetadataServiceExportedURL get already be exported url
+func selectMetadataServiceExportedURL() *common.URL {
+	var selectedUrl common.URL
+	metaDataService, err := extension.GetMetadataService(GetApplicationConfig().MetadataType)
+	if err != nil {
+		logger.Warn(err)
+		return nil
+	}
+	list, err := metaDataService.GetExportedURLs(constant.ANY_VALUE, constant.ANY_VALUE, constant.ANY_VALUE, constant.ANY_VALUE)
+	if err != nil {
+		panic(err)
+	}
+	if len(list) == 0 {
+		return nil
+	}
+	for _, urlStr := range list {
+		url, err := common.NewURL(urlStr.(string))
+		if err != nil {
+			logger.Errorf("url format error {%v}", url)
+			continue
+		}
+		selectedUrl = url
+		// rest first
+		if url.Protocol == "rest" {

Review comment:
       dubbo in java use rest url first.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo-go] pantianying merged pull request #694: Fix: Register service instance after provider config load

Posted by GitBox <gi...@apache.org>.
pantianying merged pull request #694:
URL: https://github.com/apache/dubbo-go/pull/694


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo-go] AlexStocks commented on a change in pull request #694: Fix: Register service instance after provider config load

Posted by GitBox <gi...@apache.org>.
AlexStocks commented on a change in pull request #694:
URL: https://github.com/apache/dubbo-go/pull/694#discussion_r472553449



##########
File path: config/config_loader_test.go
##########
@@ -33,8 +37,13 @@ import (
 	"github.com/apache/dubbo-go/common/config"
 	"github.com/apache/dubbo-go/common/constant"
 	"github.com/apache/dubbo-go/common/extension"
+	"github.com/apache/dubbo-go/common/logger"
 	"github.com/apache/dubbo-go/common/proxy/proxy_factory"
 	"github.com/apache/dubbo-go/config_center"
+	"github.com/apache/dubbo-go/metadata/service"
+	"github.com/apache/dubbo-go/registry"
+	gxset "github.com/dubbogo/gost/container/set"

Review comment:
       place gxset&gxpage into the second import block.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo-go] zouyx commented on a change in pull request #694: Register service instance after provider config load

Posted by GitBox <gi...@apache.org>.
zouyx commented on a change in pull request #694:
URL: https://github.com/apache/dubbo-go/pull/694#discussion_r471875885



##########
File path: config/config_loader.go
##########
@@ -206,6 +209,97 @@ func loadProviderConfig() {
 			panic(fmt.Sprintf("service %s export failed! err: %#v", key, err))
 		}
 	}
+	registerServiceInstance()
+}
+
+// registerServiceInstance register service instance
+func registerServiceInstance() {
+	url := selectMetadataServiceExportedURL()
+	if url == nil {
+		return
+	}
+	instance, err := createInstance(*url)
+	if err != nil {
+		panic(err)
+	}
+	p := extension.GetProtocol(constant.REGISTRY_KEY)
+	var rp registry.RegistryFactory
+	var ok bool
+	if rp, ok = p.(registry.RegistryFactory); !ok {
+		panic("dubbo registry protocol is invalid")
+	}
+	rs := rp.GetRegistries()
+	for _, r := range rs {
+		var sdr registry.ServiceDiscoveryHolder
+		if sdr, ok = r.(registry.ServiceDiscoveryHolder); !ok {
+			continue
+		}
+		err := sdr.GetServiceDiscovery().Register(instance)
+		if err != nil {
+			panic(err)
+		}
+	}
+}
+
+// createInstance
+func createInstance(url common.URL) (registry.ServiceInstance, error) {
+	appConfig := GetApplicationConfig()
+	port, err := strconv.ParseInt(url.Port, 10, 32)
+	if err != nil {
+		return nil, perrors.WithMessage(err, "invalid port: "+url.Port)
+	}
+
+	host := url.Ip
+	if len(host) == 0 {
+		host, err = gxnet.GetLocalIP()
+		if err != nil {
+			return nil, perrors.WithMessage(err, "could not get the local Ip")
+		}
+	}
+
+	// usually we will add more metadata
+	metadata := make(map[string]string, 8)
+	metadata[constant.METADATA_STORAGE_TYPE_PROPERTY_NAME] = appConfig.MetadataType
+
+	return &registry.DefaultServiceInstance{
+		ServiceName: appConfig.Name,
+		Host:        host,
+		Port:        int(port),
+		Id:          host + constant.KEY_SEPARATOR + url.Port,
+		Enable:      true,
+		Healthy:     true,
+		Metadata:    metadata,
+	}, nil
+}
+
+// selectMetadataServiceExportedURL get already be exported url
+func selectMetadataServiceExportedURL() *common.URL {
+	var selectedUrl common.URL
+	metaDataService, err := extension.GetMetadataService(GetApplicationConfig().MetadataType)
+	if err != nil {
+		logger.Warn(err)
+		return nil
+	}
+	list, err := metaDataService.GetExportedURLs(constant.ANY_VALUE, constant.ANY_VALUE, constant.ANY_VALUE, constant.ANY_VALUE)

Review comment:
       why not  define a new variable with `var selectedUrl common.URL`

##########
File path: config/config_loader.go
##########
@@ -206,6 +209,97 @@ func loadProviderConfig() {
 			panic(fmt.Sprintf("service %s export failed! err: %#v", key, err))
 		}
 	}
+	registerServiceInstance()
+}
+
+// registerServiceInstance register service instance
+func registerServiceInstance() {
+	url := selectMetadataServiceExportedURL()
+	if url == nil {
+		return
+	}
+	instance, err := createInstance(*url)
+	if err != nil {
+		panic(err)
+	}
+	p := extension.GetProtocol(constant.REGISTRY_KEY)
+	var rp registry.RegistryFactory
+	var ok bool
+	if rp, ok = p.(registry.RegistryFactory); !ok {
+		panic("dubbo registry protocol is invalid")
+	}
+	rs := rp.GetRegistries()
+	for _, r := range rs {
+		var sdr registry.ServiceDiscoveryHolder
+		if sdr, ok = r.(registry.ServiceDiscoveryHolder); !ok {
+			continue
+		}
+		err := sdr.GetServiceDiscovery().Register(instance)
+		if err != nil {
+			panic(err)
+		}
+	}
+}
+
+// createInstance
+func createInstance(url common.URL) (registry.ServiceInstance, error) {
+	appConfig := GetApplicationConfig()
+	port, err := strconv.ParseInt(url.Port, 10, 32)
+	if err != nil {
+		return nil, perrors.WithMessage(err, "invalid port: "+url.Port)
+	}
+
+	host := url.Ip
+	if len(host) == 0 {
+		host, err = gxnet.GetLocalIP()
+		if err != nil {
+			return nil, perrors.WithMessage(err, "could not get the local Ip")
+		}
+	}
+
+	// usually we will add more metadata
+	metadata := make(map[string]string, 8)
+	metadata[constant.METADATA_STORAGE_TYPE_PROPERTY_NAME] = appConfig.MetadataType
+
+	return &registry.DefaultServiceInstance{
+		ServiceName: appConfig.Name,
+		Host:        host,
+		Port:        int(port),
+		Id:          host + constant.KEY_SEPARATOR + url.Port,
+		Enable:      true,
+		Healthy:     true,
+		Metadata:    metadata,
+	}, nil
+}
+
+// selectMetadataServiceExportedURL get already be exported url
+func selectMetadataServiceExportedURL() *common.URL {
+	var selectedUrl common.URL
+	metaDataService, err := extension.GetMetadataService(GetApplicationConfig().MetadataType)
+	if err != nil {
+		logger.Warn(err)
+		return nil
+	}
+	list, err := metaDataService.GetExportedURLs(constant.ANY_VALUE, constant.ANY_VALUE, constant.ANY_VALUE, constant.ANY_VALUE)
+	if err != nil {
+		panic(err)
+	}
+	if len(list) == 0 {
+		return nil
+	}
+	for _, urlStr := range list {
+		url, err := common.NewURL(urlStr.(string))
+		if err != nil {
+			logger.Errorf("url format error {%v}", url)
+			continue
+		}
+		selectedUrl = url
+		// rest first
+		if url.Protocol == "rest" {

Review comment:
       if break this loop when find rest protocol, is it a problem or bug in multi protocol ?

##########
File path: registry/protocol/protocol.go
##########
@@ -117,6 +117,17 @@ func (proto *registryProtocol) initConfigurationListeners() {
 	proto.providerConfigurationListener = newProviderConfigurationListener(proto.overrideListeners)
 }
 
+func (proto *registryProtocol) GetRegistries() []registry.Registry {

Review comment:
       ```suggestion
   // nolint
   func (proto *registryProtocol) GetRegistries() []registry.Registry {
   ```

##########
File path: registry/service_discovery_factory.go
##########
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package registry
+
+// ServiceDiscoveryHolder

Review comment:
       add some comment for `ServiceDiscoveryHolder`

##########
File path: config/config_loader.go
##########
@@ -205,6 +207,98 @@ func loadProviderConfig() {
 			panic(fmt.Sprintf("service %s export failed! err: %#v", key, err))
 		}
 	}
+	registerServiceInstance()
+}
+
+// registerServiceInstance register service instance
+func registerServiceInstance(){
+	url := selectMetadataServiceExportedURL()
+	if url == nil {
+		return
+	}
+	instance, err := createInstance(*url)
+	if err != nil {
+		panic(err)
+	}
+	p := extension.GetProtocol(constant.REGISTRY_KEY)
+	var rp registry.RegistryFactory
+	var ok bool
+	if rp, ok = p.(registry.RegistryFactory); !ok {
+		panic("dubbo registry protocol is invalid")

Review comment:
       agree




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo-go] Patrick0308 commented on a change in pull request #694: Register service instance after provider config load

Posted by GitBox <gi...@apache.org>.
Patrick0308 commented on a change in pull request #694:
URL: https://github.com/apache/dubbo-go/pull/694#discussion_r472248713



##########
File path: config/config_loader.go
##########
@@ -206,6 +209,97 @@ func loadProviderConfig() {
 			panic(fmt.Sprintf("service %s export failed! err: %#v", key, err))
 		}
 	}
+	registerServiceInstance()
+}
+
+// registerServiceInstance register service instance
+func registerServiceInstance() {
+	url := selectMetadataServiceExportedURL()
+	if url == nil {
+		return
+	}
+	instance, err := createInstance(*url)
+	if err != nil {
+		panic(err)
+	}
+	p := extension.GetProtocol(constant.REGISTRY_KEY)
+	var rp registry.RegistryFactory
+	var ok bool
+	if rp, ok = p.(registry.RegistryFactory); !ok {
+		panic("dubbo registry protocol is invalid")
+	}
+	rs := rp.GetRegistries()
+	for _, r := range rs {
+		var sdr registry.ServiceDiscoveryHolder
+		if sdr, ok = r.(registry.ServiceDiscoveryHolder); !ok {
+			continue
+		}
+		err := sdr.GetServiceDiscovery().Register(instance)
+		if err != nil {
+			panic(err)
+		}
+	}
+}
+
+// createInstance
+func createInstance(url common.URL) (registry.ServiceInstance, error) {
+	appConfig := GetApplicationConfig()
+	port, err := strconv.ParseInt(url.Port, 10, 32)
+	if err != nil {
+		return nil, perrors.WithMessage(err, "invalid port: "+url.Port)
+	}
+
+	host := url.Ip
+	if len(host) == 0 {
+		host, err = gxnet.GetLocalIP()
+		if err != nil {
+			return nil, perrors.WithMessage(err, "could not get the local Ip")
+		}
+	}
+
+	// usually we will add more metadata
+	metadata := make(map[string]string, 8)
+	metadata[constant.METADATA_STORAGE_TYPE_PROPERTY_NAME] = appConfig.MetadataType
+
+	return &registry.DefaultServiceInstance{
+		ServiceName: appConfig.Name,
+		Host:        host,
+		Port:        int(port),
+		Id:          host + constant.KEY_SEPARATOR + url.Port,
+		Enable:      true,
+		Healthy:     true,
+		Metadata:    metadata,
+	}, nil
+}
+
+// selectMetadataServiceExportedURL get already be exported url
+func selectMetadataServiceExportedURL() *common.URL {
+	var selectedUrl common.URL
+	metaDataService, err := extension.GetMetadataService(GetApplicationConfig().MetadataType)
+	if err != nil {
+		logger.Warn(err)
+		return nil
+	}
+	list, err := metaDataService.GetExportedURLs(constant.ANY_VALUE, constant.ANY_VALUE, constant.ANY_VALUE, constant.ANY_VALUE)

Review comment:
       selectedUrl is above




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo-go] codecov-commenter commented on pull request #694: Fix: Register service instance after provider config load

Posted by GitBox <gi...@apache.org>.
codecov-commenter commented on pull request #694:
URL: https://github.com/apache/dubbo-go/pull/694#issuecomment-677260114


   # [Codecov](https://codecov.io/gh/apache/dubbo-go/pull/694?src=pr&el=h1) Report
   > Merging [#694](https://codecov.io/gh/apache/dubbo-go/pull/694?src=pr&el=desc) into [1.5.1](https://codecov.io/gh/apache/dubbo-go/commit/e3dd46ff2e4a1e54dda84a04845bc9c664c4a927&el=desc) will **increase** coverage by `0.03%`.
   > The diff coverage is `53.52%`.
   
   [![Impacted file tree graph](https://codecov.io/gh/apache/dubbo-go/pull/694/graphs/tree.svg?width=650&height=150&src=pr&token=dcPE6RyFAL)](https://codecov.io/gh/apache/dubbo-go/pull/694?src=pr&el=tree)
   
   ```diff
   @@            Coverage Diff             @@
   ##            1.5.1     #694      +/-   ##
   ==========================================
   + Coverage   63.89%   63.93%   +0.03%     
   ==========================================
     Files         239      239              
     Lines       12752    12795      +43     
   ==========================================
   + Hits         8148     8180      +32     
   - Misses       3818     3822       +4     
   - Partials      786      793       +7     
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/dubbo-go/pull/694?src=pr&el=tree) | Coverage Δ | |
   |---|---|---|
   | [common/extension/metadata\_service.go](https://codecov.io/gh/apache/dubbo-go/pull/694/diff?src=pr&el=tree#diff-Y29tbW9uL2V4dGVuc2lvbi9tZXRhZGF0YV9zZXJ2aWNlLmdv) | `0.00% <0.00%> (ø)` | |
   | [registry/protocol/protocol.go](https://codecov.io/gh/apache/dubbo-go/pull/694/diff?src=pr&el=tree#diff-cmVnaXN0cnkvcHJvdG9jb2wvcHJvdG9jb2wuZ28=) | `78.48% <0.00%> (-2.31%)` | :arrow_down: |
   | [...try/servicediscovery/service\_discovery\_registry.go](https://codecov.io/gh/apache/dubbo-go/pull/694/diff?src=pr&el=tree#diff-cmVnaXN0cnkvc2VydmljZWRpc2NvdmVyeS9zZXJ2aWNlX2Rpc2NvdmVyeV9yZWdpc3RyeS5nbw==) | `11.91% <ø> (-3.34%)` | :arrow_down: |
   | [config/config\_loader.go](https://codecov.io/gh/apache/dubbo-go/pull/694/diff?src=pr&el=tree#diff-Y29uZmlnL2NvbmZpZ19sb2FkZXIuZ28=) | `57.27% <61.29%> (+1.57%)` | :arrow_up: |
   | [config\_center/apollo/listener.go](https://codecov.io/gh/apache/dubbo-go/pull/694/diff?src=pr&el=tree#diff-Y29uZmlnX2NlbnRlci9hcG9sbG8vbGlzdGVuZXIuZ28=) | `82.60% <0.00%> (-17.40%)` | :arrow_down: |
   | [...tocol/rest/server/server\_impl/go\_restful\_server.go](https://codecov.io/gh/apache/dubbo-go/pull/694/diff?src=pr&el=tree#diff-cHJvdG9jb2wvcmVzdC9zZXJ2ZXIvc2VydmVyX2ltcGwvZ29fcmVzdGZ1bF9zZXJ2ZXIuZ28=) | `43.33% <0.00%> (-3.34%)` | :arrow_down: |
   | [config\_center/nacos/listener.go](https://codecov.io/gh/apache/dubbo-go/pull/694/diff?src=pr&el=tree#diff-Y29uZmlnX2NlbnRlci9uYWNvcy9saXN0ZW5lci5nbw==) | `45.45% <0.00%> (-2.17%)` | :arrow_down: |
   | [config\_center/apollo/impl.go](https://codecov.io/gh/apache/dubbo-go/pull/694/diff?src=pr&el=tree#diff-Y29uZmlnX2NlbnRlci9hcG9sbG8vaW1wbC5nbw==) | `80.82% <0.00%> (-1.90%)` | :arrow_down: |
   | [protocol/dubbo/config.go](https://codecov.io/gh/apache/dubbo-go/pull/694/diff?src=pr&el=tree#diff-cHJvdG9jb2wvZHViYm8vY29uZmlnLmdv) | `13.15% <0.00%> (ø)` | |
   | [config/consumer\_config.go](https://codecov.io/gh/apache/dubbo-go/pull/694/diff?src=pr&el=tree#diff-Y29uZmlnL2NvbnN1bWVyX2NvbmZpZy5nbw==) | `56.25% <0.00%> (ø)` | |
   | ... and [5 more](https://codecov.io/gh/apache/dubbo-go/pull/694/diff?src=pr&el=tree-more) | |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/dubbo-go/pull/694?src=pr&el=continue).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
   > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/dubbo-go/pull/694?src=pr&el=footer). Last update [e3dd46f...d58e4fa](https://codecov.io/gh/apache/dubbo-go/pull/694?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo-go] AlexStocks commented on a change in pull request #694: Register service instance after provider config load

Posted by GitBox <gi...@apache.org>.
AlexStocks commented on a change in pull request #694:
URL: https://github.com/apache/dubbo-go/pull/694#discussion_r470208442



##########
File path: config/config_loader.go
##########
@@ -205,6 +207,98 @@ func loadProviderConfig() {
 			panic(fmt.Sprintf("service %s export failed! err: %#v", key, err))
 		}
 	}
+	registerServiceInstance()
+}
+
+// registerServiceInstance register service instance
+func registerServiceInstance(){
+	url := selectMetadataServiceExportedURL()
+	if url == nil {
+		return
+	}
+	instance, err := createInstance(*url)
+	if err != nil {
+		panic(err)
+	}
+	p := extension.GetProtocol(constant.REGISTRY_KEY)
+	var rp registry.RegistryFactory
+	var ok bool
+	if rp, ok = p.(registry.RegistryFactory); !ok {
+		panic("dubbo registry protocol is invalid")
+	}
+	rs := rp.GetRegistries()
+	for _, r := range rs {
+		var sdr registry.ServiceDiscoveryHolder
+		if sdr, ok = r.(registry.ServiceDiscoveryHolder); !ok {
+			continue
+		}
+		err := sdr.GetServiceDiscovery().Register(instance)
+		if err != nil {
+			panic(err)
+		}
+	}
+}
+
+// createInstance
+func createInstance(url common.URL) (registry.ServiceInstance, error) {
+	appConfig := GetApplicationConfig()
+	port, err := strconv.ParseInt(url.Port, 10, 32)
+	if err != nil {
+		return nil, perrors.WithMessage(err, "invalid port: "+url.Port)
+	}
+
+	host := url.Ip
+	if len(host) == 0 {
+		host, err = gxnet.GetLocalIP()
+		if err != nil {
+			return nil, perrors.WithMessage(err, "could not get the local Ip")
+		}
+	}
+
+	// usually we will add more metadata
+	metadata := make(map[string]string, 8)
+	metadata[constant.METADATA_STORAGE_TYPE_PROPERTY_NAME] = appConfig.MetadataType
+
+	return &registry.DefaultServiceInstance{
+		ServiceName: appConfig.Name,
+		Host:        host,
+		Port:        int(port),
+		Id:          host + constant.KEY_SEPARATOR + url.Port,
+		Enable:      true,
+		Healthy:     true,
+		Metadata:    metadata,
+	}, nil
+}
+
+// selectMetadataServiceExportedURL get already be exported url
+func selectMetadataServiceExportedURL() *common.URL {
+	var selectedUrl common.URL
+	metaDataService, err := extension.GetMetadataService(GetApplicationConfig().MetadataType)
+	if err != nil {
+		panic(err)
+	}
+	list, err := metaDataService.GetExportedURLs(constant.ANY_VALUE, constant.ANY_VALUE, constant.ANY_VALUE, constant.ANY_VALUE)
+	if err != nil {
+		panic(err)
+	}
+	if len(list) == 0 {
+		return nil
+	}
+	for _, urlStr := range list {
+		url, err := common.NewURL(urlStr.(string))
+		if err != nil {
+			logger.Errorf("url format error {%v}", url)
+			continue
+		}
+		// rest first
+		if url.Protocol == "rest" {
+			selectedUrl = url
+			break
+		} else {
+			selectedUrl = url
+		}

Review comment:
       ```Go
       selectedUrl = url
       if url.Protocol == "rest" {
   	break
       } 
   ```

##########
File path: config/config_loader.go
##########
@@ -205,6 +207,98 @@ func loadProviderConfig() {
 			panic(fmt.Sprintf("service %s export failed! err: %#v", key, err))
 		}
 	}
+	registerServiceInstance()
+}
+
+// registerServiceInstance register service instance
+func registerServiceInstance(){
+	url := selectMetadataServiceExportedURL()
+	if url == nil {
+		return
+	}
+	instance, err := createInstance(*url)
+	if err != nil {
+		panic(err)
+	}
+	p := extension.GetProtocol(constant.REGISTRY_KEY)
+	var rp registry.RegistryFactory
+	var ok bool
+	if rp, ok = p.(registry.RegistryFactory); !ok {
+		panic("dubbo registry protocol is invalid")

Review comment:
       pls add rp type info in the panic string




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo-go] AlexStocks commented on a change in pull request #694: Fix: Register service instance after provider config load

Posted by GitBox <gi...@apache.org>.
AlexStocks commented on a change in pull request #694:
URL: https://github.com/apache/dubbo-go/pull/694#discussion_r473631271



##########
File path: config/config_loader.go
##########
@@ -206,6 +210,97 @@ func loadProviderConfig() {
 			panic(fmt.Sprintf("service %s export failed! err: %#v", key, err))
 		}
 	}
+	registerServiceInstance()
+}
+
+// registerServiceInstance register service instance
+func registerServiceInstance() {
+	url := selectMetadataServiceExportedURL()
+	if url == nil {
+		return
+	}
+	instance, err := createInstance(*url)
+	if err != nil {
+		panic(err)
+	}
+	p := extension.GetProtocol(constant.REGISTRY_KEY)
+	var rp registry.RegistryFactory
+	var ok bool
+	if rp, ok = p.(registry.RegistryFactory); !ok {
+		panic("dubbo registry protocol{" + reflect.TypeOf(p).String() + "} is invalid")
+	}
+	rs := rp.GetRegistries()
+	for _, r := range rs {
+		var sdr registry.ServiceDiscoveryHolder
+		if sdr, ok = r.(registry.ServiceDiscoveryHolder); !ok {
+			continue
+		}
+		err := sdr.GetServiceDiscovery().Register(instance)
+		if err != nil {
+			panic(err)
+		}
+	}
+}
+
+// createInstance

Review comment:
       do not add comment for private func if you do not wanna add it.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org