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/05/25 07:07:38 UTC

[GitHub] [servicecomb-service-center] little-cui commented on a diff in pull request #1302: [feat] Added whitelist function in synchronization

little-cui commented on code in PR #1302:
URL: https://github.com/apache/servicecomb-service-center/pull/1302#discussion_r878655709


##########
datasource/etcd/ms.go:
##########
@@ -945,11 +942,20 @@ func (ds *MetadataManager) SendManyHeartbeat(ctx context.Context, request *pb.He
 	for heartbeat := range instancesHbRst {
 		count++
 		instanceHbRstArr = append(instanceHbRstArr, heartbeat)
+		// heartbeat sent successfully service should exist
+		microservice, _ := eutil.GetService(ctx, domainProject, heartbeat.ServiceId)
+		// If the synchronization is not in the whitelist, it will be set to fail
+		if !svc.EnableSync(microservice.ServiceName) {
+			util.SetContext(ctx, util.CtxEnableSync, "0")
+		}
 		sendEvent(ctx, sync.UpdateAction, datasource.ResourceHeartbeat,
 			&pb.HeartbeatRequest{ServiceId: heartbeat.ServiceId, InstanceId: heartbeat.InstanceId})
 		if count == noMultiCounter {
 			close(instancesHbRst)
 		}
+		if config.GetBool("sync.enableOnStart", false) {
+			util.SetContext(ctx, util.CtxEnableSync, "1")
+		}

Review Comment:
   这里增加sync ctx设置的原因是?sync ctx是接口进入才会被设置



##########
datasource/etcd/ms.go:
##########
@@ -945,11 +942,20 @@ func (ds *MetadataManager) SendManyHeartbeat(ctx context.Context, request *pb.He
 	for heartbeat := range instancesHbRst {
 		count++
 		instanceHbRstArr = append(instanceHbRstArr, heartbeat)
+		// heartbeat sent successfully service should exist
+		microservice, _ := eutil.GetService(ctx, domainProject, heartbeat.ServiceId)
+		// If the synchronization is not in the whitelist, it will be set to fail
+		if !svc.EnableSync(microservice.ServiceName) {

Review Comment:
   方法扩展性不好,如果后续有更多过滤项怎么处理?



##########
server/service/disco/metadata.go:
##########
@@ -282,3 +298,25 @@ func ServiceUsage(ctx context.Context, request *pb.GetServiceCountRequest) (int6
 	}
 	return resp.Count, nil
 }
+
+// IsInWhiteList implement:
+// 1.Check if the service exists
+// 2.Check if the service is in the whitelist
+func IsInWhiteList(ctx context.Context, serviceID string, remoteIP string) error {

Review Comment:
   remoteIP可以不传,通过ctx获取



##########
etc/conf/syncer.yaml:
##########
@@ -3,11 +3,24 @@ sync:
   peers:
     - name: dc
       kind: servicecomb
-      endpoints: ["127.0.0.1:30105"]
+      endpoints: [ "127.0.0.1:30105" ]
       # only allow mode implemented in incremental approach like push, watch(such as pub/sub, long polling)
-      mode: [push]
+      mode: [ push ]
   tombstone:
     retire:
       # use linux crontab not Quartz cron
       cron:
-      reserve: 24h
\ No newline at end of file
+      reserve: 24h
+  whitelist:

Review Comment:
   默认是否开启,如果开启,应注释掉,避免影响正常场景



-- 
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