Skip to content
1 change: 1 addition & 0 deletions common/constant/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ const (
ConfigSecretKey = "config-center.secret"
ConfigBackupConfigKey = "config-center.isBackupConfig"
ConfigBackupConfigPathKey = "config-center.backupConfigPath"
ConfigRootPathParamKey = "dubbo.config-center.root-path"
)

const (
Expand Down
49 changes: 26 additions & 23 deletions config_center/apollo/impl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@ import (
"fmt"
"net/http"
"net/http/httptest"
"net/url"
"strings"
"sync"
"testing"
)

import (
"github.com/apolloconfig/agollo/v4/constant"
apolloconstant "github.com/apolloconfig/agollo/v4/constant"
"github.com/apolloconfig/agollo/v4/extension"

"github.com/knadh/koanf"
Expand All @@ -44,8 +45,9 @@ import (

import (
"dubbo.apache.org/dubbo-go/v3/common"
"dubbo.apache.org/dubbo-go/v3/config"
"dubbo.apache.org/dubbo-go/v3/common/constant"
"dubbo.apache.org/dubbo-go/v3/config_center"
"dubbo.apache.org/dubbo-go/v3/global"
"dubbo.apache.org/dubbo-go/v3/remoting"
)

Expand Down Expand Up @@ -147,56 +149,57 @@ func TestGetConfig(t *testing.T) {
configuration := initMockApollo(t)
configs, err := configuration.GetProperties(mockNamespace, config_center.WithGroup("dubbo"))
require.NoError(t, err)

koan := koanf.New(".")
err = koan.Load(rawbytes.Provider([]byte(configs)), yaml.Parser())
require.NoError(t, err)
rc := &config.RootConfig{}
err = koan.UnmarshalWithConf(rc.Prefix(), rc, koanf.UnmarshalConf{Tag: "yaml"})

appCfg := &global.ApplicationConfig{}
err = koan.UnmarshalWithConf(constant.ApplicationConfigPrefix, appCfg, koanf.UnmarshalConf{Tag: "yaml"})
require.NoError(t, err)

assert.Equal(t, "demo-server", rc.Application.Name)
assert.Equal(t, "demo-server", appCfg.Name)
}

func TestGetJsonConfig(t *testing.T) {
configuration := initMockApollo(t)
configs, err := configuration.GetProperties(mockJsonNamespace, config_center.WithGroup("dubbo"))
require.NoError(t, err)

koan := koanf.New(":")
err = koan.Load(rawbytes.Provider([]byte(configs)), json.Parser())
require.NoError(t, err)
rc := &config.RootConfig{}
err = koan.UnmarshalWithConf(rc.Prefix(), rc, koanf.UnmarshalConf{Tag: "json"})

appCfg := &global.ApplicationConfig{}
err = koan.UnmarshalWithConf("dubbo:application", appCfg, koanf.UnmarshalConf{Tag: "json"})
require.NoError(t, err)

assert.Equal(t, "demo-server", rc.Application.Name)
assert.Equal(t, "demo-server", appCfg.Name)
}

func TestGetConfigItem(t *testing.T) {
configuration := initMockApollo(t)
appName, err := configuration.GetInternalProperty("dubbo.application.name")
appName, err := configuration.GetInternalProperty(constant.ApplicationConfigPrefix + ".name")
require.NoError(t, err)
assert.Equal(t, "demo-server", appName)
}

func initMockApollo(t *testing.T) *apolloConfiguration {
// Register the YAML format parser with concurrent safety.
extension.AddFormatParser(constant.YAML, &Parser{})
extension.AddFormatParser(constant.YML, &Parser{})
c := &config.RootConfig{ConfigCenter: &config.CenterConfig{
Protocol: "apollo",
Address: "localhost:8080",
AppID: "testApplication_yang",
Cluster: "dev",
Namespace: "mockDubbogo.yaml",
Params: map[string]string{
"config-center.isBackupConfig": "false",
},
}}
extension.AddFormatParser(apolloconstant.YAML, &Parser{})
extension.AddFormatParser(apolloconstant.YML, &Parser{})

params := url.Values{}
params.Set(constant.ConfigNamespaceKey, "mockDubbogo.yaml")
params.Set(constant.ConfigAppIDKey, "testApplication_yang")
params.Set(constant.ConfigClusterKey, "dev")
params.Set(constant.ConfigBackupConfigKey, "false")

Comment thread
zbchi marked this conversation as resolved.
apollo := initApollo()
apolloUrl := strings.ReplaceAll(apollo.URL, "http", "apollo")
url, err := common.NewURL(apolloUrl, common.WithParams(c.ConfigCenter.GetUrlMap()))
apolloCfgURL, err := common.NewURL(apolloUrl, common.WithParams(params))
require.NoError(t, err)
configuration, err := newApolloConfiguration(url)
configuration, err := newApolloConfiguration(apolloCfgURL)
require.NoError(t, err)
return configuration
}
Expand Down
6 changes: 3 additions & 3 deletions config_center/zookeeper/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ type zookeeperDynamicConfiguration struct {
}

func newZookeeperDynamicConfiguration(url *common.URL) (*zookeeperDynamicConfiguration, error) {
rootPath := url.GetParam(constant.ConfigRootPathParamKey, "/dubbo/config")
c := &zookeeperDynamicConfiguration{
url: url,
// TODO adapt config center config
Comment thread
zbchi marked this conversation as resolved.
rootPath: "/dubbo/config",
url: url,
rootPath: rootPath,
}
logger.Infof("[Zookeeper ConfigCenter] New Zookeeper ConfigCenter with Configuration: %+v, url = %+v", c, c.GetURL())
if v := url.GetParam("base64", ""); v != "" {
Expand Down
18 changes: 3 additions & 15 deletions filter/polaris/limit/limiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import (
import (
"dubbo.apache.org/dubbo-go/v3/common"
"dubbo.apache.org/dubbo-go/v3/common/constant"
"dubbo.apache.org/dubbo-go/v3/config"
"dubbo.apache.org/dubbo-go/v3/protocol/base"
remotingpolaris "dubbo.apache.org/dubbo-go/v3/remoting/polaris"
"dubbo.apache.org/dubbo-go/v3/remoting/polaris/parser"
Expand Down Expand Up @@ -78,27 +77,16 @@ func (pl *polarisTpsLimiter) buildQuotaRequest(url *common.URL, invocation base.
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
if registryType := url.GetParam(constant.RegistryTypeKey, ""); registryType == constant.ServiceKey {
applicationMode = true
}
}

svc := url.Interface()
method := invocation.MethodName()
if applicationMode {
// TODO: only for compatibility with old config, able to directly remove after config is deleted
svc = config.GetApplicationConfig().Name
if applicationKey := url.GetParam(constant.ApplicationKey, ""); applicationKey != "" {
svc = applicationKey
}
svc = url.GetParam(constant.ApplicationKey, svc)
method = url.Interface() + "/" + invocation.MethodName()
}

Expand Down
Loading