You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by "xuzhijvn (via GitHub)" <gi...@apache.org> on 2025/05/11 16:39:07 UTC
[PR] feat: Add Apollo config center (#2857) [dubbo-go]
xuzhijvn opened a new pull request, #2866:
URL: https://github.com/apache/dubbo-go/pull/2866
@AlexStocks Please review code
--
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.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
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
Re: [PR] feat: Add Apollo config center (#2857) [dubbo-go]
Posted by "xuzhijvn (via GitHub)" <gi...@apache.org>.
xuzhijvn closed pull request #2866: feat: Add Apollo config center (#2857)
URL: https://github.com/apache/dubbo-go/pull/2866
--
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.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
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
Re: [PR] feat: Add Apollo config center (#2857) [dubbo-go]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #2866:
URL: https://github.com/apache/dubbo-go/pull/2866#issuecomment-2869972006
## [](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=2866) **Quality Gate passed**
Issues
 [4 New issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=2866&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=2866&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo-go&pullRequest=2866&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=2866&metric=new_coverage&view=list)
 [7.6% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=2866&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=2866)
--
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.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
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
Re: [PR] feat: Add Apollo config center (#2857) [dubbo-go]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #2866:
URL: https://github.com/apache/dubbo-go/pull/2866#discussion_r2083690691
##########
config_center/apollo/impl.go:
##########
@@ -0,0 +1,170 @@
+/*
+ * 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 apollo
+
+import (
+ "fmt"
+ "regexp"
+ "strings"
+ "sync"
+
+ "github.com/apolloconfig/agollo/v4"
+ "github.com/apolloconfig/agollo/v4/env/config"
+ gxset "github.com/dubbogo/gost/container/set"
+
+ "dubbo.apache.org/dubbo-go/v3/common"
+ "dubbo.apache.org/dubbo-go/v3/common/constant"
+ perrors "github.com/pkg/errors"
+
+ cc "dubbo.apache.org/dubbo-go/v3/config_center"
+ "dubbo.apache.org/dubbo-go/v3/config_center/parser"
+ "github.com/dubbogo/gost/log/logger"
+)
+
+const (
+ apolloProtocolPrefix = "http://"
+)
+
+type apolloConfiguration struct {
+ cc.BaseDynamicConfiguration
+ url *common.URL
+
+ listeners sync.Map
+ appConf *config.AppConfig
+ parser parser.ConfigurationParser
+ client agollo.Client
+}
+
+func newApolloConfiguration(url *common.URL) (*apolloConfiguration, error) {
+ c := &apolloConfiguration{
+ url: url,
+ }
+ c.appConf = &config.AppConfig{
+ AppID: url.GetParam(constant.ConfigAppIDKey, ""),
+ Cluster: url.GetParam(constant.ConfigClusterKey, ""),
+ NamespaceName: url.GetParam(constant.ConfigNamespaceKey, cc.DefaultGroup),
+ IP: c.getAddressWithProtocolPrefix(url),
+ Secret: url.GetParam(constant.ConfigSecretKey, ""),
+ IsBackupConfig: url.GetParamBool(constant.ConfigBackupConfigKey, true),
+ BackupConfigPath: url.GetParam(constant.ConfigBackupConfigPathKey, ""),
+ }
+ logger.Infof("[Apollo ConfigCenter] New Apollo ConfigCenter with Configuration: %+v, url = %+v", c.appConf, c.url)
+ client, err := agollo.StartWithConfig(func() (*config.AppConfig, error) {
+ return c.appConf, nil
+ })
+ if err != nil {
+ return nil, perrors.Wrap(err, "start apollo client failed")
+ }
+ c.client = client
+ return c, nil
+}
+
+func (c *apolloConfiguration) AddListener(key string, listener cc.ConfigurationListener, opts ...cc.Option) {
+ tmpOpts := cc.NewOptions(opts...)
+ key = tmpOpts.Center.Group + key
+ al := newApolloListener()
+ l, exist := c.listeners.LoadOrStore(key, al)
+ if !exist {
+ c.client.AddChangeListener(al)
+ }
+ l.(*apolloListener).AddListener(listener)
+}
+
+func (c *apolloConfiguration) RemoveListener(key string, listener cc.ConfigurationListener, opts ...cc.Option) {
+ tmpOpts := cc.NewOptions(opts...)
+ key = tmpOpts.Center.Group + key
+ l, ok := c.listeners.Load(key)
+ if ok {
+ l.(*apolloListener).RemoveListener(listener)
+ }
+}
+
+func (c *apolloConfiguration) GetInternalProperty(key string, opts ...cc.Option) (string, error) {
+ if c.client == nil {
+ return "", perrors.New("apollo client is not initialized")
+ }
+ cache := c.client.GetConfigCache(c.appConf.NamespaceName)
+ if cache == nil {
+ return "", perrors.New(fmt.Sprintf("nothing in namespace:%s ", key))
+ }
+ value, err := cache.Get(key)
+ if err != nil {
+ return "", perrors.Wrap(err, "get config value failed")
+ }
+ return value.(string), nil
+}
+
+func (c *apolloConfiguration) GetRule(key string, opts ...cc.Option) (string, error) {
+ return c.GetInternalProperty(key, opts...)
+}
+
+// PublishConfig will publish the config with the (key, group, value) pair
+func (c *apolloConfiguration) PublishConfig(string, string, string) error {
+ return perrors.New("unsupport operation")
+}
+
+// GetConfigKeysByGroup will return all keys with the group
+func (c *apolloConfiguration) GetConfigKeysByGroup(group string) (*gxset.HashSet, error) {
+ return nil, perrors.New("unsupport operation")
Review Comment:
The error message uses 'unsupport operation'; consider replacing 'unsupport' with 'unsupported'.
```suggestion
return perrors.New("unsupported operation")
}
// GetConfigKeysByGroup will return all keys with the group
func (c *apolloConfiguration) GetConfigKeysByGroup(group string) (*gxset.HashSet, error) {
return nil, perrors.New("unsupported operation")
```
##########
config_center/apollo/impl.go:
##########
@@ -0,0 +1,170 @@
+/*
+ * 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 apollo
+
+import (
+ "fmt"
+ "regexp"
+ "strings"
+ "sync"
+
+ "github.com/apolloconfig/agollo/v4"
+ "github.com/apolloconfig/agollo/v4/env/config"
+ gxset "github.com/dubbogo/gost/container/set"
+
+ "dubbo.apache.org/dubbo-go/v3/common"
+ "dubbo.apache.org/dubbo-go/v3/common/constant"
+ perrors "github.com/pkg/errors"
+
+ cc "dubbo.apache.org/dubbo-go/v3/config_center"
+ "dubbo.apache.org/dubbo-go/v3/config_center/parser"
+ "github.com/dubbogo/gost/log/logger"
+)
+
+const (
+ apolloProtocolPrefix = "http://"
+)
+
+type apolloConfiguration struct {
+ cc.BaseDynamicConfiguration
+ url *common.URL
+
+ listeners sync.Map
+ appConf *config.AppConfig
+ parser parser.ConfigurationParser
+ client agollo.Client
+}
+
+func newApolloConfiguration(url *common.URL) (*apolloConfiguration, error) {
+ c := &apolloConfiguration{
+ url: url,
+ }
+ c.appConf = &config.AppConfig{
+ AppID: url.GetParam(constant.ConfigAppIDKey, ""),
+ Cluster: url.GetParam(constant.ConfigClusterKey, ""),
+ NamespaceName: url.GetParam(constant.ConfigNamespaceKey, cc.DefaultGroup),
+ IP: c.getAddressWithProtocolPrefix(url),
+ Secret: url.GetParam(constant.ConfigSecretKey, ""),
+ IsBackupConfig: url.GetParamBool(constant.ConfigBackupConfigKey, true),
+ BackupConfigPath: url.GetParam(constant.ConfigBackupConfigPathKey, ""),
+ }
+ logger.Infof("[Apollo ConfigCenter] New Apollo ConfigCenter with Configuration: %+v, url = %+v", c.appConf, c.url)
+ client, err := agollo.StartWithConfig(func() (*config.AppConfig, error) {
+ return c.appConf, nil
+ })
+ if err != nil {
+ return nil, perrors.Wrap(err, "start apollo client failed")
+ }
+ c.client = client
+ return c, nil
+}
+
+func (c *apolloConfiguration) AddListener(key string, listener cc.ConfigurationListener, opts ...cc.Option) {
+ tmpOpts := cc.NewOptions(opts...)
+ key = tmpOpts.Center.Group + key
+ al := newApolloListener()
+ l, exist := c.listeners.LoadOrStore(key, al)
+ if !exist {
+ c.client.AddChangeListener(al)
+ }
+ l.(*apolloListener).AddListener(listener)
+}
+
+func (c *apolloConfiguration) RemoveListener(key string, listener cc.ConfigurationListener, opts ...cc.Option) {
+ tmpOpts := cc.NewOptions(opts...)
+ key = tmpOpts.Center.Group + key
+ l, ok := c.listeners.Load(key)
+ if ok {
+ l.(*apolloListener).RemoveListener(listener)
+ }
+}
+
+func (c *apolloConfiguration) GetInternalProperty(key string, opts ...cc.Option) (string, error) {
+ if c.client == nil {
+ return "", perrors.New("apollo client is not initialized")
+ }
+ cache := c.client.GetConfigCache(c.appConf.NamespaceName)
+ if cache == nil {
+ return "", perrors.New(fmt.Sprintf("nothing in namespace:%s ", key))
+ }
+ value, err := cache.Get(key)
+ if err != nil {
+ return "", perrors.Wrap(err, "get config value failed")
+ }
+ return value.(string), nil
+}
+
+func (c *apolloConfiguration) GetRule(key string, opts ...cc.Option) (string, error) {
+ return c.GetInternalProperty(key, opts...)
+}
+
+// PublishConfig will publish the config with the (key, group, value) pair
+func (c *apolloConfiguration) PublishConfig(string, string, string) error {
+ return perrors.New("unsupport operation")
+}
+
+// GetConfigKeysByGroup will return all keys with the group
+func (c *apolloConfiguration) GetConfigKeysByGroup(group string) (*gxset.HashSet, error) {
+ return nil, perrors.New("unsupport operation")
Review Comment:
The error message uses 'unsupport operation'; consider replacing 'unsupport' with 'unsupported'.
```suggestion
return perrors.New("unsupported operation")
}
// GetConfigKeysByGroup will return all keys with the group
func (c *apolloConfiguration) GetConfigKeysByGroup(group string) (*gxset.HashSet, error) {
return nil, perrors.New("unsupported operation")
```
--
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.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
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
Re: [PR] feat: Add Apollo config center (#2857) [dubbo-go]
Posted by "xuzhijvn (via GitHub)" <gi...@apache.org>.
xuzhijvn commented on PR #2866:
URL: https://github.com/apache/dubbo-go/pull/2866#issuecomment-2870466675
Need to fix the test case, closed 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.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
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