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 2020/07/29 07:24:59 UTC

[GitHub] [servicecomb-java-chassis] GuoYL123 commented on a change in pull request #1894: [SCB-2043] flow control support custom / bug fix

GuoYL123 commented on a change in pull request #1894:
URL: https://github.com/apache/servicecomb-java-chassis/pull/1894#discussion_r461293774



##########
File path: handlers/handler-flowcontrol-qps/src/main/java/org/apache/servicecomb/qps/QpsControllerManager.java
##########
@@ -211,6 +212,8 @@ public QpsControllerManager setGlobalQpsStrategy(String globalLimitKey, String g
   private AbstractQpsStrategy chooseStrategy(String globalConfigKey, Long limit, Long bucket,
       String strategyKey) {
     AbstractQpsStrategy strategy;
+    AbstractQpsStrategy customStrategy = SPIServiceUtils

Review comment:
       ` new TokenBucketStrategy(globalConfigKey, limit, bucket);`
   `new FixedWindowStrategy(globalConfigKey, limit);`
   has different parameters.

##########
File path: handlers/handler-flowcontrol-qps/src/main/java/org/apache/servicecomb/qps/QpsControllerManager.java
##########
@@ -211,6 +212,8 @@ public QpsControllerManager setGlobalQpsStrategy(String globalLimitKey, String g
   private AbstractQpsStrategy chooseStrategy(String globalConfigKey, Long limit, Long bucket,
       String strategyKey) {
     AbstractQpsStrategy strategy;
+    AbstractQpsStrategy customStrategy = SPIServiceUtils

Review comment:
       done

##########
File path: handlers/handler-flowcontrol-qps/src/main/java/org/apache/servicecomb/qps/QpsControllerManager.java
##########
@@ -210,21 +209,17 @@ public QpsControllerManager setGlobalQpsStrategy(String globalLimitKey, String g
 
   private AbstractQpsStrategy chooseStrategy(String globalConfigKey, Long limit, Long bucket,
       String strategyKey) {
-    AbstractQpsStrategy strategy;
-    switch (StrategyType.parseStrategyType(strategyKey)) {
-      case FixedWindow:
-        strategy = new FixedWindowStrategy(globalConfigKey, limit);
-        break;
-      case LeakyBucket:
-        strategy = new LeakyBucketStrategy(globalConfigKey, limit);
-        break;
-      case TokenBucket:
-        strategy = new TokenBucketStrategy(globalConfigKey, limit, bucket);
-        break;
-      case SlidingWindow:
-      default:
-        strategy = new FixedWindowStrategy(globalConfigKey, limit);
+    AbstractQpsStrategy strategy = new FixedWindowStrategy(globalConfigKey, limit);
+    List<AbstractQpsStrategy> customStrategy = SPIServiceUtils
+        .getOrLoadSortedService(AbstractQpsStrategy.class);
+    for (AbstractQpsStrategy abstractQpsStrategy : customStrategy) {
+      if (abstractQpsStrategy.name().equals(strategyKey)) {

Review comment:
       already has local value 'strategy'

##########
File path: handlers/handler-flowcontrol-qps/src/main/java/org/apache/servicecomb/qps/QpsControllerManager.java
##########
@@ -210,21 +209,17 @@ public QpsControllerManager setGlobalQpsStrategy(String globalLimitKey, String g
 
   private AbstractQpsStrategy chooseStrategy(String globalConfigKey, Long limit, Long bucket,
       String strategyKey) {
-    AbstractQpsStrategy strategy;
-    switch (StrategyType.parseStrategyType(strategyKey)) {
-      case FixedWindow:
-        strategy = new FixedWindowStrategy(globalConfigKey, limit);
-        break;
-      case LeakyBucket:
-        strategy = new LeakyBucketStrategy(globalConfigKey, limit);
-        break;
-      case TokenBucket:
-        strategy = new TokenBucketStrategy(globalConfigKey, limit, bucket);
-        break;
-      case SlidingWindow:
-      default:
-        strategy = new FixedWindowStrategy(globalConfigKey, limit);
+    AbstractQpsStrategy strategy = new FixedWindowStrategy(globalConfigKey, limit);

Review comment:
       throw a Exception

##########
File path: handlers/handler-flowcontrol-qps/src/main/java/org/apache/servicecomb/qps/QpsControllerManager.java
##########
@@ -209,22 +208,21 @@ public QpsControllerManager setGlobalQpsStrategy(String globalLimitKey, String g
   }
 
   private AbstractQpsStrategy chooseStrategy(String globalConfigKey, Long limit, Long bucket,
-      String strategyKey) {
-    AbstractQpsStrategy strategy;
-    switch (StrategyType.parseStrategyType(strategyKey)) {
-      case FixedWindow:
-        strategy = new FixedWindowStrategy(globalConfigKey, limit);
-        break;
-      case LeakyBucket:
-        strategy = new LeakyBucketStrategy(globalConfigKey, limit);
-        break;
-      case TokenBucket:
-        strategy = new TokenBucketStrategy(globalConfigKey, limit, bucket);
-        break;
-      case SlidingWindow:
-      default:
-        strategy = new FixedWindowStrategy(globalConfigKey, limit);
+      String strategyName) {

Review comment:
       when name is incorrect , throw a Exception ?  
   `    if (strategy == null) {
         throw new ServiceCombException("the qps strategy name is not exist , please check.");
       }`

##########
File path: handlers/handler-flowcontrol-qps/src/main/java/org/apache/servicecomb/qps/QpsControllerManager.java
##########
@@ -209,22 +208,21 @@ public QpsControllerManager setGlobalQpsStrategy(String globalLimitKey, String g
   }
 
   private AbstractQpsStrategy chooseStrategy(String globalConfigKey, Long limit, Long bucket,
-      String strategyKey) {
-    AbstractQpsStrategy strategy;
-    switch (StrategyType.parseStrategyType(strategyKey)) {
-      case FixedWindow:
-        strategy = new FixedWindowStrategy(globalConfigKey, limit);
-        break;
-      case LeakyBucket:
-        strategy = new LeakyBucketStrategy(globalConfigKey, limit);
-        break;
-      case TokenBucket:
-        strategy = new TokenBucketStrategy(globalConfigKey, limit, bucket);
-        break;
-      case SlidingWindow:
-      default:
-        strategy = new FixedWindowStrategy(globalConfigKey, limit);
+      String strategyName) {

Review comment:
       when name is incorrect , throw a Exception , so it's no need to give a default value.
   `    if (strategy == null) {
         throw new ServiceCombException("the qps strategy name is not exist , please check.");
       }`

##########
File path: handlers/handler-flowcontrol-qps/src/main/java/org/apache/servicecomb/qps/QpsControllerManager.java
##########
@@ -209,22 +208,21 @@ public QpsControllerManager setGlobalQpsStrategy(String globalLimitKey, String g
   }
 
   private AbstractQpsStrategy chooseStrategy(String globalConfigKey, Long limit, Long bucket,
-      String strategyKey) {
-    AbstractQpsStrategy strategy;
-    switch (StrategyType.parseStrategyType(strategyKey)) {
-      case FixedWindow:
-        strategy = new FixedWindowStrategy(globalConfigKey, limit);
-        break;
-      case LeakyBucket:
-        strategy = new LeakyBucketStrategy(globalConfigKey, limit);
-        break;
-      case TokenBucket:
-        strategy = new TokenBucketStrategy(globalConfigKey, limit, bucket);
-        break;
-      case SlidingWindow:
-      default:
-        strategy = new FixedWindowStrategy(globalConfigKey, limit);
+      String strategyName) {

Review comment:
       when name is incorrect , throw a Exception , so it's no need to give a default value.
   `    if (strategy == null) {
         throw new ServiceCombException("the qps strategy name is not exist , please check.");
       }`




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

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