丁云鹏 1 rok temu
rodzic
commit
91ac3009e5

+ 5 - 0
recommend-server-service/pom.xml

@@ -216,6 +216,11 @@
             <groupId>org.mongodb</groupId>
             <artifactId>mongodb-driver-sync</artifactId>
         </dependency>
+        <dependency>
+            <groupId>com.tzld.piaoquan</groupId>
+            <artifactId>abtest-client</artifactId>
+            <version>1.0.0</version>
+        </dependency>
     </dependencies>
 
 

+ 6 - 0
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/Application.java

@@ -2,6 +2,7 @@ package com.tzld.piaoquan.recommend.server;
 
 // import com.tzld.piaoquan.recommend.feature.client.FeatureClient;
 
+import com.tzld.piaoquan.abtest.client.ABTestClient;
 import com.tzld.piaoquan.recommend.feature.client.FeatureClient;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
@@ -44,6 +45,11 @@ public class Application {
         return new FeatureClient();
     }
 
+    @Bean
+    public ABTestClient abTestClient() {
+        return new ABTestClient();
+    }
+
     @Bean
     public ProtobufHttpMessageConverter protobufHttpMessageConverter() {
         return new ProtobufHttpMessageConverter();

+ 36 - 0
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/remote/ABTestRemoteService.java

@@ -0,0 +1,36 @@
+package com.tzld.piaoquan.recommend.server.remote;
+
+import com.tzld.piaoquan.abtest.client.ABTestClient;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.Map;
+
+
+/**
+ * @author dyp
+ */
+@Component
+@Slf4j
+public class ABTestRemoteService {
+
+    @Autowired
+    private ABTestClient client;
+
+    public String getGroup(String mid, String uid, int appType, String group) {
+        if (StringUtils.isBlank(mid)) {
+            return null;
+        }
+        return client.getGroup(mid, uid, appType, group);
+    }
+
+    public Map<String, String> getExp(String mid, String uid, int appType, String group) {
+        if (StringUtils.isBlank(mid)) {
+            return null;
+        }
+        return client.getExp(mid, uid, appType, group);
+    }
+
+}

+ 32 - 19
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/RecommendService.java

@@ -13,6 +13,7 @@ import com.tzld.piaoquan.recommend.server.gen.recommend.VideoProto;
 import com.tzld.piaoquan.recommend.server.model.MachineInfo;
 import com.tzld.piaoquan.recommend.server.model.RecommendParam;
 import com.tzld.piaoquan.recommend.server.model.Video;
+import com.tzld.piaoquan.recommend.server.remote.ABTestRemoteService;
 import com.tzld.piaoquan.recommend.server.service.flowpool.FlowPoolConfigService;
 import com.tzld.piaoquan.recommend.server.service.flowpool.FlowPoolConstants;
 import com.tzld.piaoquan.recommend.server.service.flowpool.FlowPoolService;
@@ -34,6 +35,7 @@ import org.apache.commons.lang3.RandomUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Service;
 
@@ -74,6 +76,9 @@ public class RecommendService {
     @ApolloJsonValue("${new.exp,config.v2:[]}")
     private List<ExpConfig> expConfigs;
 
+    @Value("${new.exp.abtest.service.switch:true}")
+    private boolean newExpABTestServiceSwitch;
+
     @Autowired
     private FlowPoolConfigService flowPoolConfigService;
     @Autowired
@@ -87,6 +92,9 @@ public class RecommendService {
     @Autowired
     private StatisticsLogService statisticsLogService;
 
+    @Autowired
+    private ABTestRemoteService abTestRemoteService;
+
     @PostConstruct
     public void init() {
         ab_initial_config_map.put(AppTypeEnum.VLOG.getCode(), "095");
@@ -408,28 +416,33 @@ public class RecommendService {
 
         // TODO:hard code 为了快速做AB验证,应该由AB系统支持
         if (newExpList.contains(param.getAppType())) {
-            Map<String, List<Layer>> layerMap = CommonCollectionUtils.toMap(expConfigs, c -> c.getAppType(),
-                    c -> c.getLayers());
-            if (MapUtils.isNotEmpty(layerMap)) {
-                Map<String, Integer> bucketMap = JSONUtils.fromJson(request.getNewExpGroup(),
-                        new TypeToken<Map<String, Integer>>() {
-                        }, Collections.emptyMap());
-                if (MapUtils.isNotEmpty(bucketMap)) {
-                    List<Layer> layers = layerMap.get(param.getAppType() + "");
-
-                    if (CollectionUtils.isNotEmpty(layers)) {
-                        Map<String, String> expIdMap = new HashMap<>();
-                        for (Layer layer : layers) {
-                            for (Exp exp : layer.getExps()) {
-                                if (bucketMap.containsKey(layer.getLayerId())
-                                        && exp.getRange().length == 2
-                                        && exp.getRange()[0] <= bucketMap.get(layer.getLayerId())
-                                        && exp.getRange()[1] >= bucketMap.get(layer.getLayerId())) {
-                                    expIdMap.put(layer.getLayerId(), exp.getExpId());
+            if (newExpABTestServiceSwitch) {
+                param.setExpIdMap(abTestRemoteService.getExp(param.getMid(), param.getUid(), param.getAppType(),
+                        request.getNewExpGroup()));
+            } else {
+                Map<String, List<Layer>> layerMap = CommonCollectionUtils.toMap(expConfigs, c -> c.getAppType(),
+                        c -> c.getLayers());
+                if (MapUtils.isNotEmpty(layerMap)) {
+                    Map<String, Integer> bucketMap = JSONUtils.fromJson(request.getNewExpGroup(),
+                            new TypeToken<Map<String, Integer>>() {
+                            }, Collections.emptyMap());
+                    if (MapUtils.isNotEmpty(bucketMap)) {
+                        List<Layer> layers = layerMap.get(param.getAppType() + "");
+
+                        if (CollectionUtils.isNotEmpty(layers)) {
+                            Map<String, String> expIdMap = new HashMap<>();
+                            for (Layer layer : layers) {
+                                for (Exp exp : layer.getExps()) {
+                                    if (bucketMap.containsKey(layer.getLayerId())
+                                            && exp.getRange().length == 2
+                                            && exp.getRange()[0] <= bucketMap.get(layer.getLayerId())
+                                            && exp.getRange()[1] >= bucketMap.get(layer.getLayerId())) {
+                                        expIdMap.put(layer.getLayerId(), exp.getExpId());
+                                    }
                                 }
                             }
+                            param.setExpIdMap(expIdMap);
                         }
-                        param.setExpIdMap(expIdMap);
                     }
                 }
             }

+ 2 - 0
recommend-server-service/src/main/resources/application.yml

@@ -24,6 +24,8 @@ grpc:
   client:
     recommend-feature:
       negotiationType: PLAINTEXT
+    abtest:
+      negotiationType: PLAINTEXT
 
 server:
   tomcat: