This is an automated email from the ASF dual-hosted git repository.

alexstocks pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/dubbo-go.git


The following commit(s) were added to refs/heads/develop by this push:
     new c885393e3 Fixed: the issue that services configuration under provider 
is invalid in dubbo.load() loading mode. (#2941)
c885393e3 is described below

commit c885393e3493d5262cbaef9f6932fdd3ce95c568
Author: 1kasa <[email protected]>
AuthorDate: Sat Jul 26 10:40:17 2025 +0800

    Fixed: the issue that services configuration under provider is invalid in 
dubbo.load() loading mode. (#2941)
    
    * Fix: the error that consumerConfig failed to successfully overwrite part 
of the configuration when overallreference was empty
    
    * sort import
    
    * wrong commit
    
    * wrong commit
    
    * Temporary Save
    
    * Temporary Save
    
    * Fixed the issue that services configuration under provider is invalid in 
dubbo.load() loading mode.
    
    * Temporary Save
    
    * fix: wrong commit
    
    * sort import
    
    * Add comment
    
    * Merge and modify duplicate content
    
    * replace by constant
    
    * add else logger
    
    * fix warning logger
    
    * Optimize code
    
    * Optimize test code
    
    * fix test name
---
 client/client.go           |  1 +
 client/options.go          | 19 +++++++++++++++++--
 client/options_test.go     | 31 +++++++++++++++++++++++++++++++
 config/reference_config.go |  1 +
 config/service_config.go   |  1 -
 dubbo.go                   |  1 -
 options.go                 |  2 ++
 protocol/triple/triple.go  |  1 +
 server/action.go           |  1 -
 server/options.go          |  1 +
 server/server.go           | 24 ++++++++++++++++++++++++
 11 files changed, 78 insertions(+), 5 deletions(-)

diff --git a/client/client.go b/client/client.go
index 096b2a54c..1fddf423e 100644
--- a/client/client.go
+++ b/client/client.go
@@ -172,6 +172,7 @@ func (cli *Client) dial(interfaceName string, info 
*ClientInfo, srv any, opts ..
                // this config must be set after Reference initialized
                setInterfaceName(interfaceName),
        }
+
        finalOpts = append(finalOpts, opts...)
        if err := newRefOpts.init(finalOpts...); err != nil {
                return nil, err
diff --git a/client/options.go b/client/options.go
index 9d0b47991..bcefc3c2d 100644
--- a/client/options.go
+++ b/client/options.go
@@ -102,9 +102,8 @@ func (refOpts *ReferenceOptions) init(opts 
...ReferenceOption) error {
        }
 
        // init cluster
-       // TODO: use constant replace failover
        if refConf.Cluster == "" {
-               refConf.Cluster = "failover"
+               refConf.Cluster = constant.ClusterKeyFailover
        }
 
        // init registries
@@ -510,6 +509,7 @@ func (cliOpts *ClientOptions) init(opts ...ClientOption) 
error {
        for _, opt := range opts {
                opt(cliOpts)
        }
+
        if err := defaults.Set(cliOpts); err != nil {
                return err
        }
@@ -564,6 +564,21 @@ func (cliOpts *ClientOptions) init(opts ...ClientOption) 
error {
 
        // todo(DMwangnima): is there any part that we should do compatibility 
processing?
 
+       // init overallReference from Consumer config
+       if consumerConf != nil {
+               if cliOpts.overallReference.Filter == "" {
+                       cliOpts.overallReference.Filter = consumerConf.Filter
+               }
+               if len(cliOpts.overallReference.RegistryIDs) <= 0 {
+                       cliOpts.overallReference.RegistryIDs = 
consumerConf.RegistryIDs
+               }
+               if cliOpts.overallReference.TracingKey == "" {
+                       cliOpts.overallReference.TracingKey = 
consumerConf.TracingKey
+               }
+               if cliOpts.overallReference.Check == nil {
+                       cliOpts.overallReference.Check = &consumerConf.Check
+               }
+       }
        // init graceful_shutdown
        
graceful_shutdown.Init(graceful_shutdown.SetShutdownConfig(cliOpts.Shutdown))
        return nil
diff --git a/client/options_test.go b/client/options_test.go
index 1e580db7e..8b1a52cb0 100644
--- a/client/options_test.go
+++ b/client/options_test.go
@@ -28,6 +28,7 @@ import (
 
 import (
        "dubbo.apache.org/dubbo-go/v3/common/constant"
+       "dubbo.apache.org/dubbo-go/v3/global"
        "dubbo.apache.org/dubbo-go/v3/registry"
 )
 
@@ -1231,3 +1232,33 @@ func TestWithKeepAliveConfig(t *testing.T) {
        }
        processNewClientCases(t, cases)
 }
+
+func TestInitWithConsumer(t *testing.T) {
+       trueVal := true
+       cliOpts := &ClientOptions{
+               Consumer: &global.ConsumerConfig{
+                       Filter:      "f",
+                       RegistryIDs: []string{"r"},
+                       TracingKey:  "t",
+                       Check:       trueVal,
+               },
+               overallReference: &global.ReferenceConfig{},
+               Registries: map[string]*global.RegistryConfig{
+                       "r": {
+                               Protocol: "mock-protocol",
+                               Address:  "127.0.0.1:2181",
+                       },
+               },
+       }
+
+       if err := cliOpts.init(); err != nil {
+               t.Fatal(err)
+       }
+
+       ref := cliOpts.overallReference
+       if ref.Filter != "f" || ref.TracingKey != "t" ||
+               len(ref.RegistryIDs) != 1 || ref.RegistryIDs[0] != "r" ||
+               ref.Check == nil || *ref.Check != true {
+               t.Errorf("fields not copied as expected: %+v", ref)
+       }
+}
diff --git a/config/reference_config.go b/config/reference_config.go
index 9657f931d..b0e42ea0c 100644
--- a/config/reference_config.go
+++ b/config/reference_config.go
@@ -326,6 +326,7 @@ func (rc *ReferenceConfig) getURLMap() url.Values {
        for k, v := range rc.Params {
                urlMap.Set(k, v)
        }
+
        urlMap.Set(constant.InterfaceKey, rc.InterfaceName)
        urlMap.Set(constant.TimestampKey, strconv.FormatInt(time.Now().Unix(), 
10))
        urlMap.Set(constant.ClusterKey, rc.Cluster)
diff --git a/config/service_config.go b/config/service_config.go
index 0734fc5b5..bc6e658a3 100644
--- a/config/service_config.go
+++ b/config/service_config.go
@@ -316,7 +316,6 @@ func (s *ServiceConfig) Export() error {
                                setRegistrySubURL(ivkURL, regUrl)
 
                                invoker = s.generatorInvoker(regUrl, info)
-
                                exporter := s.cacheProtocol.Export(invoker)
                                if exporter == nil {
                                        return 
perrors.New(fmt.Sprintf("Registry protocol new exporter error, registry is 
{%v}, url is {%v}", regUrl, ivkURL))
diff --git a/dubbo.go b/dubbo.go
index 10531f304..93e3ad5a5 100644
--- a/dubbo.go
+++ b/dubbo.go
@@ -112,7 +112,6 @@ func (ins *Instance) NewClient(opts ...client.ClientOption) 
(*client.Client, err
 
        // options passed by users has higher priority
        cliOpts = append(cliOpts, opts...)
-
        cli, err := client.NewClient(cliOpts...)
        if err != nil {
                return nil, err
diff --git a/options.go b/options.go
index 61a713e20..83c81af4c 100644
--- a/options.go
+++ b/options.go
@@ -89,6 +89,7 @@ func (rc *InstanceOptions) init(opts ...InstanceOption) error 
{
        // remaining procedure is like RootConfig.Init() without 
RootConfig.Start()
        // tasks of RootConfig.Start() would be decomposed to Client and Server
        rcCompat := compatRootConfig(rc)
+
        if err := rcCompat.Logger.Init(); err != nil { // init default logger
                return err
        }
@@ -164,6 +165,7 @@ func (rc *InstanceOptions) init(opts ...InstanceOption) 
error {
        }
 
        compatInstanceOptions(rcCompat, rc) // overrider options config because 
some config are changed after init
+
        return nil
 }
 
diff --git a/protocol/triple/triple.go b/protocol/triple/triple.go
index 538d67d57..4e18ff6d1 100644
--- a/protocol/triple/triple.go
+++ b/protocol/triple/triple.go
@@ -122,6 +122,7 @@ func (tp *TripleProtocol) Refer(url *common.URL) 
base.Invoker {
                logger.Warnf("can't dial the server: %s", url.Key())
                return nil
        }
+
        tp.SetInvokers(invoker)
        logger.Infof("[TRIPLE Protocol] Refer service: %s", url.String())
        return invoker
diff --git a/server/action.go b/server/action.go
index b85edcee5..c43bb7d63 100644
--- a/server/action.go
+++ b/server/action.go
@@ -134,7 +134,6 @@ func (svcOpts *ServiceOptions) ExportWithInfo(info 
*common.ServiceInfo) error {
 
 func (svcOpts *ServiceOptions) export(info *common.ServiceInfo) error {
        svcConf := svcOpts.Service
-
        if info != nil {
                if svcConf.Interface == "" {
                        svcConf.Interface = info.InterfaceName
diff --git a/server/options.go b/server/options.go
index ef4c8220d..d043808aa 100644
--- a/server/options.go
+++ b/server/options.go
@@ -527,6 +527,7 @@ func (svcOpts *ServiceOptions) init(srv *Server, opts 
...ServiceOption) error {
 
        svcOpts.srvOpts = srv.cfg
        svc := svcOpts.Service
+
        dubboutil.CopyFields(reflect.ValueOf(srv.cfg.Provider).Elem(), 
reflect.ValueOf(svc).Elem())
 
        svcOpts.exported = atomic.NewBool(false)
diff --git a/server/server.go b/server/server.go
index 0d9267891..7ffbb279e 100644
--- a/server/server.go
+++ b/server/server.go
@@ -122,6 +122,30 @@ func (s *Server) genSvcOpts(handler any, opts 
...ServiceOption) (*ServiceOptions
                        SetRegistries(regsCfg),
                )
        }
+       // Get service-level configuration items from provider.services 
configuration
+       if proCfg != nil && proCfg.Services != nil {
+               // Get the unique identifier of the handler (the default is the 
structure name or the alias set during registration)
+               interfaceName := common.GetReference(handler)
+               // Give priority to accurately finding the service 
configuration from the configuration based on the reference name (i.e. the 
handler registration name)
+               svcCfg, ok := proCfg.Services[interfaceName]
+               if !ok {
+                       //fallback: traverse matching interface fields
+                       for _, cfg := range proCfg.Services {
+                               if cfg.Interface == interfaceName {
+                                       svcCfg = cfg
+                               }
+                       }
+               }
+
+               if svcCfg != nil {
+                       svcOpts = append(svcOpts,
+                               SetService(svcCfg),
+                       )
+                       logger.Infof("Injected options from provider.services 
for %s", interfaceName)
+               } else {
+                       logger.Warnf("No matching service config found for 
[%s]", interfaceName)
+               }
+       }
        // options passed by users have higher priority
        svcOpts = append(svcOpts, opts...)
        if err := newSvcOpts.init(s, svcOpts...); err != nil {

Reply via email to