liubao68 commented on a change in pull request #1894:
URL:
https://github.com/apache/servicecomb-java-chassis/pull/1894#discussion_r461262652
##
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:
Maybe this code can be better refactored.
1. all strategies are SPI
2. any implementation have a name
3. choose the target strategy by configured name and default to 'FixedWindow'
##
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:
Maybe this code can be better refactored.
1. all strategies are SPI
2. any implementation have a name
3. choose the target strategy by configured name and default to 'FixedWindow'
By doing this, the strategy enum and case statements can be removed.
##
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:
Hidden parameters in implementation and I think will work.
##
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:
Hidden parameters in implementation and I think will work. You can think
of users will custom strategies like this, how will they do it?
##
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:
strategyKey can have default value 'FixedWindow', wrong used defined
value can throw exception. So here do not need new a default 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);
+List customStrategy = SPIServiceUtils
+.getOrLoadSortedService(AbstractQpsStrategy.class);
+for