You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by GitBox <gi...@apache.org> on 2022/01/13 07:02:08 UTC

[GitHub] [servicecomb-service-center] xiaoluoluo opened a new pull request #1220: [feat] add engine info to instance

xiaoluoluo opened a new pull request #1220:
URL: https://github.com/apache/servicecomb-service-center/pull/1220


   【issue】#1219
   【修改内容】:配置中增加实例的引擎信息,注册实例的时候加上配置的引擎信息
   【修改原因】:增加引擎信息到实例中去
   【影响范围】:无
   【额外说明】:无
   【测试用例】:无
   


-- 
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: commits-unsubscribe@servicecomb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [servicecomb-service-center] little-cui commented on a change in pull request #1220: [feat] add engine info to instance

Posted by GitBox <gi...@apache.org>.
little-cui commented on a change in pull request #1220:
URL: https://github.com/apache/servicecomb-service-center/pull/1220#discussion_r783709225



##########
File path: server/service/disco/instance.go
##########
@@ -39,6 +39,8 @@ import (
 const (
 	defaultMinInterval = 5 * time.Second
 	defaultMinTimes    = 3
+	engineID           = "engineID"
+	engineName         = "engineName"

Review comment:
       注册逻辑不应该感知具体的properties,应该将配置中的properties下全量内容append到实例信息中,具体可以这样:
   在server/config包下util.go增加一个
   ```go
   // 只支持最后一层是map结构的配置获取,内层实现是通过archaius.GetConfigs() 遍历
   func GetMap(key, def) map[string]string
   ```




-- 
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: commits-unsubscribe@servicecomb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [servicecomb-service-center] little-cui commented on a change in pull request #1220: [feat] add engine info to instance

Posted by GitBox <gi...@apache.org>.
little-cui commented on a change in pull request #1220:
URL: https://github.com/apache/servicecomb-service-center/pull/1220#discussion_r784654801



##########
File path: server/config/util_test.go
##########
@@ -36,3 +37,21 @@ func TestGetString(t *testing.T) {
 	assert.Equal(t, "test", config.GetString("test.getString", "none"))
 	assert.Equal(t, "test", config.GetString("other.getString", "none", config.WithENV("TEST_GET_STRING")))
 }
+
+func TestGetStringMap(t *testing.T) {
+	changeConfigPath()
+	os.Setenv("TEST_GET_STRING", "test")
+	defer archaius.Clean()
+	archaius.Init(archaius.WithMemorySource(), archaius.WithENVSource(),
+		archaius.WithOptionalFiles([]string{filepath.Join(util.GetAppRoot(), "conf", "app.yaml")}))
+
+	maps := config.GetStringMap("registry.schema")
+	assert.NotEqual(t, 0, len(maps))

Review comment:
       缺少用例:
   1、获取一个不存在的配置
   2、获取一个相同前缀的配置,如:实际配置是a.b.c和a.bb.c,测试config.GetStringMap("a.b")
   3、获取一个非最后一层的配置,如:实际是a.b.c,测试config.GetStringMap("a")
   4、获取一个非string map类型的配置,如:实际配置如下,测试config.GetStringMap("a.b")
   ```yaml
   a:
     b:
      - c
      - d
   ```

##########
File path: server/config/util.go
##########
@@ -89,6 +90,28 @@ func GetInt64(key string, def int64, opts ...Option) int64 {
 	return beego.AppConfig.DefaultInt64(options.Standby, def)
 }
 
+func GetStringMap(key string) map[string]string {
+	result := make(map[string]string)
+	getMapFunc(key, func(k string, value interface{}) {
+		result[k] = cast.ToString(value)
+	})
+	return result
+}
+
+func getMapFunc(key string, dataFunc func(k string, v interface{})) {
+	configs := archaius.GetConfigs()
+	for k, v := range configs {
+		if !strings.HasPrefix(k, key) {
+			continue
+		}
+		keys := strings.Split(k, key+".")
+		if len(keys) <= 1 {
+			continue
+		}
+		dataFunc(keys[len(keys)-1], v)

Review comment:
       len(keys)抽取局部变量




-- 
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: commits-unsubscribe@servicecomb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [servicecomb-service-center] little-cui commented on a change in pull request #1220: [feat] add engine info to instance

Posted by GitBox <gi...@apache.org>.
little-cui commented on a change in pull request #1220:
URL: https://github.com/apache/servicecomb-service-center/pull/1220#discussion_r783901782



##########
File path: server/config/util.go
##########
@@ -89,6 +89,28 @@ func GetInt64(key string, def int64, opts ...Option) int64 {
 	return beego.AppConfig.DefaultInt64(options.Standby, def)
 }
 
+func GetValueStringMap(key string) map[string]string {
+	result := make(map[string]string)
+	getMapFunc(key, func(k string, value interface{}) {
+		result[k] = value.(string)
+	})
+	return result
+}
+
+func getMapFunc(key string, dataFunc func(k string, v interface{})) {
+	configs := archaius.GetConfigs()
+	for k, v := range configs {
+		if !strings.HasPrefix(k, key) {

Review comment:
       1、补充UT
   2、这里场景漏考虑,需要key+'.'

##########
File path: server/config/util.go
##########
@@ -89,6 +89,28 @@ func GetInt64(key string, def int64, opts ...Option) int64 {
 	return beego.AppConfig.DefaultInt64(options.Standby, def)
 }
 
+func GetValueStringMap(key string) map[string]string {

Review comment:
       保持风格一致,叫GetStringMap即可

##########
File path: etc/conf/app.yaml
##########
@@ -148,6 +148,9 @@ registry:
       name:
       region:
       availableZone:
+    properties:
+      engineID:
+      engineName:

Review comment:
       1、删掉engineXXX配置,开源不需要默认
   2、为properties配置增加注释,说明用途

##########
File path: server/service/disco/instance.go
##########
@@ -97,9 +97,28 @@ func populateInstanceDefaultValue(ctx context.Context, instance *pb.MicroService
 		return pb.NewError(pb.ErrServiceNotExists, "Invalid 'serviceID' in request body.")
 	}
 	instance.Version = microservice.Version
+
+	setPropertiesToInstance(instance)
 	return nil
 }
 
+func setPropertiesToInstance(instance *pb.MicroServiceInstance) {
+	if instance.Properties == nil {
+		instance.Properties = make(map[string]string)
+	}
+
+	propertiesMap := config.GetValueStringMap("registry.instance.properties")

Review comment:
       放到init()中,作为私有全局变量,避免每次都要遍历一遍,影响注册性能

##########
File path: server/service/disco/instance.go
##########
@@ -97,9 +97,28 @@ func populateInstanceDefaultValue(ctx context.Context, instance *pb.MicroService
 		return pb.NewError(pb.ErrServiceNotExists, "Invalid 'serviceID' in request body.")
 	}
 	instance.Version = microservice.Version
+
+	setPropertiesToInstance(instance)
 	return nil
 }
 
+func setPropertiesToInstance(instance *pb.MicroServiceInstance) {
+	if instance.Properties == nil {
+		instance.Properties = make(map[string]string)
+	}
+
+	propertiesMap := config.GetValueStringMap("registry.instance.properties")
+	if len(propertiesMap) <= 0 {
+		return
+	}
+
+	for k, v := range propertiesMap {
+		if _, ok := instance.Properties[k]; !ok || len(v) > 0 {
+			instance.Properties[k] = v

Review comment:
       不需要判断v是否有内容,没有KEY场景则应该直接覆盖

##########
File path: server/service/disco/instance.go
##########
@@ -97,9 +97,28 @@ func populateInstanceDefaultValue(ctx context.Context, instance *pb.MicroService
 		return pb.NewError(pb.ErrServiceNotExists, "Invalid 'serviceID' in request body.")
 	}
 	instance.Version = microservice.Version
+
+	setPropertiesToInstance(instance)

Review comment:
       补充此场景的UT




-- 
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: commits-unsubscribe@servicecomb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [servicecomb-service-center] little-cui commented on a change in pull request #1220: [feat] add engine info to instance

Posted by GitBox <gi...@apache.org>.
little-cui commented on a change in pull request #1220:
URL: https://github.com/apache/servicecomb-service-center/pull/1220#discussion_r783709225



##########
File path: server/service/disco/instance.go
##########
@@ -39,6 +39,8 @@ import (
 const (
 	defaultMinInterval = 5 * time.Second
 	defaultMinTimes    = 3
+	engineID           = "engineID"
+	engineName         = "engineName"

Review comment:
       注册逻辑不应该感知具体的properties,应该将配置中的properties下全量内容append到实例信息中




-- 
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: commits-unsubscribe@servicecomb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [servicecomb-service-center] little-cui commented on a change in pull request #1220: [feat] add engine info to instance

Posted by GitBox <gi...@apache.org>.
little-cui commented on a change in pull request #1220:
URL: https://github.com/apache/servicecomb-service-center/pull/1220#discussion_r784649860



##########
File path: server/service/disco/instance_test.go
##########
@@ -384,6 +385,22 @@ func TestRegisterInstance(t *testing.T) {
 		assert.Error(t, testErr)
 		assert.Equal(t, pb.ErrInvalidParams, testErr.Code)
 	})
+
+	t.Run(" register properties info to instance, should be passed", func(t *testing.T) {
+		instance := &pb.MicroServiceInstance{
+			ServiceId: serviceId1,
+			Endpoints: []string{
+				"sameInstance:127.0.0.1:8080",
+			},
+			HostName: "UT-HOST",
+			Status:   pb.MSI_UP,
+		}
+		_, err := discosvc.RegisterInstance(ctx, &pb.RegisterInstanceRequest{
+			Instance: instance,
+		})
+		assert.NoError(t, err)
+		assert.Equal(t, 2, len(instance.Properties))

Review comment:
       一、断言不准确:需要明确具体properties的值是否等于预期值
   二、缺少用例:
   1、用户注册有自定义properties,预期结果
   2、用户注册与系统配置相同的properties,预期结果
   




-- 
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: commits-unsubscribe@servicecomb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [servicecomb-service-center] little-cui merged pull request #1220: [feat] add engine info to instance

Posted by GitBox <gi...@apache.org>.
little-cui merged pull request #1220:
URL: https://github.com/apache/servicecomb-service-center/pull/1220


   


-- 
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: commits-unsubscribe@servicecomb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org