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

marsevilspirit 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 d75262830 refactor: replace `filter/polaris/limit` use of config 
package (#2947)
d75262830 is described below

commit d752628300f8013937720c28f76e9e4897390a74
Author: Xuetao Li <[email protected]>
AuthorDate: Sun Aug 17 21:01:04 2025 +0800

    refactor: replace `filter/polaris/limit` use of config package (#2947)
---
 common/constant/key.go          |  1 +
 config/registry_config.go       |  1 +
 filter/polaris/limit/limiter.go | 30 +++++++++++++++++++++---------
 registry/options.go             |  6 ++++++
 server/action.go                |  1 +
 5 files changed, 30 insertions(+), 9 deletions(-)

diff --git a/common/constant/key.go b/common/constant/key.go
index da43d9b95..b6da578bc 100644
--- a/common/constant/key.go
+++ b/common/constant/key.go
@@ -199,6 +199,7 @@ const (
        RegistrySimplifiedKey   = "simplified"
        RegistryNamespaceKey    = "registry.namespace"
        RegistryGroupKey        = "registry.group"
+       RegistryTypeKey         = "registry.type"
        RegistryTypeInterface   = "interface"
        RegistryTypeService     = "service"
        RegistryTypeAll         = "all"
diff --git a/config/registry_config.go b/config/registry_config.go
index e67233329..7c7535504 100644
--- a/config/registry_config.go
+++ b/config/registry_config.go
@@ -83,6 +83,7 @@ func (c *RegistryConfig) getUrlMap(roleType common.RoleType) 
url.Values {
        urlMap.Set(constant.RegistryKey+"."+constant.WeightKey, 
strconv.FormatInt(c.Weight, 10))
        urlMap.Set(constant.RegistryTTLKey, c.TTL)
        urlMap.Set(constant.ClientNameKey, clientNameID(c, c.Protocol, 
c.Address))
+       urlMap.Set(constant.RegistryTypeKey, c.RegistryType)
 
        for k, v := range c.Params {
                urlMap.Set(k, v)
diff --git a/filter/polaris/limit/limiter.go b/filter/polaris/limit/limiter.go
index d482aa11a..535e7d3e8 100644
--- a/filter/polaris/limit/limiter.go
+++ b/filter/polaris/limit/limiter.go
@@ -74,20 +74,32 @@ func (pl *polarisTpsLimiter) IsAllowable(url *common.URL, 
invocation base.Invoca
        return resp.Get().Code == model.QuotaResultOk
 }
 
-func (pl *polarisTpsLimiter) buildQuotaRequest(url *common.URL, invoaction 
base.Invocation) polaris.QuotaRequest {
+func (pl *polarisTpsLimiter) buildQuotaRequest(url *common.URL, invocation 
base.Invocation) polaris.QuotaRequest {
        ns := remotingpolaris.GetNamespace()
        applicationMode := false
+
+       // TODO: only for compatibility with old config, able to directly 
remove after config is deleted
        for _, item := range config.GetRootConfig().Registries {
                if item.Protocol == constant.PolarisKey {
                        applicationMode = item.RegistryType == 
constant.ServiceKey
                }
        }
 
+       if url.GetParam(constant.RegistryKey, "") == constant.PolarisKey {
+               if registryType := url.GetParam(constant.RegistryTypeKey, ""); 
registryType != "" {
+                       applicationMode = registryType == constant.ServiceKey
+               }
+       }
+
        svc := url.Interface()
-       method := invoaction.MethodName()
+       method := invocation.MethodName()
        if applicationMode {
+               // TODO: only for compatibility with old config, able to 
directly remove after config is deleted
                svc = config.GetApplicationConfig().Name
-               method = url.Interface() + "/" + invoaction.MethodName()
+               if applicationKey := url.GetParam(constant.ApplicationKey, ""); 
applicationKey != "" {
+                       svc = applicationKey
+               }
+               method = url.Interface() + "/" + invocation.MethodName()
        }
 
        req := polaris.NewQuotaRequest()
@@ -95,19 +107,19 @@ func (pl *polarisTpsLimiter) buildQuotaRequest(url 
*common.URL, invoaction base.
        req.SetService(svc)
        req.SetMethod(method)
 
-       matchs, ok := pl.buildArguments(req.(*model.QuotaRequestImpl))
+       matches, ok := pl.buildArguments(req.(*model.QuotaRequestImpl))
        if !ok {
                return nil
        }
 
-       attachement := invoaction.Attachments()
-       arguments := invoaction.Arguments()
+       attachment := invocation.Attachments()
+       arguments := invocation.Arguments()
 
-       for i := range matchs {
-               item := matchs[i]
+       for i := range matches {
+               item := matches[i]
                switch item.GetType() {
                case v1.MatchArgument_HEADER:
-                       if val, ok := attachement[item.GetKey()]; ok {
+                       if val, ok := attachment[item.GetKey()]; ok {
                                
req.AddArgument(model.BuildHeaderArgument(item.GetKey(), fmt.Sprintf("%+v", 
val)))
                        }
                case v1.MatchArgument_QUERY:
diff --git a/registry/options.go b/registry/options.go
index b96e632bb..f9be163f9 100644
--- a/registry/options.go
+++ b/registry/options.go
@@ -188,6 +188,12 @@ func WithRegisterInterface() Option {
        }
 }
 
+func WithRegisterService() Option {
+       return func(opts *Options) {
+               opts.Registry.RegistryType = constant.RegistryTypeService
+       }
+}
+
 func WithoutUseAsMetaReport() Option {
        return func(opts *Options) {
                opts.Registry.UseAsMetaReport = "false"
diff --git a/server/action.go b/server/action.go
index c43bb7d63..be33fb819 100644
--- a/server/action.go
+++ b/server/action.go
@@ -284,6 +284,7 @@ func (svcOpts *ServiceOptions) generatorInvoker(url 
*common.URL, info *common.Se
 // setRegistrySubURL set registry sub url is ivkURl
 func setRegistrySubURL(ivkURL *common.URL, regUrl *common.URL) {
        ivkURL.AddParam(constant.RegistryKey, 
regUrl.GetParam(constant.RegistryKey, ""))
+       ivkURL.AddParam(constant.RegistryTypeKey, 
regUrl.GetParam(constant.RegistryTypeKey, ""))
        regUrl.SubURL = ivkURL
 }
 

Reply via email to