Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

register not use metadata configuration. #1565

Merged
merged 7 commits into from
Nov 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cluster/cluster/zoneaware/cluster_interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type interceptor struct {
}

func (z *interceptor) Invoke(ctx context.Context, invoker protocol.Invoker, invocation protocol.Invocation) protocol.Result {
key := constant.RegistryKey + "." + constant.ZoneForceKey
key := constant.RegistryKey + "." + constant.RegistryZoneForceKey
force := ctx.Value(key)

if force != nil {
Expand Down
4 changes: 2 additions & 2 deletions cluster/cluster/zoneaware/cluster_invoker.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (invoker *clusterInvoker) Invoke(ctx context.Context, invocation protocol.I
}

// providers in the registry with the same zone
key := constant.RegistryKey + "." + constant.ZoneKey
key := constant.RegistryKey + "." + constant.RegistryZoneKey
zone := invocation.AttachmentsByKey(key, "")
if "" != zone {
for _, invoker := range invokers {
Expand All @@ -73,7 +73,7 @@ func (invoker *clusterInvoker) Invoke(ctx context.Context, invocation protocol.I
}
}

force := invocation.AttachmentsByKey(constant.RegistryKey+"."+constant.ZoneForceKey, "")
force := invocation.AttachmentsByKey(constant.RegistryKey+"."+constant.RegistryZoneForceKey, "")
if "true" == force {
return &protocol.RPCResult{
Err: fmt.Errorf("no registry instance in zone or "+
Expand Down
12 changes: 6 additions & 6 deletions cluster/cluster/zoneaware/cluster_invoker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,15 @@ func TestZoneWareInvokerWithZoneSuccess(t *testing.T) {
for i := 0; i < 2; i++ {
zoneValue := zoneArray[i]
url, _ := common.NewURL(fmt.Sprintf("dubbo://192.168.1.%v:20000/com.ikurento.user.UserProvider", i))
url.SetParam(constant.RegistryKey+"."+constant.ZoneKey, zoneValue)
url.SetParam(constant.RegistryKey+"."+constant.RegistryZoneKey, zoneValue)

invoker := mock.NewMockInvoker(ctrl)
invoker.EXPECT().IsAvailable().Return(true).AnyTimes()
invoker.EXPECT().GetUrl().Return(url).AnyTimes()
invoker.EXPECT().Invoke(gomock.Any()).DoAndReturn(
func(invocation protocol.Invocation) protocol.Result {
return &protocol.RPCResult{
Attrs: map[string]interface{}{constant.ZoneKey: zoneValue},
Attrs: map[string]interface{}{constant.RegistryZoneKey: zoneValue},
Rest: clusterpkg.Rest{Tried: 0, Success: true},
}
})
Expand All @@ -177,11 +177,11 @@ func TestZoneWareInvokerWithZoneSuccess(t *testing.T) {
inv := &invocation.RPCInvocation{}
// zone hangzhou
hz := zoneArray[0]
inv.SetAttachments(constant.RegistryKey+"."+constant.ZoneKey, hz)
inv.SetAttachments(constant.RegistryKey+"."+constant.RegistryZoneKey, hz)

result := clusterInvoker.Invoke(context.Background(), inv)

assert.Equal(t, hz, result.Attachment(constant.ZoneKey, ""))
assert.Equal(t, hz, result.Attachment(constant.RegistryZoneKey, ""))
}

func TestZoneWareInvokerWithZoneForceFail(t *testing.T) {
Expand All @@ -206,9 +206,9 @@ func TestZoneWareInvokerWithZoneForceFail(t *testing.T) {

inv := &invocation.RPCInvocation{}
// zone hangzhou
inv.SetAttachments(constant.RegistryKey+"."+constant.ZoneKey, "hangzhou")
inv.SetAttachments(constant.RegistryKey+"."+constant.RegistryZoneKey, "hangzhou")
// zone force
inv.SetAttachments(constant.RegistryKey+"."+constant.ZoneForceKey, "true")
inv.SetAttachments(constant.RegistryKey+"."+constant.RegistryZoneForceKey, "true")

result := clusterInvoker.Invoke(context.Background(), inv)

Expand Down
2 changes: 1 addition & 1 deletion cluster/router/v3router/router_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func NewUniformRouterChain() (router.PriorityRouter, error) {
rootConfig := config.GetRootConfig()
dynamicConfiguration := conf.GetEnvInstance().GetDynamicConfiguration()
if dynamicConfiguration == nil {
logger.Infof("Config center does not start, please check if the configuration center has been properly configured in dubbogo.yml")
logger.Infof("[Mesh Router] Config center does not start, please check if the configuration center has been properly configured in dubbogo.yml")
return nil, nil
}
dynamicConfiguration.AddListener(rootConfig.Application.Name, r)
Expand Down
75 changes: 46 additions & 29 deletions common/constant/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,20 +122,34 @@ const (
DubboGoCtxKey = DubboCtxKey("dubbogo-ctx")
)

// metadata report keys
const (
MetadataReportNamespaceKey = "metadata-report.namespace"
MetadataReportGroupKey = "metadata-report.group"
MetadataReportUsernameKey = "metadata-report.username"
MetadataReportPasswordKey = "metadata-report.password"
MetadataReportProtocolKey = "metadata-report.protocol"
)

// registry keys
const (
RegistryKey = "registry"
RegistryProtocol = "registry"
ServiceRegistryProtocol = "service-discovery-registry"
RoleKey = "registry.role"
RegistryRoleKey = "registry.role"
RegistryDefaultKey = "registry.default"
RegistryUsernameKey = "registry.username"
RegistryPasswordKey = "registry.password"
RegistryAccessKey = "registry.accesskey"
RegistrySecretKey = "registry.secretkey"
RegistryTimeoutKey = "registry.timeout"
RegistryLabelKey = "label"
PreferredKey = "preferred"
ZoneKey = "zone"
ZoneForceKey = "zone.force"
RegistryZoneKey = "zone"
RegistryZoneForceKey = "zone.force"
RegistryTTLKey = "registry.ttl"
SimplifiedKey = "simplified"
NamespaceKey = "namespace"
RegistrySimplifiedKey = "simplified"
RegistryNamespaceKey = "registry.namespace"
RegistryGroupKey = "registry.group"
)

Expand All @@ -161,20 +175,22 @@ const (
ExportKey = "export"
)

// config center keys
const (
ConfigNamespaceKey = "namespace"
ConfigGroupKey = "group"
ConfigAppIDKey = "appId"
ConfigClusterKey = "cluster"
ConfigTimeoutKey = "timeout"
ConfigUsernameKey = "username"
ConfigPasswordKey = "password"
ConfigLogDirKey = "logDir"
ConfigVersionKey = "configVersion"
CompatibleConfigKey = "compatible_config"
ConfigSecretKey = "secret"
ConfigBackupConfigKey = "isBackupConfig"
ConfigBackupConfigPathKey = "backupConfigPath"
ConfigNamespaceKey = "config-center.namespace"
ConfigGroupKey = "config-center.group"
ConfigAppIDKey = "config-center.appId"
ConfigClusterKey = "config-center.cluster"
ConfigTimeoutKey = "config-center.timeout"
ConfigUsernameKey = "config-center.username"
ConfigAccessKey = "config-center.access"
ConfigPasswordKey = "config-center.password"
ConfigLogDirKey = "config-center.logDir"
ConfigVersionKey = "config-center.configVersion"
CompatibleConfigKey = "config-center.compatible_config"
ConfigSecretKey = "config-center.secret"
ConfigBackupConfigKey = "config-center.isBackupConfig"
ConfigBackupConfigPathKey = "config-center.backupConfigPath"
)

const (
Expand Down Expand Up @@ -202,26 +218,27 @@ const (

const (
NacosKey = "nacos"
NacosGroupKey = "nacos.group"
NacosDefaultRoleType = 3
NacosCacheDirKey = "cacheDir"
NacosLogDirKey = "logDir"
NacosBeatIntervalKey = "beatInterval"
NacosCacheDirKey = "nacos.cacheDir"
NacosLogDirKey = "nacos.logDir"
NacosBeatIntervalKey = "nacos.beatInterval"
NacosEndpoint = "endpoint"
NacosServiceNameSeparator = ":"
NacosCategoryKey = "category"
NacosCategoryKey = "nacos.category"
NacosProtocolKey = "protocol"
NacosPathKey = "path"
NacosNamespaceID = "namespaceId"
NacosPassword = "password"
NacosUsername = "username"
NacosNamespaceID = "nacos.namespaceId"
NacosNotLoadLocalCache = "nacos.not.load.cache"
NacosAppNameKey = "appName"
NacosRegionIDKey = "regionId"
NacosAccessKey = "access"
NacosSecretKey = "secret"
NacosRegionIDKey = "nacos.regionId"
NacosAccessKey = "nacos.access"
NacosSecretKey = "nacos.secret"
NacosOpenKmsKey = "kms"
NacosUpdateThreadNumKey = "updateThreadNum"
NacosLogLevelKey = "logLevel"
NacosLogLevelKey = "nacos.logLevel"
NacosUsername = "nacos.username"
NacosPassword = "nacos.password"
)

const (
Expand Down
11 changes: 7 additions & 4 deletions common/extension/service_discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,29 @@ import (
)

import (
"dubbo.apache.org/dubbo-go/v3/common"
"dubbo.apache.org/dubbo-go/v3/common/constant"
"dubbo.apache.org/dubbo-go/v3/registry"
)

var discoveryCreatorMap = make(map[string]func() (registry.ServiceDiscovery, error), 4)
var discoveryCreatorMap = make(map[string]func(url *common.URL) (registry.ServiceDiscovery, error), 4)

// SetServiceDiscovery will store the @creator and @name
// protocol indicate the implementation, like nacos
// the name like nacos-1...
func SetServiceDiscovery(protocol string, creator func() (registry.ServiceDiscovery, error)) {
func SetServiceDiscovery(protocol string, creator func(url *common.URL) (registry.ServiceDiscovery, error)) {
discoveryCreatorMap[protocol] = creator
}

// GetServiceDiscovery will return the registry.ServiceDiscovery
// protocol indicate the implementation, like nacos
// the name like nacos-1...
// if not found, or initialize instance failed, it will return error.
func GetServiceDiscovery(protocol string) (registry.ServiceDiscovery, error) {
func GetServiceDiscovery(url *common.URL) (registry.ServiceDiscovery, error) {
protocol := url.GetParam(constant.RegistryKey, "")
creator, ok := discoveryCreatorMap[protocol]
if !ok {
return nil, perrors.New("Could not find the service discovery with discovery protocol: " + protocol)
}
return creator()
return creator(url)
}
10 changes: 3 additions & 7 deletions common/rpc_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,13 +377,9 @@ func suiteMethod(method reflect.Method) *MethodType {
argsType []reflect.Type
)

// this method is in RPCService
// we force users must implement RPCService interface in their provider
// and RPCService has only one method "Reference"
// In general, this method should not be exported to client
// so we ignore this method
// see RPCService
if mname == "Reference" {
// Reference is used to define service reference, and method with prefix 'XXX' is generated by triple pb tool
// They should not to be exported
if mname == "Reference" || strings.HasPrefix(mname, "XXX") {
return nil
}

Expand Down
13 changes: 9 additions & 4 deletions config/config_center_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ type CenterConfig struct {
Address string `validate:"required" yaml:"address" json:"address,omitempty"`
DataId string `yaml:"data-id" json:"data-id,omitempty"`
Cluster string `yaml:"cluster" json:"cluster,omitempty"`
Group string `default:"dubbo" yaml:"group" json:"group,omitempty"`
Group string `yaml:"group" json:"group,omitempty"`
Username string `yaml:"username" json:"username,omitempty"`
Password string `yaml:"password" json:"password,omitempty"`
Namespace string `default:"dubbo" yaml:"namespace" json:"namespace,omitempty"`
Namespace string `yaml:"namespace" json:"namespace,omitempty"`
AppID string `default:"dubbo" yaml:"app-id" json:"app-id,omitempty"`
Timeout string `default:"10s" yaml:"timeout" json:"timeout,omitempty"`
Params map[string]string `yaml:"params" json:"parameters,omitempty"`
Expand Down Expand Up @@ -132,13 +132,18 @@ func startConfigCenter(rc *RootConfig) error {
cc := rc.ConfigCenter
dynamicConfig, err := cc.GetDynamicConfiguration()
if err != nil {
logger.Errorf("Start dynamic configuration center error, error message is %v", err)
logger.Errorf("[Config Center] Start dynamic configuration center error, error message is %v", err)
return err
}

strConf, err := dynamicConfig.GetProperties(cc.DataId, config_center.WithGroup(cc.Group))
if err != nil {
logger.Warnf("Dynamic onfig center has started, but config may not be initialized, because %s", err)
logger.Warnf("[Config Center] Dynamic config center has started, but config may not be initialized, because: %s", err)
return nil
}
if len(strConf) == 0 {
logger.Warnf("[Config Center] Dynamic config center has started, but got empty config with config-center configuration %+v\n"+
"Please check if your config-center config is correct.", cc)
return nil
}
koan := koanf.New(".")
Expand Down
15 changes: 9 additions & 6 deletions config/metadata_report_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@ import (

// MetadataReportConfig is app level configuration
type MetadataReportConfig struct {
Protocol string `required:"true" yaml:"protocol" json:"protocol,omitempty"`
Address string `required:"true" yaml:"address" json:"address"`
Username string `yaml:"username" json:"username,omitempty"`
Password string `yaml:"password" json:"password,omitempty"`
Timeout string `yaml:"timeout" json:"timeout,omitempty"`
Group string `yaml:"group" json:"group,omitempty"`
Protocol string `required:"true" yaml:"protocol" json:"protocol,omitempty"`
Address string `required:"true" yaml:"address" json:"address"`
Username string `yaml:"username" json:"username,omitempty"`
Password string `yaml:"password" json:"password,omitempty"`
Timeout string `yaml:"timeout" json:"timeout,omitempty"`
Group string `yaml:"group" json:"group,omitempty"`
Namespace string `yaml:"namespace" json:"namespace,omitempty"`
// metadataType of this application is defined by application config, local or remote
metadataType string
}
Expand All @@ -60,6 +61,8 @@ func (mc *MetadataReportConfig) ToUrl() (*common.URL, error) {
common.WithPassword(mc.Password),
common.WithLocation(mc.Address),
common.WithProtocol(mc.Protocol),
common.WithParamsValue(constant.MetadataReportGroupKey, mc.Group),
common.WithParamsValue(constant.MetadataReportNamespaceKey, mc.Namespace),
common.WithParamsValue(constant.MetadataTypeKey, mc.metadataType),
)
if err != nil || len(res.Protocol) == 0 {
Expand Down
4 changes: 2 additions & 2 deletions config/reference_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ type ReferenceConfig struct {
Check *bool `yaml:"check" json:"check,omitempty" property:"check"`
URL string `yaml:"url" json:"url,omitempty" property:"url"`
Filter string `yaml:"filter" json:"filter,omitempty" property:"filter"`
Protocol string `default:"dubbo" yaml:"protocol" json:"protocol,omitempty" property:"protocol"`
Protocol string `default:"tri" yaml:"protocol" json:"protocol,omitempty" property:"protocol"`
RegistryIDs []string `yaml:"registry-ids" json:"registry-ids,omitempty" property:"registry-ids"`
Cluster string `yaml:"cluster" json:"cluster,omitempty" property:"cluster"`
Loadbalance string `yaml:"loadbalance" json:"loadbalance,omitempty" property:"loadbalance"`
Expand Down Expand Up @@ -241,7 +241,7 @@ func (rc *ReferenceConfig) getURLMap() url.Values {
urlMap.Set(constant.GroupKey, rc.Group)
urlMap.Set(constant.VersionKey, rc.Version)
urlMap.Set(constant.GenericKey, rc.Generic)
urlMap.Set(constant.RoleKey, strconv.Itoa(common.CONSUMER))
urlMap.Set(constant.RegistryRoleKey, strconv.Itoa(common.CONSUMER))
urlMap.Set(constant.ProvidedBy, rc.ProvidedBy)
urlMap.Set(constant.SerializationKey, rc.Serialization)

Expand Down
11 changes: 5 additions & 6 deletions config/registry_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ func (c *RegistryConfig) Init() error {

func (c *RegistryConfig) getUrlMap(roleType common.RoleType) url.Values {
urlMap := url.Values{}
urlMap.Set(constant.GroupKey, c.Group)
urlMap.Set(constant.RoleKey, strconv.Itoa(int(roleType)))
urlMap.Set(constant.RegistryGroupKey, c.Group)
urlMap.Set(constant.RegistryRoleKey, strconv.Itoa(int(roleType)))
urlMap.Set(constant.RegistryKey, c.Protocol)
urlMap.Set(constant.RegistryTimeoutKey, c.Timeout)
// multi registry invoker weight label for load balance
urlMap.Set(constant.RegistryKey+"."+constant.RegistryLabelKey, strconv.FormatBool(true))
urlMap.Set(constant.RegistryKey+"."+constant.PreferredKey, strconv.FormatBool(c.Preferred))
urlMap.Set(constant.RegistryKey+"."+constant.ZoneKey, c.Zone)
urlMap.Set(constant.RegistryKey+"."+constant.RegistryZoneKey, c.Zone)
urlMap.Set(constant.RegistryKey+"."+constant.WeightKey, strconv.FormatInt(c.Weight, 10))
urlMap.Set(constant.RegistryTTLKey, c.TTL)
for k, v := range c.Params {
Expand Down Expand Up @@ -127,10 +127,9 @@ func (c *RegistryConfig) toURL(roleType common.RoleType) (*common.URL, error) {
}
return common.NewURL(registryURLProtocol+"://"+address,
common.WithParams(c.getUrlMap(roleType)),
common.WithParamsValue(constant.SimplifiedKey, strconv.FormatBool(c.Simplified)),
common.WithParamsValue(constant.RegistrySimplifiedKey, strconv.FormatBool(c.Simplified)),
common.WithParamsValue(constant.RegistryKey, c.Protocol),
common.WithParamsValue(constant.GroupKey, c.Group),
common.WithParamsValue(constant.NamespaceKey, c.Namespace),
common.WithParamsValue(constant.RegistryNamespaceKey, c.Namespace),
common.WithUsername(c.Username),
common.WithPassword(c.Password),
common.WithLocation(c.Address),
Expand Down
3 changes: 2 additions & 1 deletion config/root_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ func (rc *RootConfig) Init() error {
return err
}
if err := rc.ConfigCenter.Init(rc); err != nil {
logger.Infof("Config center doesn't start,because %s", err)
logger.Infof("[Config Center] Config center doesn't start")
logger.Debugf("config center doesn't start because %s", err)
} else {
if err := rc.Logger.Init(); err != nil { // init logger using config from config center again
return err
Expand Down
Loading